5 years, 9 months ago.

LPC1768 run code before the watchdog timer resets

I'm building a drone using a LPC1768 as flight controller. If the device locks up for some reason, I want the motors to be turned off.

My idea was to do this with a watchdog timer where some code would be executed just before the chip is reset in order to achieve this task. Is this at all possible? (I can't seem to find a way to attach my own ISR to the watchdog or have it execute before the device resets).

1 Answer

5 years, 9 months ago.

The watchdog is a hardware safety feature that is meant to recover the device when the software goes crazy. It would not be smart, nor safe, to allow anything to possibly prevent the hard reset when the watchdog becomes active. consider that any software that would run when the watchdog is triggered, but before the hard reset kicks in, could also become unresponsive or lock up. It is probably not possible to even use the watchdog for that purpose. You might be able to use some other form of interrupt driven solution if you really want something like this. However, the safest way is probably to just allow the watchdog to reset the LPC1768 and make sure that your hardware setup is done in such a way that all motors and other actuators are disabled at reset. You can then check to detect the cause of the reset (regular reset, watchdog reset) and decide either to start the regular program or continue to keep all pins disabled and idle. Note that pins will become inputs at reset and the logic levels will float high.

Accepted Answer

Thank you for the insights! The thing is that the high floating inputs means that some motors will be full power and others be at no power.

I'll add a check which pulls everything down if a watchdog reset has been registered and use interrupt priority to check for any "soft freezes".

posted by Sander Swart 08 Jul 2018

There are more elaborate solutions to make sure a system is fully fail safe, but in your case I would at least change the hardware (eg add a hardware logic level invertor) to make sure all motors and other actuators are off at reset. The system should be in a safe state even when someone presses the reset button forever..

posted by Wim Huiskamp 09 Jul 2018