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 duty cycle strange behaviour!

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



Joined: 29 Dec 2008
Posts: 18
Location: Italy

View user's profile Send private message

Pwm duty cycle strange behaviour!
PostPosted: Fri Sep 09, 2011 1:34 pm     Reply with quote

Hi there!

I'm doing a small motor control with the classic H bridge controlled by a 18F4550 pic (with 20MHz and HSPLL active).
It works really well but, I noticed a strange behaviour, here's the code!

Code:
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_16_BIT);   
   setup_timer_2(T2_DIV_BY_1,0xff,1);      //25.0 us overflow, 25.0 us interrupt per generare la portante PWM 46kHz
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_ccp1(CCP_PWM);   // Configure CCP1 as a PWM
   setup_ccp1(CCP_PWM_FULL_BRIDGE | CCP_PWM_H_H |CCP_SHUTDOWN_ON_INT0|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L);
   set_tris_d(0x1F);
   set_tris_d(0x02);
   set_pwm1_duty((int16)0x000F);


The last instruction gives me a duty cycle of 0%!!!
If I write values from 0x000C to 0x000F I obtain the same wrong duty cycle!!! Moreover if the last 4bits have a value between 0xC and 0xF, the duty cycle is always 0%!
Writing 0x000A I obtain a duty cycle of 0.9% as expected!
I see the pwm registers and seem all ok with the right value as described in the datasheet.
Thank you in advance for your help!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 09, 2011 1:45 pm     Reply with quote

What's your compiler version ?
acm45



Joined: 29 Dec 2008
Posts: 18
Location: Italy

View user's profile Send private message

PostPosted: Fri Sep 09, 2011 1:51 pm     Reply with quote

The compiler version is: 4.114
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 09, 2011 2:21 pm     Reply with quote

I put this code in a standard small template with #include, #fuses, #use
delay, and main(), and it doesn't compile with vs. 4.114. The last
parameter is not in the 18F4550.h file. Therefore this is not real code.
Quote:

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_16_BIT);


Please post real tested code, with the #include, #fuses, #use delay(),
and main().




-----
Edit: Corrected a typo. I meant to say "not real code".


Last edited by PCM programmer on Sun Sep 11, 2011 1:17 pm; edited 1 time in total
acm45



Joined: 29 Dec 2008
Posts: 18
Location: Italy

View user's profile Send private message

SOLVED
PostPosted: Sun Sep 11, 2011 2:39 am     Reply with quote

sorry for the parameter RTCC_16_BIT, I defined it into my 18F4550.h file as a 0x00. Anyway, I find the problem in my own code, setting the pwm duty cycle I was setting also the reverse bridge control.
Thank you for your help!
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