1/ f = t
1/1000000 hz = 0,000001 sec = 0,001 msec
Code:
#define SERVO1 OCR1A
#define SERVO2 OCR1B
// PWM Timmer
SIGNAL(SIG_OVERFLOW1)
{
TCNT1 = 0;
/* configure to set outputs on compare match so we can turn on the
* pulse in the next statement */
TCCR1A |= BV(COM1A1)|BV(COM1A0)|BV(COM1B1)|BV(COM1B0);
/* force compare match to set outputs */
TCCR1A |= BV(FOC1A)|BV(FOC1B);
/* configure to clear outputs on compare match so that the output
* compare function ends the pulse */
TCCR1A &= ~(BV(COM1A0)|BV(COM1B0));
}
void init_servos(void)
{
/* Use Timers 1 generate the pulses for 2 R/C servos; each
* timer can do up to 3 servos. */
/*
* configure OC1A for mode 0: normal, top=0xffff prescale=8 (f~=30):
*
* WGM33=0, WGM23=0, WGM13=0, WGM03=0, CS32=0, CS31=1, CS30=0
*/
DDRD |= BV(PORTD5) | BV(PORTD4);
TCCR1A &= ~(BV(WGM11) | BV(WGM10) | BV(COM1A1) | BV(COM1B1));
TCCR1A |= BV(COM1A0) | BV(COM1B0);
TCCR1B &= ~(BV(WGM13) | BV(WGM12) | BV(CS12) | BV(CS10));
TCCR1B |= BV(CS11);
TCNT1 = 0;
TIMSK |= BV(TOIE1);
/* set all Servos to their center positions */
SERVO1 = SERVO_MID;
SERVO2 = SERVO_MID;
}
so sieht mein PWM Servo code aus bei 16 MHz
vielleicht hilft es dir
Lesezeichen