10 years, 4 months ago.

Increase timer with input

Hello,

I would like to set a value in a timer, which have to increase with an input rising edge. And an interrupt should start when the timer reaches 0.

sorry for my english.

The value should increase with each rising edge? And then generate an interrupt when the timer reaches 0? But that only happens when it overflows, which are alot of rising edges before that happens. So you probably mean it slightly different, please clarify :). Depending on how you mean it exactly it might be possible, if you are willing to directly work with the hardware, so without the mbed libs (at least for this specific part of your program).

posted by Erik - 09 Dec 2013

3 Answers

10 years, 4 months ago.

The micro processors used in mbed have hardware counters that will count external pulses without any processorload. The counters can be preset and will generate an interrupt as soon as they reach zero. However, the mbed libs dont support this peripheral counter since the implementation is hardware dependant (see http://mbed.org/questions/118/Why-are-counters-as-a-peripheral-avoided/). You will have to develop your own software for this function, but there is example code available on the internet (see http://mbed.org/forum/mbed/topic/3876/)

Accepted Answer
10 years, 4 months ago.

I don't think there is an easy way to do this automatically, however it should not be to bad to do it by hand. You should take a look at interrupt in. Then you can attach a function to that interrupt which decrements some counter. Once that counter reaches zero you can set a flag or you can start a new thread to perform some task.

10 years, 4 months ago.

I've already thought about it, but my system really need the processor and I can't interrupt him too much because it won't work at all. My last solution is using 2 mbeds. The main mbed would be interrupted by the second.

Thank you for your answer.

Have you looked at using mbed rtos?

posted by Pennball III 09 Dec 2013