Reply by Frank van Eijkelenburg June 30, 20062006-06-30
Peter Dickerson wrote:
> "Peter Dickerson" <first{dot}surname@tesco.net> wrote in message > news:8jWog.9$Xp3.2@newsfe4-gui.ntli.net... >> "Frank van Eijkelenburg" <someone@work.com.invalid> wrote in message >> news:44A3FC9B.5010001@work.com.invalid... >>> Peter Dickerson wrote: >> [snip] >>>> 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 >>>> >>>> >>> 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?! >> 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. > > 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 > >
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 by Frank van Eijkelenburg June 30, 20062006-06-30
Dave wrote:
> On Thu, 29 Jun 2006 17:27:53 +0200, Frank van Eijkelenburg wrote: > >> 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. > > 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~
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 by Frank van Eijkelenburg June 30, 20062006-06-30
Dave wrote:
> On Thu, 29 Jun 2006 17:27:53 +0200, Frank van Eijkelenburg wrote: > >> 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. > > 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~
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 by Peter Dickerson June 30, 20062006-06-30
"Peter Dickerson" <first{dot}surname@tesco.net> wrote in message
news:8jWog.9$Xp3.2@newsfe4-gui.ntli.net...
> "Frank van Eijkelenburg" <someone@work.com.invalid> wrote in message > news:44A3FC9B.5010001@work.com.invalid... > > Peter Dickerson wrote: > [snip] > > > > > > 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 > > > > > > > > > > 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?! > > 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. 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 by Peter Dickerson June 29, 20062006-06-29
"Frank van Eijkelenburg" <someone@work.com.invalid> wrote in message
news:44A3FC9B.5010001@work.com.invalid...
> Peter Dickerson wrote:
[snip]
> > > > 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 > > > > > > 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?!
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 by Dave June 29, 20062006-06-29
On Thu, 29 Jun 2006 17:27:53 +0200, Frank van Eijkelenburg wrote:

> 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.
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 by Roberto Waltman June 29, 20062006-06-29
Frank van Eijkelenburg wrote:
>.... 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?!
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 by Frank van Eijkelenburg June 29, 20062006-06-29
Peter Dickerson wrote:
> "Frank van Eijkelenburg" <someone@work.com.invalid> wrote in message > news:482ef$44a3f118$3e3aa7a5$13428@news.versatel.net... > >>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 > > 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? > > >>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. > > > 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 > >
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 by Peter Dickerson June 29, 20062006-06-29
"Frank van Eijkelenburg" <someone@work.com.invalid> wrote in message
news:482ef$44a3f118$3e3aa7a5$13428@news.versatel.net...
> 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 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?
> 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.
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 by Frank van Eijkelenburg June 29, 20062006-06-29
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