EEVblog Electronics Community Forum

Electronics => Beginners => Topic started by: scott216 on October 12, 2014, 11:05:26 pm

Title: LED to indicate Arduino is running
Post by: scott216 on October 12, 2014, 11:05:26 pm
From time to time I'll have an Arduino lock-up.  In the past if I wanted to check for a lock-up I setup a heartbeat LED which will blink when the Arduino is running.  If the program hangs, the LED will stop blinking.  I have a project now where I want the LED to stay on continuously if the sketch is running and turn off if the Arduino locks-up.  I was thinking I could still have a heartbeat output, but instead of going directly into an LED, it would go into a little circuit which controls the LED. The circuit would look for the heartbeat and if it didn't see a heartbeat, the LED would turn off. I don't know how to build a circuit that would do this. Any suggestions?
Title: Re: LED to indicate Arduino is running
Post by: suicidaleggroll on October 12, 2014, 11:15:19 pm
How have you controlled the heartbeat in the past?  What if the Arduino locks up while the output is high instead of low?  Doesn't Arduino have a watchdog timer?

I've never used an Arduino, is locking up really that common?  It seems like a fundamental problem that should be fixed, rather than jumping through hoops trying to implement some kind of signal to tell you when it's screwing up.  Maybe if it's that big of an issue you should use a different (aka: more reliable) platform?

I can think of a lot of ways to accomplish this, but it all seems like a roundabout way to notify the user of a problem that should never happen in the first place.
Title: Re: LED to indicate Arduino is running
Post by: ludzinc on October 12, 2014, 11:17:33 pm
Just use the output to retrigger a monostable multivibrator.

Typically a 555 is used for this, amongst other options.

See here:  http://www.eleinmec.com/article.asp?4 (http://www.eleinmec.com/article.asp?4)
Title: Re: LED to indicate Arduino is running
Post by: scott216 on October 12, 2014, 11:22:48 pm
How have you controlled the heartbeat in the past?  What if the Arduino locks up while the output is high instead of low?  Doesn't Arduino have a watchdog timer?

I've never used an Arduino, is locking up really that common?  It seems like a fundamental problem that should be fixed, rather than jumping through hoops trying to implement some kind of signal to tell you when it's screwing up.  Maybe if it's that big of an issue you should use a different (aka: more reliable) platform?

If the LED stops blinking I don't care if the output is high or low, I'll see that it stops blinking.  It's doesn't happen much, I think the Arduino is pretty reliable.  I've seen it generally happen with some sort of communication problem, like with Ethernet or I2C, and also with a memory problem.  Like a string was too long or it ran out of memory. 

Watchdog timer works on some Arduinos and not others - I think it depends on the bootloader.  One problem with watchdog is it kind-of hides the problem.  The Arduino could be hanging and rebooting and I wouldn't know it.




Title: Re: LED to indicate Arduino is running
Post by: scott216 on October 12, 2014, 11:24:37 pm
Just use the output to retrigger a monostable multivibrator.

Typically a 555 is used for this, amongst other options.

See here:  http://www.eleinmec.com/article.asp?4 (http://www.eleinmec.com/article.asp?4)

Thanks, I'll check that out.  I figured a 555 would probably be involved one way or another.
Title: Re: LED to indicate Arduino is running
Post by: suicidaleggroll on October 12, 2014, 11:27:32 pm
Just use the output to retrigger a monostable multivibrator.

Typically a 555 is used for this, amongst other options.

See here:  http://www.eleinmec.com/article.asp?4 (http://www.eleinmec.com/article.asp?4)

Thanks, I'll check that out.  I figured a 555 would probably be involved one way or another.

Remember the comment I made about it failing high or low.  You don't want a solution that counts in one state and resets in another, you need a solution that counts in steady state (high or low) and resets on transitions.
Title: Re: LED to indicate Arduino is running
Post by: zapta on October 12, 2014, 11:30:16 pm
You want a ''retrigerable" and  "edge triggered" monostable, like this one (there are many others)

http://www.nxp.com/documents/data_sheet/74LVC1G123.pdf (http://www.nxp.com/documents/data_sheet/74LVC1G123.pdf)
Title: Re: LED to indicate Arduino is running
Post by: scott216 on October 13, 2014, 01:15:09 am
Thanks for all the help.  I just built this circuit with a 555 timer and it looks like it should do what I need.
http://www.doctronics.co.uk/555.htm#retriggering (http://www.doctronics.co.uk/555.htm#retriggering)
Title: Re: LED to indicate Arduino is running
Post by: SL4P on October 13, 2014, 02:32:12 am
...turn off if the Arduino locks-up.
Isn't that a bit indeterminate?  If it locks up - putting a LED toggle conveniently in the (buggy) lock-up code may be harder than it appears (why not fix the code?) !

Or put your LED toggle somewhere within the main loop(), perhaps with a divider to make it 'visible'... say 5Hz or whatever.  Then you'll see when the loop has become 'locked-up'.  Perhaps even using an interrupt & counter to restart or break out of your code (a-la watchdog style).

Even better, you can update a global variable at various places in your code, and oly when the crash timer fires - read that variable to see the most recent place the variable was updated (i.e. most recent updated value from your code).
Title: Re: LED to indicate Arduino is running
Post by: zapta on October 13, 2014, 04:56:15 am
Thanks for all the help.  I just built this circuit with a 555 timer and it looks like it should do what I need.
http://www.doctronics.co.uk/555.htm#retriggering (http://www.doctronics.co.uk/555.htm#retriggering)

If your MCU will get stuck in the trigger state the LED will stay on.  This is why you want an edge triggered monostable.
Title: Re: LED to indicate Arduino is running
Post by: kolbep on October 13, 2014, 05:54:57 am
Enable the WDT, and possibly BOR,
then have code at the start of the program, that if, when it starts up, it detects that it was a WDT reset or BOR (anything really except for normal powerup), if it does see the flag, then light up a LED to let you know it locked and was restarted.

Although, I am more used to PICS, so I do not know what functionality like that the Arduino has.
Title: Re: LED to indicate Arduino is running
Post by: scott216 on October 13, 2014, 11:54:29 am
Thanks for all the help.  I just built this circuit with a 555 timer and it looks like it should do what I need.
http://www.doctronics.co.uk/555.htm#retriggering (http://www.doctronics.co.uk/555.htm#retriggering)

If your MCU will get stuck in the trigger state the LED will stay on.  This is why you want an edge triggered monostable.

Good point.  Thanks.
Title: Re: LED to indicate Arduino is running
Post by: scott216 on October 13, 2014, 12:06:54 pm
Enable the WDT, and possibly BOR,
then have code at the start of the program, that if, when it starts up, it detects that it was a WDT reset or BOR (anything really except for normal powerup), if it does see the flag, then light up a LED to let you know it locked and was restarted.

Although, I am more used to PICS, so I do not know what functionality like that the Arduino has.

What's BOR?  I'm not sure if there's a way for the Arduino to know it restarted from a timeout; I'll check for this on the Arduino forum, maybe there's a way.

BTW - I haven't event done the programming for this project yet, so I it may never hang-up.  I'm just trying to anticipate problems.  It's my first project using RS-485 communication (Arduino is receiving only, no sending). 
 
Title: Re: LED to indicate Arduino is running
Post by: ozwolf on October 13, 2014, 12:15:43 pm
Why not try one of these from Freetronics?

http://www.freetronics.com/products/watchdog-timer-module#.VDvBDqEcSt8 (http://www.freetronics.com/products/watchdog-timer-module#.VDvBDqEcSt8)

Documentation says that the module will actually blip the reset line if Arduino locks up.
Title: Re: LED to indicate Arduino is running
Post by: scott216 on October 13, 2014, 12:22:05 pm
Why not try one of these from Freetronics?

http://www.freetronics.com/products/watchdog-timer-module#.VDvBDqEcSt8 (http://www.freetronics.com/products/watchdog-timer-module#.VDvBDqEcSt8)

Documentation says that the module will actually blip the reset line if Arduino locks up.

That would work.  I see in the schematic it uses a 555.  Is this an edge-triggered monostable circuit or something different? 
Title: Re: LED to indicate Arduino is running
Post by: Kjelt on October 13, 2014, 12:54:06 pm
Try to find out where the uC hangs, if it is for instance I2C than it could be that one of the I2C chips "hangs" the bus. In that case you can try to reset that chip or clear the bus by transmitting some I2C CLK signals. If that still does not help you should reboot the whole pcb. In any case it is better to first try to recover from an error and determine exactly what causes the error.
Title: Re: LED to indicate Arduino is running
Post by: ozwolf on October 13, 2014, 12:57:45 pm
Why not try one of these from Freetronics?

http://www.freetronics.com/products/watchdog-timer-module#.VDvBDqEcSt8 (http://www.freetronics.com/products/watchdog-timer-module#.VDvBDqEcSt8)

Documentation says that the module will actually blip the reset line if Arduino locks up.

That would work.  I see in the schematic it uses a 555.  Is this an edge-triggered monostable circuit or something different?

Have a read of the Quickstart Guide and you will note that the module requires your code (sample code in Guide) to blip an I/O pin (connected to IN) at intervals < default 5 mins or optional 1 minute.  So all you're doing is resetting the 555 module before it has a chance to time out and fire the OUT which is connected to your RESET pin on microcontroller.

I haven't used this module myself, as I'm happy with using the Timer ISR routine on the Arduino to flash the LED on pin D13 at 1/2 second intervals.  My logic being that if the Arduino is locked up the Timer ISR will fail as well.  However, my method will not RESET automatically like the Watchdog Timer Module does.
Title: Re: LED to indicate Arduino is running
Post by: SL4P on October 13, 2014, 06:36:37 pm
...logic being that if the Arduino is locked up the Timer ISR will fail as well...
Not strictly true. (Sorry Oz!)
If your code is in a 'deadly embrace' loop - the ISR will continue to fire - with the LED blinking happily while the code does nothing...!

e.g: http://www.pcmag.com/encyclopedia/term/41017/deadly-embrace (http://www.pcmag.com/encyclopedia/term/41017/deadly-embrace)
Title: Re: LED to indicate Arduino is running
Post by: firewalker on October 13, 2014, 08:00:19 pm
Why don't you use the watchdog included to the AVR chip? If there is a lockup it will reset the chip, and will flip a register bit. Using that bit you can later hard reset the chip (if needed).

Alexander.
Title: Re: LED to indicate Arduino is running
Post by: scott216 on October 13, 2014, 08:11:50 pm
Why don't you use the watchdog included to the AVR chip? If there is a lockup it will reset the chip, and will flip a register bit. Using that bit you can later hard reset the chip (if needed).

Alexander.
I just found out about the register bit the watch dog timer resets.  I might use a WDT instead.
Title: Re: LED to indicate Arduino is running
Post by: kolbep on October 13, 2014, 08:27:46 pm
BOR = brown out reset.
the micro ia held in reset until the supply voltage exceeds a settable limit.

That way if the battery goes flat, or the powersupply gives a low voltage, then the Micro does not behave eratically.
Title: Re: LED to indicate Arduino is running
Post by: SevenLeggedSheep on October 14, 2014, 04:27:14 am
Feed your "running" pulse into C48. Take the output (Arduino OK) from R122.

Change R111 and C47 to your requirements, this circuit is designed to provide lockup indication for a PIC very quickly.

It's only a simple enhancement to a very standard 555 heartbeat circuit, and it works reliably.

HTH
Title: Re: LED to indicate Arduino is running
Post by: ozwolf on October 14, 2014, 10:46:10 am
...logic being that if the Arduino is locked up the Timer ISR will fail as well...
Not strictly true. (Sorry Oz!)
If your code is in a 'deadly embrace' loop - the ISR will continue to fire - with the LED blinking happily while the code does nothing...!

e.g: http://www.pcmag.com/encyclopedia/term/41017/deadly-embrace (http://www.pcmag.com/encyclopedia/term/41017/deadly-embrace)

That's why I like this forum.  Always an opportunity to learn.  You're right.  Searching "arduino watchdog timer" on Google, throws up quite a few good examples and solutions.  Didn't even know there was an on-board WDT.
Title: Re: LED to indicate Arduino is running
Post by: Psi on October 14, 2014, 10:57:45 am
From time to time I'll have an Arduino lock-up.  In the past if I wanted to check for a lock-up I setup a heartbeat LED which will blink when the Arduino is running.  If the program hangs, the LED will stop blinking.  I have a project now where I want the LED to stay on continuously if the sketch is running and turn off if the Arduino locks-up.

i have a simple idea, no need for a 555.
Generate some high frequency pulses/AC with the mcu (ideally in software and not using a hw timer). Coupled that signal to a LED through an appropriately sized capacitor.

If the mcu is running current will flow through the cap and light the LED up, if the mcu stops the switching stops and the cap will blocks DC so LED=off

You can use Xc = 1/(2 pi F C)  to calculate the reactance in ohms of a cap at a set frequency.
Title: Re: LED to indicate Arduino is running
Post by: richard.cs on October 14, 2014, 11:14:45 am
i have a simple idea, no need for a 555.
Generate some high frequency pulses/AC with the mcu (ideally in software and not using a hw timer). Coupled that signal to a LED through an appropriately sized capacitor.

If the mcu is running current will flow through the cap and light the LED up, if the mcu stops the switching stops and the cap will blocks DC so LED=off

You can use Xc = 1/(2 pi F C)  to calculate the reactance in ohms of a cap at a set frequency.

^ This.

You'll need a diode in antiparallel with the LED or you'll just pump the anode down negative and it'll turn off. Given you're hitting it with squarewaves I would still include some series resistance with the LED, maybe make that the dominant thing limiting the current and make the capacitor reactance small in comparison. If you wanted a low frequency you could make the capacitor large and then have a second capacitor that holds the LED on during the off cycle.
Title: Re: LED to indicate Arduino is running
Post by: max_torque on October 14, 2014, 11:27:08 am
As mentioned, and AC coupled charge pump circuit is a low component count solution, and if you "set" the output port in one critical function and "unset" it in another it also validates that both those functions are being called and running appropriately!

(ie, do a software bitbang port drive, not using a hardware periferal like PWM etc, and don't toggle the port but set and unset it seperately)
Title: Re: LED to indicate Arduino is running
Post by: SL4P on October 14, 2014, 12:30:06 pm
My (last) word...   I'd forego the added hardware - but carefully plan & test a software solution (perhaps patched WDT).  Nothing extra to fail, and the chip already has everything you want - it just needs to be corralled into a solution for your requirements.
Title: Re: LED to indicate Arduino is running
Post by: Seekonk on October 14, 2014, 05:56:59 pm
A little programming error led me to this little trick.  I was driving a FET and it stayed on long after it was supposed to turn off in the program.  I looked for a logic error and couldn't find one.  What I had done was forget to declare that pin as an output.  After it wrote a one to that pin, that pin returned to being a floating input.  FET gate capacitance kept the FET on till the charge drained off.  I figure that trick has to be useful some day.