Da gibt bessere Moglichkeiten für eine Servo anzusteuern. Ich verwende ide ISR (Interrupt Subroutine) die auf 10 kHz lauft. Bei mir in die M32 programmiert, aber geht auch in Robotbase. Bei diese ISR kannst du die Servo's in 10 Positionen fahren von 1 mS bis 2 mS.
Code:
//stuurt servopulsen aan tussen 1 en 2mS
uint8_t servo1 = 15;
uint8_t servo2 = 15;
uint8_t servo3 = 11;
uint8_t servo4 = 19;
void servo(uint8_t nummer,uint8_t puls)
{
if(nummer==1) servo1=puls;
if(nummer==2) servo2=puls;
if(nummer==3) servo3=puls;
if(nummer==4) servo4=puls;
}
/*****************************************************************************/
// Delays, Stopwatches and Beeper:
// ---------------------
// Internal status bits
volatile union {
uint8_t byte;
struct {
unsigned beep:1;
unsigned unused:7;
};
} controlStatus;
volatile stopwatches_t stopwatches;
volatile uint8_t delay_timer;
volatile uint8_t ms_timer;
volatile uint8_t servo_timer;
volatile uint16_t sound_timer;
/**
* Timer 0 Compare ISR - This timer is used for various
* timing stuff: The delay timer for blocking delays,
* "Stopwatches" for non-blocking delays and the timing of
* the sound generation with timer2...
*
* By default, it runs at 10kHz which means this ISR is called
* every ~100µs! This is nice for timing stuff!
*/
ISR (TIMER0_COMP_vect)
{
// Blocking delay (100µs):
delay_timer++;
servo_timer++;
if (servo_timer>250)
{
servo_timer=0;
PORTC |= IO_PC2;
PORTC |= IO_PC3;
PORTC |= IO_PC5;
PORTC |= IO_PC7;
}
if (servo_timer>servo4) PORTC &= ~IO_PC2;
if (servo_timer>servo3) PORTC &= ~IO_PC3;
if (servo_timer>servo2) PORTC &= ~IO_PC5;
if (servo_timer>servo1) PORTC &= ~IO_PC7;
Sleep function hat das Nachteil das auch alles andere nicht weiter bearbeitet werd.
Lesezeichen