Wiblocks --- ATmega Software Reset

ZB1 Software Reset

The ATmega168 lacks a software reset instruction. For the ZB1 a software reset instruction would enable firmware updates through the RF link.

ATmega168 Reset

There are four ways to reset the ATmega168 --- the watchdog timer, the brown-out comparator, the external reset pin and power-on comparator.

Software Reset using the Watchdog

To force a software reset using the watchdog, the watchdog interrupt is enabled and the program is placed in an infinite loop. To make the timeout happen quickly the watchdog counter is set to zero which will force a timeout after approximately 15mS. A reboot command is shown below.

#include <avr/wdt.h>


void reboot() {
  while (1) {}
The standard ZB1 bootloader requires a modification so that the watchdog reset will start the bootloader and not restart the application. In the bootloader code, near the top of the main function is a test to see which type of reset has occured. In the standard bootloader only an external reset will start the bootloader (EXTRF = 1). The code listed below will allow either an external reset or a watchdog reset (WDRF = 1) to start the bootloader.
if (! (ch &  (_BV(EXTRF) | _BV(WDRF)))) // if its a not an external reset...
   app_start();  // skip bootloader

Software Reset using an external pin

If the watchdog is being used an unused output pin could be used to trigger an external reset using a one-shot. The one-shot is necessary to insure that the reset line is held low long enough to guarantee a reset.