LPC2138 timers

I am using a capture pin in combination with a timer of the LPC2138 controller. Each time a rising/falling edge is detected the running timer value is captured and stored in a CAP register. I am using this method to measure timing between the edges and calculate the frequency of the signal (squarewave).

Each time I enter my interrupt service routine I reset the timer (to start a new measurement). Is there a way to do this automatically, because now I have a small gap between the edge and the start point of measurement. I saw that you can automatically reset the timer if a match value is reached, but could not find this possibility for the capture pins.

TIA, Frank

Reply to
Frank van Eijkelenburg
Loading thread data ...

controller.

captured

between

a new

a

Surely that will introduce a error due to the interrupt latency. Shouldn't you be subtracting the previous capture value leaving the time to free run?

you

not

You shouldn't need to reset the timer at all. You want it to keep going so that the results are entiely based on hardware timing without and latency issues (except to respond to the interrupt before the next capture is expected).

Peter

Reply to
Peter Dickerson

Hi Peter,

thank you for the idea. If the timer was used only for measurement, it would work I guess. However, the timer is also used as timeout timer (if for a long period no edges are detected a timeout occures). I could manually detect if the timeout period is elapsed, but this should be done outside the interrupt service routine. Anyway, automatically reset the timer would be the best solution, but I am afraid it isn't possible?!

Frank

Reply to
Frank van Eijkelenburg

service

I

I have a similar situation. (With a different processor.) In my case, the precision required for timeout detection is much lower than the one used to measure time intervals. So I use another lower repetition timer in my system to detect timeouts as follows:

In the ISR for edge detection, reset the "edge" timeout counter every time.

In the lower resolution timer ISR, increment the edge timeout counter and declare a timeout if a limit is exceeded.

Reply to
Roberto Waltman

controller.

captured

new

From the datasheet:

  • Four 32-bit capture channels per timer/counter that can take a snapshot of the timer value when an input signal transitions. A capture event may also optionally generate an interrupt.

If a snapshot of the timer is taken, doesn't the timer continue to run? If it does, no need to reset the timer, just subtract the previous reading from the current CAP reading using the same data width as the CAP register for the math.

~Dave~

Reply to
Dave
[snip]

so

latency

would

long

if the

service

but I

So use two timers. Don't reset the input capture one but reset the timout one. That way you'll get both the timeout and the timing to the nearest clk.

Peter

Reply to
Peter Dickerson

going

solution,

clk.

Alternatively, if the timer supports capture and compare then update the compare value to be capture_value+timeout (modulo timer size) in the capture interrupt. You should only get a compare interrupt if no edge has occured during the timeout interval.

Peter

Reply to
Peter Dickerson

controller.

captured

between

new

The timer does continue to run, but if you looked at the previous posts, you can see that I use it also as timeout timer. So each interrupt the timer has to reset (or the timeout occures while I still receive edge interrupts within time).

Frank

Reply to
Frank van Eijkelenburg

controller.

captured

between

new

The timer does continue to run, but if you looked at the previous posts, you can see that I use it also as timeout timer. So each interrupt the timer has to reset (or the timeout occures while I still receive edge interrupts within time).

Frank

Reply to
Frank van Eijkelenburg

It is supported and a good solution I think, because I already use a second timer for other purposes. So no timers left anymore.

Thanks for your suggestions, Frank

Reply to
Frank van Eijkelenburg

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.