Meine Lösung für die Servos in M32 mit die forhandene 100 µS timer : 2 Servos wirden gesteurt ueber port C5 und portC7. Minpos servo = werte 8, maxpos servo = werte 22. Das ergibt dan eine puls von 0.8 bis 2.2 mS.
Wan servo-timer 200 erreicht (=20 mS), wird er auf 0 gesetzt, und wirden beide ports hoch gesetzt. Die ports wirden zuruck auf 0 gesetzt abhangig von die eingestellte werte "servo1" und "servo2"
In die config.h mus naturlich noch die port C5 und C7 als ausgang declariert werden !
Code:
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>200) {servo_timer=0;PORTC |= IO_PC5;PORTC |= IO_PC7;}
if (servo_timer>servo2) PORTC &= ~IO_PC5;
if (servo_timer>servo1) PORTC &= ~IO_PC7;
// All 1ms based timing stuff
if(ms_timer++ >= 10) { // 10 * 100µs = 1ms
Lesezeichen