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

Maximum Pwm Frequency - Half bridge mode - Pic 16f887

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



Joined: 14 Aug 2019
Posts: 9

View user's profile Send private message

Maximum Pwm Frequency - Half bridge mode - Pic 16f887
PostPosted: Thu Aug 29, 2019 9:13 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 29, 2019 11:28 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 30, 2019 12:09 am     Reply with quote

Hi Ttelmah

Thank you very much for your kindly help!

Hope you have a nice day!
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Fri Aug 30, 2019 12:24 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 30, 2019 2:58 am     Reply with quote

Hi Ttelmah

Thank you very much for your help!
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