|
|
View previous topic :: View next topic |
Author |
Message |
pic-e
Joined: 29 May 2008 Posts: 1
|
Highest PWM is only 2.5 Mhz |
Posted: Thu May 29, 2008 7:12 am |
|
|
Hello,
I have a 16F877 running at 20Mhz. Using the formula below, I would think that I should be able to get out a freq of 5 Mhz but it is only 2.5.
Code: | Crystal Frequency
PWM Freq = -----------------------------------------
(PR2 + 1) * (Timer2 Prescaler) * 4
|
My code:
Code: |
#include <16F877.H>
#fuses HS, NOWDT, NOPROTECT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
main()
{
output_low(PIN_C2); // Set CCP1 output low setup_ccp1 (CCP_PWM); // Configure CCP1 as a PWM
setup_timer_2(T2_DIV_BY_1, 1, 1);
set_pwm1_duty(1); // 50% duty cycle
while(1); // Prevent PIC from going to sleep
} |
|
|
|
RLScott
Joined: 10 Jul 2007 Posts: 465
|
Re: Highest PWM is only 2.5 Mhz |
Posted: Thu May 29, 2008 8:09 am |
|
|
The period of Timer 2 is (PR2+1) * Prescaler * 4 * Tosc. In your case Tosc = 50 nsec. With PR2=1, this works out to 2*1*4*50 nsec = 400 nsec. Therefore the frequency is 1/400 nsec = 2.5 MHz.
Robert Scott
Real-Time Specialties |
|
|
Ttelmah Guest
|
|
Posted: Thu May 29, 2008 8:55 am |
|
|
Code: |
setup_timer_2(T2_DIV_BY_1, 0, 1);
set_pwm1_duty(2L); // 50% duty cycle
|
Best Wishes |
|
|
|
|
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
|