View previous topic :: View next topic |
Author |
Message |
phamngockienbp
Joined: 14 Aug 2019 Posts: 9
|
Maximum Pwm Frequency - Half bridge mode - Pic 16f887 |
Posted: Thu Aug 29, 2019 9:13 pm |
|
|
Hi every one
I would like to generate spwm with the frequency higher than 20 KHz at half bridge mode.
May I ask for the maximum pwm frequency on pic 16F887.
I had tested with pwm 19 Khz, pic worked properly.
But the pwm frequency was increased to over 20 KHz, pic didn't work well as expected.
On the datasheet, I found that the maximum frequency is only 20 KHz. Is it correct ?
Please kindly help me in this regard, thank you in advance! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Thu Aug 29, 2019 11:28 pm |
|
|
Critical thing you don't say is your clock speed.
It sounds as if you are using #use pwm. This is limited compared to
accessing the timer directly. But critical thing you need to remember
is that the PWM resolution is inversely proportional to the frequency
selected. A PWM at 40KHz (say) will have almost no available 'steps'.
Calculation as follows:
Tmer2 is fed off Fosc/4. So if you are running off 25MHz, the absolute
maximum frequency that can be generated is:
(25000000/4)/4 = 1562500Hz.
At which point there will be just four PWM steps available.
Now if (for example), you are running off 4MHz, then at 20KHz, there
are just 50 steps available. #use pwm, since it allows you to adjust in
percent, has to only allow frequencies that give adjustment in a good
number of steps
If you are running at 8MHz, you can merrily go to 125KHz, but only with
16 steps available. |
|
|
phamngockienbp
Joined: 14 Aug 2019 Posts: 9
|
|
Posted: Fri Aug 30, 2019 12:09 am |
|
|
Hi Ttelmah
Thank you very much for your kindly help!
Hope you have a nice day! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Fri Aug 30, 2019 12:24 am |
|
|
As I happened to have an 887 on the bench, I just tried this:
Code: |
setup_timer_2(T2_DIV_BY_1, 9,1);
setup_CCP1(CCP_PWM_L_L | CCP_PWM_HALF_BRIDGE);
set_pwm1_duty(20L);
|
On the chip at 20MHz, it is merrily giving me 500KHz. However only 40
possible steps, so just over 5.3bits of resolution.
Remember also, that your range of deadband etc., will affect just how
low you can take the supported resolution.
Wondering where you got the 20KHz figure from, since the data sheet
gives example settings going over 200KHz. Where there is a 20KHz(ish)
figure, is for the maximum frequency retaining 10bit resolution, which is
of course limited by the clock rate. So:
20000000/1024 = 19531.25Hz.
Maximum frequency the PWM can do from 20MHz, with 1024 steps. |
|
|
phamngockienbp
Joined: 14 Aug 2019 Posts: 9
|
|
Posted: Fri Aug 30, 2019 2:58 am |
|
|
Hi Ttelmah
Thank you very much for your help! |
|
|
|