Part Number: TM4C1290NCPDT
Other Parts Discussed in Thread: EK-TM4C1294XL
I need to enable a timer, wait for a pulse and start counting, then stop counting and interrupt on the next pulse. Any examples?
Thanks
Doug
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Part Number: TM4C1290NCPDT
Other Parts Discussed in Thread: EK-TM4C1294XL
I need to enable a timer, wait for a pulse and start counting, then stop counting and interrupt on the next pulse. Any examples?
Thanks
Doug
Hello Doug,
Few questions here...
1) Are you looking to start counting on the first rising edge and then stop counting and interrupt on the second rising edge?
2) When you say interrupt for the second pulse, can you elaborate on this more? Would this be more marking to the application the process is finished?
I ask because to wait for a pulse and start counting makes me think you'd either need to poll or have some sort of interrupt in place to trigger the counting when the first pulse is observed. Unless you want to do polling for this, you'd need interrupts on both pulses.
Hello Ralph,
1) Yes, I want to get the time between the leading edge of two pulses.
2) The interrupt on the second pulse is to go read the time that transpired.
Yes, I suspect I will need to get a GPIO pin interrupt to start the timer, it will mean losing the counts that would have occurred between the pulse edge and the handling of the interrupt and starting the timer - plus the uncertainty if interrupts get stacked up. It might be good enough though.
Thanks,
Doug
Hi Doug,
Okay, makes sense based on your description. I am not sure whether a GPIO interrupt would make the most sense but there are ways to do it with that.
The first thing that comes to mind would be to only use one Timer with some detailed logic to do something like clearing the Timer when you get the first interrupt so it starts back at zero OR storing that value to subtract from your next value on interrupt. I would have to think more about the logic for that and depending what you need in terms of repeated usage I am not sure how all that would work out. But then that would enable you to use just one GPIO. Perhaps just doing a chain method where every interrupt you update the value? Not sure how often these pulses fire or if you are trying to measure a specific pulse based on application trigger. But just having the Timer update every time it interrupts would be the quick and dirty way (though you'll need to account for overflow).
A more complex but possibly more accurate implementation would be something inspired from our timer_edge_capture example for EK-TM4C1294XL LaunchPad in TivaWare 2.2.0.295.
For that example, it is measuring the duration of a pulse so it starts measuring at the rising edge and stops measuring at the falling edge. Since you need rising edge to rising edge, then I think what you would want to do is the following:
1) Step up both Timer A and B for Rising Edge
2) Only enable Timer A to start
3) On rising edge, Timer A will interrupt
4) In the ISR for Timer A, enable Timer B, starting the count.
5) In the ISR for Timer B, store the count and flip a flag to inform that the count as been stored.
What you'll have to decide from there is what logic is used for Timer A on the 2nd interrupt and also how to handle clearing timers. I am not sure how often you need to do this.
Lastly as you mentioned maybe you need to use the GPIO rising edge interrupt to start the Timer instead, but I think then you'd need to either re-configure the GPIO in the process to go from GPIO peripheral to Timer Peripheral OR you'd be back to two GPIO being used for the signal.
Let me know what you think of this information.
Hi Ralph,
Thanks for the feedback, much appreciated. The pulse train isn't that fast, maxing out at about 100 pulses per second; the accuracy of the timing isn't super critical. What I'm thinking of doing now is setting the pins to GPIO, on first edge interrupt starting a (32 bit) timer and on second edge interrupt read the timer value.
I could use the example in the datasheet of using one timer constantly running and another timer to count overflows, however since there are 3 pulse trains to time it would use up 6 timers.
I think all these thoughts solve my issue.
Thanks for your help.
Doug