View previous topic :: View next topic |
Author |
Message |
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
smoother pwm control |
Posted: Tue Oct 04, 2011 10:32 am |
|
|
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
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Wed Oct 05, 2011 8:40 am |
|
|
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
|
Finer resolution |
Posted: Wed Oct 05, 2011 1:24 pm |
|
|
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 |
|
|
|