Hallo, beim Atmega 32 gab es SREG_I_bit := 1; // Interrupt enable TOIE0_bit := 1; // Timer0 overflow interrupt enable TCCR0 := 5; // Start timer with 128 prescaler Wie mache ich das beim XMega? Mit dem RTC? Welche Register bruache ich?! Finde zwar vieles zu vielen Timer, aber welches ist der richtige?
Die RTC ist ein separates Modul
1 | CLK.RTCCTRL = CLK_RTCSRC_RCOSC_gc | CLK_RTCEN_bm; //RTC Clock = 32768/1024 |
2 | RTC.CTRL |= RTC_PRESCALER_DIV1_gc; //Div = 1 |
3 | while( RTC.STATUS & RTC_SYNCBUSY_bm); //Wait RTC Busy |
4 | RTC.PER = 1024-1; //1s |
5 | RTC.CNT = 0; |
6 | RTC.INTCTRL |= RTC_OVFINTLVL_LO_gc; |
Dann hast du ein RTC Overflow Interrupt alle 1s Beim "normalen" Timer:
1 | TCD0.CNT = 0; |
2 | TCD0.PER = 499; // TOP |
3 | TCD0.CTRLA = TC_CLKSEL_DIV8_gc; |
4 | TCD0.INTCTRLA = TC_OVFINTLVL_LO_gc; // Low Level Interrupt |
^^ das ergibt bei 4 MHz einen Interrupt alle 1ms
ah, danke, habe jetzt auch gerade ein Beispiel im example ORdner gefunden, das sieht einfacher aus :-)
1 | program Timer0_Interrupt; |
2 | |
3 | |
4 | procedure Timer0Overflow_ISR(); org IVT_ADDR_TCC0_OVF; |
5 | begin |
6 | PORTD_OUTTGL := 0xFF; // Toggle PORTD |
7 | end; |
8 | |
9 | begin |
10 | PORTD_DIRSET := 0xFF; // Set PORTD as output |
11 | PORTD_OUTCLR := 0xFF; // Clear PORTD |
12 | |
13 | delay_ms(1000); |
14 | |
15 | TCC0_PERL := 0x10; // Set period 10000 |
16 | TCC0_PERH := 0x27; |
17 | |
18 | TCC0_CTRLA := 0x05; // Prescaler DIV64 |
19 | TCC0_INTCTRLA := 2; // Enable overflow interrupt |
20 | PMIC_CTRL := 2; // Enable medium level interrupts |
21 | CPU_SREG.B7 := 1; // Enable global interrupts |
22 | |
23 | while (TRUE) do nop // Endless loop, port is changed inside Interrupt Service Routine (ISR) |
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.