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

12F1840 PWM Generation

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



Joined: 11 Nov 2006
Posts: 181
Location: Birmingham, UK

View user's profile Send private message

12F1840 PWM Generation
PostPosted: Mon Aug 05, 2019 12:11 pm     Reply with quote

Hi,
I want to control a model r/c servo from the 1840. I need to be able to select either 830 us or 1500us pulse width.

I have looked at lots of posts on PWM, but am still not seeing the wood for the trees! I am using the internal oscillator at 16MHz.

Can someone please help me out, so I can understand how to achieve this?
Thanks
Brian
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 05, 2019 12:52 pm     Reply with quote

See the sample code in this link. It uses the CCS driver file servos.c:
http://www.ccsinfo.com/forum/viewtopic.php?t=34560&start=22
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Mon Aug 05, 2019 12:59 pm     Reply with quote

You can't.
You need to perhaps use the CCP, rather than the PWM.

Problem is a servo pulse is normally repeated at 25mSec intervals.
From your master clock, the slowest the PWM can go is 245Hz.
The PWM is designed to provide _fast_ pulses without needing CPU
overhead. Not to provide slow pulses like this.

I posted a routine to handle a servo pulse in percent here:
<http://www.ccsinfo.com/forum/viewtopic.php?t=50914&highlight=servo>

This uses the CCP. You'd need 33 for 830uSec.
BLL



Joined: 11 Nov 2006
Posts: 181
Location: Birmingham, UK

View user's profile Send private message

PostPosted: Tue Aug 06, 2019 1:59 am     Reply with quote

Hi Ttelmah

Thanks again for your help - I shall go and study your code.

Brian
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