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 CCS Technical Support

18F4550 PWM

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



Joined: 31 May 2012
Posts: 10

View user's profile Send private message

18F4550 PWM
PostPosted: Tue Dec 23, 2014 5:37 am     Reply with quote

I have a board which has 18F4550 with 20Mhz crystal. I want to turn right and left servo motor with respect to buttons(Low-High) or Pot value.
Now, I want to try to get a Pwm signal approximately Tp>2msec.

#use delay(clock=48000000)
setup_timer_2(T2_DIV_BY_A,B,1); //A can be 1,4,16 B can be 0-255

From using;
PWM period (Tpwm) = (PR2+1) x 4 x Tosc x TMR2 prescaler
PWM Duty Cycle=(value) x (Tosc) x TMR2 prescaler x 4

How can I get Tp>2msec with using A and B values or other ways?Thx
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Tue Dec 23, 2014 5:42 am     Reply with quote

You can't with the PWM.

The PWM, is designed to give _fast_ pulses without processor intervention.

Search for CCP and servo in the forum search. Code has been posted here (and may be in the code library as well), to use the CCP module for this.
cengav4r



Joined: 31 May 2012
Posts: 10

View user's profile Send private message

PostPosted: Tue Dec 30, 2014 8:45 am     Reply with quote

Could you give more detail information about using CCP module? Do you also mean software PWM? I knew that CCP is capture/compare/pwm, ??
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Tue Dec 30, 2014 9:30 am     Reply with quote

Not software, or hardware PWM.

The CCP module does three separate functions. Counter. Compare. PWM.

Now the counter is obvious (it counts). The PWM similarly develops a PWM signal. However this only uses a 8+2bit counter (two directly from the master clock, as opposed to the normal Fosc/4). This is designed to give fast pulse widths. The key is the middle C, which is the 'compare' functionality. This allows the hardware to trigger an 'event' based upon a timing function, and offers full 16bit counting, from the Fosc/4 source (or a division of this - so supports frequencies 256* lower than the hardware PWM). Hence the CCP module in compare mode, can be used to generate lower frequency 'PWM' functionality, with hardware accuracy. It needs some software, but 99% of the work is done by the hardware.

Code to do this for a servo has been published here.
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