View previous topic :: View next topic |
Author |
Message |
Helyos
Joined: 22 Oct 2003 Posts: 22
|
PWM 100Khz 16f876-4Mhz |
Posted: Thu Feb 05, 2004 8:14 pm |
|
|
Hi, I�m new in this great world of pics.
I have 16f876-4Mhz and version 3.155
I don�t know how to get a frecuency of 100 Khz, and I want to control the duty cicle of the two PWM independents in the 16f876.
I only saw examples for frecuencies of 20 Khz or less.
Could you help me?
Thanks |
|
|
kypec
Joined: 20 Sep 2003 Posts: 54
|
|
Posted: Fri Feb 06, 2004 9:55 am |
|
|
Here are my calculated settings for your desired 100 kHz PWM frequency
at Fosc=4 MHz.
Code: |
setup_timer_2(T2_DIV_BY_1,9,1);
setup_ccp1(CCP_PWM); //PWM mode
setup_ccp2(CCP_PWM); //PWM mode
|
However, keep in mind that the resolution which you get
at the configuration above is only some 5,32 bits which means:
Code: |
set_pwm1_duty(0); //this is 0% duty cycle
set_pwm1_duty(40); //this is 100% duty cycle
|
Therefore, your effective range for PWM control is no more
than 41 discrete steps.
If this is too few for your application then you will have to
increase the oscillator frequency (up to 20 MHz) or
decrease the PWM frequency.
Have a nice day,
kypec |
|
|
Helyos
Joined: 22 Oct 2003 Posts: 22
|
Thanks |
Posted: Fri Feb 06, 2004 2:08 pm |
|
|
Thank you very much.
I will try it on monday when I can see it in oscilloscope.
Have a nice day
Helyos |
|
|
|