|
21 | 21 | #include <tiam1808/hw/soc_AM1808.h> |
22 | 22 | #include <tiam1808/timer.h> |
23 | 23 |
|
24 | | -/** |
25 | | - * The compare value to set for the 16 least significant bits of the hardware timer |
26 | | - * |
27 | | - * This is the value which causes the interrupt to be triggered every millisecond. |
28 | | - */ |
29 | | -#define TMR_PERIOD_LSB32 0x05CC |
30 | | -/* |
31 | | - * The compare value to set for the 16 most significant bits of the hardware timer |
32 | | - */ |
33 | | -#define TMR_PERIOD_MSB32 0x0 |
| 24 | +// The input to the Timer0 module is PLL0_AUXCLK. This will always run at 24 MHz on the EV3, |
| 25 | +// regardless of what the CPU speed is set to. We configure the timer to generate interrupts |
| 26 | +// every millisecond, and we configure the timer to reset to 0 when it reaches a count value |
| 27 | +// corresponding to one millisecond of time. Finer timing resolution can be obtained by |
| 28 | +// combining the software-managed millisecond counter with the timer value. |
| 29 | +const uint32_t auxclk_freq_hz = 24000000; |
| 30 | +const uint32_t timer_ms_period = (auxclk_freq_hz / 1000) - 1; |
34 | 31 |
|
35 | 32 | /** |
36 | 33 | * The current tick in milliseconds |
@@ -80,7 +77,8 @@ void pbdrv_clock_init(void) { |
80 | 77 |
|
81 | 78 | /* Set up the timer */ |
82 | 79 | TimerConfigure(SOC_TMR_0_REGS, TMR_CFG_32BIT_UNCH_CLK_BOTH_INT); |
83 | | - TimerPeriodSet(SOC_TMR_0_REGS, TMR_TIMER34, TMR_PERIOD_LSB32); |
| 80 | + TimerPreScalarCount34Set(SOC_TMR_0_REGS, 0); |
| 81 | + TimerPeriodSet(SOC_TMR_0_REGS, TMR_TIMER34, timer_ms_period); |
84 | 82 |
|
85 | 83 | /* Register the Timer ISR */ |
86 | 84 | IntRegister(SYS_INT_TINT34_0, systick_isr_C); |
|
0 commit comments