Safe functions in interrupt handler

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
rom1011
Posts: 6
Joined: 24 Sep 2017 22:57

Safe functions in interrupt handler

Post by rom1011 »

Hello,
the documentation of the ZUno interrupt handlers states that only pinMode(), digitalRead() and digitalWrite() are safe to call from interrupt handlers.
I would like to call the micros() function to measure time between pulses. Will that cause any problems? Any alternatives you could think of?

Thanks
-Roland

petergebruers
Posts: 249
Joined: 26 Jul 2015 17:29

Re: Safe functions in interrupt handler

Post by petergebruers »

I think Z-Uno does not have a micros() function. I might be wrong about that, but I cannot find it in the Z-Uno libraries and it is not listed on the reference page. Did you mean to write "millis()"?

Out of curiosity, what resolution do you need?

Would counting in the 1ms timer interrupt work for you?

http://z-uno.z-wave.me/Reference/1msTimer/

User avatar
PoltoS
Posts: 5824
Joined: 26 Jan 2011 19:36

Re: Safe functions in interrupt handler

Post by PoltoS »

Using deep functions in the interrupt is bad as it can kill the stack.

In your case as suggested by @petergebruers you are suggested to use 1ms or GPT timer and increment a global variables. Use this variable as your tick counter in another interrupt handler

rom1011
Posts: 6
Joined: 24 Sep 2017 22:57

Re: Safe functions in interrupt handler

Post by rom1011 »

Thanks for the feedback - will use the timer to provide the ticks. I will only get a handful pulses per second so the 1ms timer should provide plenty of accuracy.
And yes petergebruers - there is no micros() on ZUno - thanks for pointing that out. Am still a newby on the ZUno. But it rocks!

-Roland

petergebruers
Posts: 249
Joined: 26 Jul 2015 17:29

Re: Safe functions in interrupt handler

Post by petergebruers »

Join the club of happy newbies :-) ... and happy hacking!

Post Reply