This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Not enough timers

My application uses the Softdevice, app_timer and app_pwm. So all timers are in use, but I have to measure two more pwm signals on two input pins. (Those come from HC-SR04 sonar sensors)

I have set up interrupt handlers on raising and falling edges but now I need a time source which is precise enough. When I just use the RTC1 counter which is used by app_timer I get wrong results most of the time. I guess app_timer resets the counter sometimes.

Maybe it would be possible to modify app_timer so I can get a free running timer?(app_timer would have to save the counter value to some variable before reset or something)

So all I need is another time source that just counts up and is at least as precise as the RTC.

  • You can setup a pin the trigger an event on any edge (it is called TOGGLE), so then you can do it like this:

    PPI ch 1: Reset timer on any edge on pin X

    PPI ch 2: Capture timer value on any edge on pin X

    The capture will get the value just before the timer is reset to 0. The CC register will then hold the value of the pulse width before the last edge (either the low pulsewidth or the high pulsewidth depending on the polarity of the edge), if the last edge is the falling edge then you are fine. You can ensure this by not triggering the ultrasonic sensor before you have read the CC register. Let me know if I didn't explain this good enough :)

  • Very good idea! I only trigger the sensor if the previous measurement has finished anyway and so I know that the last edge before the trigger signal was a falling edge.

Related