1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

LPC2138 timers

Discussion in 'Embedded' started by Frank van Eijkelenburg, Jun 29, 2006.

  1. 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
     
    Frank van Eijkelenburg, Jun 29, 2006
    #1
    1. Advertisements

  2. 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 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
     
    Peter Dickerson, Jun 29, 2006
    #2
    1. Advertisements

  3. 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
     
    Frank van Eijkelenburg, Jun 29, 2006
    #3
  4. 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.
     
    Roberto Waltman, Jun 29, 2006
    #4
  5. Frank van Eijkelenburg

    Dave Guest

    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~
     
    Dave, Jun 29, 2006
    #5
  6. 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
     
    Peter Dickerson, Jun 29, 2006
    #6
  7. 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
     
    Peter Dickerson, Jun 30, 2006
    #7
  8. 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
     
    Frank van Eijkelenburg, Jul 1, 2006
    #8
  9. 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
     
    Frank van Eijkelenburg, Jul 1, 2006
    #9
  10. 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
     
    Frank van Eijkelenburg, Jul 1, 2006
    #10
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.