Home arrow Support arrow Forums

Luminary Micro Forums

<< Start < Prev 1 2 Next > End >>

Freddy

Expert Boarder
Click here to see the profile of this user

2008/09/27 06:56

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

Freddy

Expert Boarder
Click here to see the profile of this user

2008/09/27 06:57

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

cb1

Platinum Boarder
Click here to see the profile of this user

2008/09/27 07:36

Re:How to measure frequencies with the timer module?

Freddy-

Yours are great results! (< 0.02% error)

Like you - I believe that too little attention has been given to the counting ability/set-up. (timing is not everything)

Would it not make better sense to employ:
periods += 1; // if periods starts from 0 we then know that periods = 2 indicates 2 rollovers.

I'll check your comment re: Register 17.

login or register to reply

Freddy

Expert Boarder
Click here to see the profile of this user

2008/09/27 08:34

Re:How to measure frequencies with the timer module?

The code to compute the frequency (called once a second):

Code:

 TIMER0_TAILR_R 0xFFFF// reset Timer A0 frequency = (periods + (0xFFFF TIMER0_TAR_R)); periods 0;



cb1 wrote:
Would it not make better sense to employ:
periods += 1; // if periods starts from 0 we then know that periods = 2 indicates 2 rollovers.

That would probably be more useful when you plan to compensate the lost cycles (while the timer is restarted in the interrupt). At that point you have to make assumptions on code execution time...
I prefer having a high resolution on low frequencies.
Of course you could build something dynamic to avoid the overflows...
Some small improvements to the timer module would really help.
A simple option to not disable the counter on match and just keep counting would really help. If the Edge Count mode would allow triggering the Capture Event Interrupt it would be really great.

login or register to reply

Freddy

Expert Boarder
Click here to see the profile of this user

2008/09/27 08:34

Re:How to measure frequencies with the timer module?

The code to compute the frequency (called once a second):

Code:

 frequency periods TIMER0_TAR_R; TIMER0_TAILR_R 0xFFFF// reset timer periods 0xFFFF;



cb1 wrote:
Would it not make better sense to employ:
periods += 1; // if periods starts from 0 we then know that periods = 2 indicates 2 rollovers.

That would probably be more useful when you plan to compensate the lost cycles (while the timer is restarted in the interrupt). At that point you have to make assumptions on code execution time...
I prefer having a high resolution on low frequencies.
Of course you could build something dynamic to avoid the overflows...
Some small improvements to the timer module would really help.
A simple option to not disable the counter on match (simply assert interrupt and keep counting) would really help. If the Edge Count mode would allow triggering the Capture Event Interrupt it would be really great.

Post edited by: Freddy, at: 2008/10/02 12:47

login or register to reply
<< Start < Prev 1 2 Next > End >>