Ich habs jetzt neu so versucht geht aber auch nicht, irgendwas habe ich scheinbar nicht begriffen.
Ziel des Codes ist es, mir die Ports für 1.5ms auf High zu ziehen und 18.5ms auf Low (Servomittelposition)Code:#include <avr/io.h> // I/O Port definitions #include <avr/interrupt.h> // Interrupt macros #define F_CPU 16000000 #define timer 96 //0.01ms // volatile int ms1 = 0; volatile int ms2 = 0; volatile int ms3 = 0; void timer_init(void) { TCCR0 |= (1<<CS00); //Prescaler 1 TCNT0 = timer; TIMSK |= (1<<TOIE0); //Interupts aktivieren TIFR |= (1<<TOV0); }; ISR(TIMER0_OVF_vect) { //Endausschlag LINKS if(ms1>150) PORTB &= ~(1<<PORTB1); else PORTB |= (1<<PORTB1); if(ms1<2000) ms1++; else ms1 = 0; TCNT0 = timer; //Endausschlag MITTE if(ms2>150) PORTB &= ~(1<<PORTB2); else PORTB |= (1<<PORTB2); if(ms2<2000) ms2++; else ms2 = 0; //Endausschlag RECHTS if(ms3>150) PORTB &= ~(1<<PORTB3); else PORTB |= (1<<PORTB3); if(ms3<2000) ms3++; else ms3 = 0; }; int main(void) { DDRB |= (1<<PORTB1) | (1<<PORTB2) | (1<<PORTB3); //B... AUSGANG PORTB &= ~((1<<PORTB1) | (1<<PORTB2) | (1<<PORTB3)); //B.. Low sei(); //GLOBALE INTERUPTS AKTIVIERT timer_init(); //FUNKTIONSAUFRUF }
Mit dem Wert von 150 wollte ich auf die 1.5ms kommen.
Und dort wo jetzt 96 steht hatte ich die Berrechnung der timer variable







Zitieren

Lesezeichen