Hallo,
ich stehe irgendwie auf dem Schlauch und sehe den Fehler nicht,
vielleicht hat jemand nen Tipp.
Ich habe frisch ein Atxmega 128A1 Xplained auf dem Tisch und bin gerade
etwas dabei mich damit zu beschäftigen und herumzuspielen. Ich habe vor
die interne RTC zu aktivieren und klassisch im Sekundentakt die 8 LEDs
des Xplained mit dem Wert eines einfachen Zählers zu schalten.
Das Clocksystem habe ich scheinbar korrekt initialisiert, waitstates und
auch Usart-Baud usw. stimmen, die Ausgaben sind auf dem Terminal i.O.
Das Problem:
ich habe die RTC so konfiguriert, dass der Overflow-Vector auf meine
ISR-Funktion zeigt, Prescaler auf 1, Taktrate der RTC sind die 32kHz.
So, das Period-Register der RTC habe mit dem Wert 32768 geladen, sodass
rein theoretisch ja der Overflow-Interrupt jede Sekunde ausgelöst werden
sollte.
Geht aber nicht! Es dauert länger als 1s.
Ich habe mir also das Period-register ausgeben lassen und musste
feststellen, dass es nachwievor auf 0xffff steht. Laut der
Assemblerausgabe des Compilers wird aber alles korrekt ins Register
geschrieben, wieso ist das so? Was mache ich falsch?
Der Source (luna):
1 | '----------------------------------------------------------------------------
|
2 | 'controller device
|
3 | '----------------------------------------------------------------------------
|
4 | avr.device = atxmega128a1
|
5 | avr.clock = 32000000
|
6 | avr.stack = 64
|
7 | '----------------------------------------------------------------------------
|
8 | 'setup clock system
|
9 | '----------------------------------------------------------------------------
|
10 | ClkSys.Enable( OSC_RC32MEN_bm ) 'enable the internal 32 Mhz oscillator
|
11 | ClkSys.Prescalers_Config( CLK_PSADIV_1_gc, CLK_PSBCDIV_1_1_gc ) 'configure the prescalers for the periferal to 1:1
|
12 | ClkSys.WaitReady( OSC_RC32MRDY_bm ) 'wait until the clock is stable
|
13 | ClkSys.Main_ClockSource_Select( CLK_SCLKSEL_RC32M_gc ) 'set the clock as main clock
|
14 | ClkSys.Enable( OSC_RC32KEN_bm ) 'enable the internal 32 khz oscillator
|
15 | ClkSys.WaitReady( OSC_RC32KRDY_bm ) 'wait until the clock is stable
|
16 | ClkSys.RTC_ClockSource_Enable( CLK_RTCSRC_TOSC32_gc ) 'set and enable clock source for the real time clock (RTC)
|
17 | '----------------------------------------------------------------------------
|
18 | 'setup usart
|
19 | '----------------------------------------------------------------------------
|
20 | 'the txd pin of uartc0 must be set to output
|
21 | #define txdc0 as portc.3
|
22 | txdc0.mode = output,high
|
23 | 'configure/enable the standard usart (usartc0)
|
24 | usart.baud = 19200
|
25 | usart.rxd.enable
|
26 | usart.txd.enable
|
27 |
|
28 | #define LED as porte
|
29 | LED.mode = output,high
|
30 |
|
31 | '----------------------------------------------------------------------------
|
32 | 'setup RTC
|
33 | '----------------------------------------------------------------------------
|
34 | RTC.OVF_VECT = RTC_OVF
|
35 | RTC.INTCTRL.OVFINTLVL = 1
|
36 | RTC.CTRL.PRESCALER = 1
|
37 | RTC.PER = 32768
|
38 |
|
39 | dim cnt as byte
|
40 |
|
41 | avr.interrupts.enable
|
42 |
|
43 | print "RTC.PER = ";str(RTC.PER) '<-- Ausgabe immer 0xffff !?!?!
|
44 |
|
45 | do
|
46 | loop
|
47 |
|
48 | 'the RTC overflow interrupt event
|
49 | isr RTC_OVF
|
50 | cnt++
|
51 | porte.value = (not cnt)
|
52 | endisr
|
Frank