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

smoother pwm control

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



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

smoother pwm control
PostPosted: Tue Oct 04, 2011 10:32 am     Reply with quote

Hi There,

I'm looking for a way (if possible) to adjust the duty cycle for my pwm in a finer interval than 1%.
I'm running the pwm on a PIC16F883 with a 20MHz crystal. My timer2 (for the pwm) is configured like this
Code:
setup_timer_2( T2_DIV_BY_1,24, 1);
Which gives me the desired 200kHz.
I currently set the duty cycle like this:
Code:

long SetIntens= 88;
set_pwm1_duty(SetIntens);

Which works fine for whole percent numbers but i would like to control the pwm in a finer interval....

Thanks for hints and suggestions!
Ron
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 04, 2011 10:48 am     Reply with quote

This thread has an example of using the CCP in Compare mode to
do PWM with finer resolution:
http://www.ccsinfo.com/forum/viewtopic.php?t=44328
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Wed Oct 05, 2011 8:40 am     Reply with quote

But, not at this high speed. :(
PCM's solution gives more steps for a low frequency PWM, but doesn't help at 200KHz.
At 200KHz, you are going to have problems. You can get a little finer, by going to a CPU supporting 25MHz, or switching to a 18 chip with a PLL, and going to 40, or possibly even 64MHz (depending on the chip). However the big question is do you really need 200KHz?.
The step size, is cycles on the clock, so if you could go down to 100KHz, and 40Mhz, you would have 400steps available, against your current 100.

Best Wishes
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

Finer resolution
PostPosted: Wed Oct 05, 2011 1:24 pm     Reply with quote

Answer the questions.

Why do you need better than 1% setting?
Why do you need 200kHz?
What you are trying to achieve?

Then we may be able to suggest sensible solutions.

Mike

P.S. 1% setting gives a max 0.5% error
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