CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PWM problem 16F1503

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PWM problem 16F1503
PostPosted: Wed Aug 31, 2016 1:03 am     Reply with quote

I would like to have an PWM output on Pin C5, so I declared PWM1 in the software, but I don't get PWM on this pin.

I've copied the program from PCM programmer from this topic:
http://www.ccsinfo.com/forum/viewtopic.php?t=48643&highlight=16f1503

This is my test program:

Code:

#include <16F1503.H>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4M)

//=========================================
void main()
{
setup_pwm1(PWM_ENABLED | PWM_OUTPUT | PWM_ACTIVE_HIGH);
setup_timer_2(T2_DIV_BY_1, 249, 1);                 
set_pwm1_duty(500L);

while(1);
}


Why isn't it working? Should be simple...

Compiler version: 5.058
Ttelmah



Joined: 11 Mar 2010
Posts: 19329

View user's profile Send private message

PostPosted: Wed Aug 31, 2016 1:49 am     Reply with quote

I'd suggest priorities....

Table 11-5.

You will see that CWG1A, and CLC1 both have higher priorities than the PWM. You need to ensure these are disabled. Now, technically the CLC1 output should default to A2, but don't trust it.
So:
Code:

#include <16F1503.H>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4M)

//=========================================
void main(void)
{
    setup_clc1(CLC_DISABLED);
    setup_cwg(CWG_DISABLED, CWG_NO_AUTO_SHUTDOWN, 0 , 0);
    setup_pwm1(PWM_ENABLED | PWM_OUTPUT | PWM_ACTIVE_HIGH);
    setup_timer_2(T2_DIV_BY_1, 249, 1);                 
    set_pwm1_duty(500L);

    while(TRUE)
        ;



Haven't got a chip to test, but generally this is the commonest problem. Obviously you have MCLR enabled with your fuses so do need a pullup on this or the chip won't run.
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Aug 31, 2016 2:03 am     Reply with quote

I had seen the MCLR fuse also, and change it to NOMCLR. Also updated to CCS version 5.062.

Tested your program, but unfortunately doesn't work also.

I've also added setup_oscillator(OSC_4MHZ); in my test program, but also this doesn't make sense.
Ttelmah



Joined: 11 Mar 2010
Posts: 19329

View user's profile Send private message

PostPosted: Wed Aug 31, 2016 2:09 am     Reply with quote

Have you tested the chip actually is running?.
A simple 'flash an LED' program?.

Always the first place to start.
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Aug 31, 2016 3:29 am     Reply with quote

An output toggle function on pin A5 is working, but not on the C5 (even if I disable the setup_PWM/Setup_timer_2/Set_pwm_duty functions).

I've also tried an different PCB, with the same result.

edit: It is working, my fault, measuring PWM at the wrong pin.
Ttelmah



Joined: 11 Mar 2010
Posts: 19329

View user's profile Send private message

PostPosted: Wed Aug 31, 2016 6:17 am     Reply with quote

Very Happy
temtronic



Joined: 01 Jul 2010
Posts: 9162
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Aug 31, 2016 8:22 am     Reply with quote

re:
Quote:
edit: It is working, my fault, measuring PWM at the wrong pin.

WELCOME to the 'club' ! It gets worse the older you get and the more pins the PIC has.....
..then there's those 'programmable' pins that 'magically' aren't what you thought they were....

Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group