weg22
Joined: 08 Jul 2005 Posts: 91
|
Is CCP_PWM too fast for an RC servo? |
Posted: Tue Apr 18, 2006 1:16 pm |
|
|
Hi all,
I am now trying to use the CCP pin to generate a PWM signal (as opposed to the INT_TIMER0 in my last post). However, I think the frequency needed to control an RC servo (a 20 ms period = 50 Hz) isn't feasible with my 10 MHz oscillator. The code below generates a 625 Hz PWM signal, but I need 50 Hz for it to work. Does anyone know of a workaround for this (without swapping my crystal)?
Thanks in advance,
weg
Code: |
include <16F877.H>
#include <stdlib.h>
#include <math.h>
#define LED PIN_C0
#fuses HS,NOWDT,NOPROTECT,PUT,NOLVP
#use delay(clock=10000000)
void main()
{
output_high(LED); delay_ms(1500);
output_low(LED); delay_ms(1500);
// setup PWM output
setup_ccp1(CCP_PWM); // pwm output
setup_timer_2(T2_DIV_BY_16, 255, 1);
while(1)
{
output_high(LED);
set_pwm1_duty(5);
}
}
|
|
|