Hier die Einstellungen für einen ATMEGA 16 bei 8MHz
Und hier die dazugehörigen Interruptroutinen für 4 KanäleCode:// Timer/Counter 1 initialization // Clock source: System Clock // Clock value: 1000,000 kHz // Mode: Normal top=FFFFh // OC1A output: Discon. // OC1B output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge // Timer 1 Overflow Interrupt: Off // Input Capture Interrupt: Off // Compare A Match Interrupt: On // Compare B Match Interrupt: On TCCR1A=0x00; TCCR1B=0x02; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x18;
Ich hab die Routinen noch nicht mit Servos getestet, man möge mir also Fehler verzeihen, wenn was nicht stimmt.Code:// Timer 1 output compare A interrupt service routine interrupt [TIM1_COMPA] void timer1_compa_isr(void) { PORTC=0; // Port C abschalten = alle Ausgänge aus } // Timer 1 output compare B interrupt service routine interrupt [TIM1_COMPB] void timer1_compb_isr(void) { switch(uc_channel) { case 0: PORTC.0=1; // Kanal 1 ein OCR1A=ui_pwm[0]; break; case 1: PORTC.1=1; // Kanal 2 ein OCR1A=ui_pwm[1]; break; case 2: PORTC.2=1; // Kanal 3 ein OCR1A=ui_pwm[2]; break; case 3: PORTC.3=1; // Kanal 4 ein OCR1A=ui_pwm[3]; break; }; TCNT1=0; uc_channel++; if ( uc_channel>3){uc_channel=0;}; }
Die Codes sind für Codevision AVR, sollten sich aber leicht für andere Compiler umschreiben lassen.







Zitieren

Lesezeichen