Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Servomotor.c
- *
- * Created: 18.03.2019 13:44:05
- * Author : lgoeke
- */
- #include <avr/io.h>
- #include <avr/interrupt.h>
- volatile int iI;
- ISR(TIMER0_OVF_vect)
- {
- if(iI == 0)
- {
- PORTB = 0x01; //Pin 1 auf High
- TCNT0 = 0x43; //Timer auf 1,5 ms
- iI++; //iI + 1
- }
- else if(iI == 1)
- {
- PORTB = 0x00; //Pin 1 auf low
- TCNT0 = 0xC0; //Timer auf 0,5 ms
- iI++; //iI + 1
- }
- else if((iI > 1) && (iI < 11))
- {
- TCNT0 = 0x05; // Timer auf 2ms
- iI++; //iI + 1
- }
- else if(iI == 11)
- {
- TCNT0 = 0x05; //Timer auf 2ms
- iI = 0; //iI auf 0
- }
- }
- int main(void)
- {
- sei(); //Interrupt wird freigegeben
- DDRB = 0xFF; //Alle Ausgänge
- TIMSK = 0x01; //Overflow tritt ein
- TCCR0 = 0x02; //Prescaler wird auf 8 festgelegt
- PORTB = 0xFF; //alle Ausgänge auf High
- while (1)
- {
- }
- }
- //Taktfrequenz = 1MHz
- //1Mhz/8 = 125000 Hz = (Kehrwert 8/1Mhz =) 8µs pro Schritt (256 * 8µs = 2,048ms)
- //Timer auf 1,5ms
- //1,5ms/8µs = 187,5 Schritte
- //TCNT0 = 255 - 188 = 67 => 0x43(hexa)
- //Timer auf 0,5ms
- //0,5ms/8µs = 62,5 Schritte
- //TCNT0 = 255 - 63 = 192 => 0xC0(hexa)
- //Timer auf 2ms
- //2ms/8µs = 250 Schritte
- //TCNT0 = 255 - 250 = 5 => 0x05(hexa)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement