PDA

View Full Version : Heartbeat LED



ecoli-557
- 11th March 2009, 21:27
I am asking for opinions on how others setup and use a LED to blink periodically to show the system is up and working.

Usuallly I just use a counter in a loop and toggle the LED based on bits in the counter, however, that does not always work well when the program spins waiting on an input.

I am thinking about setting up a timer and set the LED to the overflow?

How do some of you guys do it?

ecoli-557
- 11th March 2009, 22:42
Hey-
I did a better search on this and the 'older' forum and located DT's ASM interrupt used for the heartbeat. No overhead and it works just great with inputs that wait on a keypad.
It works great!

Thanks Darrell!

Jerson
- 12th March 2009, 03:25
Well, having an LED beat to a timer overflow in an interrupt is not a heartbeat at all. It will not tell you if your code is hung or has malfunctioned. All it will tell you is that the interrupt system is functioning. Its a false assurance at best. Similar logic also applies to resetting the watchdog timer within an interrupt. Don't do it in the interrupt is what I can advise. You would want your code to restart if ever it gets hung. You do not want it to falsely clear the watchdog timer and assure you that all is well when it's obviously not.

The best place for such code is in the mainline where your program spends most of its time. If there are other sections in code where you wait for input, it may be a good idea to replicate the code there too. I use a technique where the timer interrupt increments a byte sized counter. The D7 bit of the counter is copied to the Hearbeat Led. If it stops, it means either the timer interrupt has stopped(malfunction) or the program is hung(malfunction). The first one could mean you have shut off the timer or its interrupt. The second one definitely is a malfunction.

ecoli-557
- 12th March 2009, 13:22
Your approach is clearly better for the reasons mentioned.

I will foll around with this notion and see what happens.

Regards.

J. Mark Wolf
- 13th March 2009, 11:31
I like to use a different approach.

I have a one-shot connected to a flashing LED. If the one-shot is allowed to expire the led will flash. If your software "tickles" the one-shot every pass through the main loop, the one-shot remains re-triggered, and the LED remains off.

This way your LED flashes only if your program stops working.

ecoli-557
- 13th March 2009, 14:05
That approach is interesting, and it would solve the internal issues of just blindly working at the code level.

I could use a comparitor to check for the voltage level, and use it with the one-shot for a 'fault' indication as well.......

Thanks for the info. This shows me there really are many different ways to skin a heartbeat <grin>.