Re:How to measure frequencies with the timer module?
I'm using a solution similar to cb1's. To increase the frequency range I set the match register to 0 and use to match interrupt to detect overflows.
Accuracy is really good At 50 Mhz core clock: Up to ~1 MHz it's just +/- 1 period. 12.5 Mhz input frequency is measured as 12497528 Hz (But there's still some room for improvements).
The ISR (triggered on match):
| Code: | void ISR_Timer0A(void)
{
unsigned long MIS = TIMER0_MIS_R;
TIMER0_ICR_R = MIS; // clear interrupt
TIMER0_TAILR_R = 0xFFFF; // reset timer
TIMER0_CTL_R |= TIMER_CTL_TAEN; // restart timer
periods += 0xFFFF;
}
|
To improve it you could simply skip reading MIS and simply write a fixed value to ICR. And you might want to use bit-banding to restart the timer.
But I've a question too:
The datasheet (LM3S8962) states that the timer is reloaded on match. That doesn't work for me (without the ILR line it doesn't work). Any ideas?
And I think there's something wrong with the GPTMTAR/GPTMTBR register description:
Register 17: GPTM TimerA (GPTMTAR), offset 0x048
This register shows the current value of the TimerA counter in all cases except for Input Edge Count
mode. When in this mode, this register contains the time at which the last edge event took place.
I think "Input Edge Count mode" is mixed up with "Input Edge Timing mode".
login or register to reply
|