|
|
View previous topic :: View next topic |
Author |
Message |
lgeorge123
Joined: 05 Dec 2004 Posts: 31
|
how to set pic18f452 to its max pwm frequency |
Posted: Mon Jan 26, 2009 8:09 am |
|
|
using pic18f452 and crystal 20MHz , for the code :
setup_timer_2(T2_DIV_BY_1,255, 1) , I only get 20KHZ pwm frequency.
So how can I set to its max frequency ?????? |
|
|
Ttelmah Guest
|
|
Posted: Mon Jan 26, 2009 10:09 am |
|
|
There is a balancing 'act', between the output frequency, and the available resolution steps. You code gives the maximum frequency, _supporting 1024 steps in the output_.
If you think about it, since the PWM 'steps' in single counts of the crystal, this will give:
20000000/1024 = 19531.25Hz
To go faster, you have to sacrifice accuracy. So for a PWM, supporting just ten steps say, you can get 2MHz as your output. The actual maximum, would be a PWM with:
setup_timer_2(T2_DIV_BY_1,0, 1);
giving just four counts of the master clock, per pulse (2.5MHz). However you only get 2bits of output resolution.
You need to decide on what PWM frequency you need, and then see if enough resolution will be available at this frequency. So if (for instance), you want 100000Hz, then this would be the master clock over 200, giving 200 possible output steps, and using:
setup_timer_2(T2_DIV_BY_1,49, 1);
wth allowable 'duty cycle' numbers from 0 to 199.
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|
|
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
|