Computing stuff tied to the physical world

Using watchdog resets

In AVR, Hardware, Software on Nov 9, 2012 at 00:01

The Bluetooth readout node running the “smaRelay” code is ready to go:

DSC 4237

As mentioned yesterday, I’ve decided to take the easy way out and completely power down the Bluetooth module and go through a full powerup/connect/readout cycle about once every 5 minutes.

The advantage for me of a battery-powered unit, is that I don’t have to locate this thing near a power outlet – it can be placed out of sight, unobtrusively doing its work.

I seem to have developed an allergy for power cables and wall warts all over the place…

The power on/off logic held a little surprise, about which I’ll report tomorrow.

Here’s is the new part of the updated smaRelay.ino sketch:

Screen Shot 2012 11 07 at 14 27 33

Quite a different use of the watchdog here:

  • on powerup, go into low-power mode and wait for 5 minutes
  • prepare the watchdog to perform a reset in 8 seconds
  • power up Bluetooth, connect to the SMA, and read out some values
  • then power down Bluetooth and power up the RFM12 radio
  • send out a data packet over RF12
  • lastly, turn the radio off and power down
  • let the watchdog do the reset and make this sketch start over

This approach has as “benefit” that it’ll fail gracefully: even if anything goes wrong and things hang, the hardware watchdog will pull the ATmega out of that hole and restart it, which then starts off again by entering an ultra-low power mode for 5 minutes. So even if the SMA is turned off, this sketch won’t be on more than about 1% of the time.

Here’s the energy consumption measurement of an actual readout cycle:


The readings are a bit noisy – perhaps because I had to use 1 mV/div over a 1 Ω resistor (the 10 Ω used before interfered too much with this new power-switching code).

As you can see, the whole operation takes about 4 seconds. IOW, this node is consuming 153 milli-Coulombs every 300 seconds. That’s 0.5 mC/sec, or 0.5 mA on average. So the estimated lifetime on 3x AA 1900 mAh Eneloops is 3800 hours – some 5 months.

Update – The first set of batteries lasted until March 18th, 2013 – i.e. over 4 months.

Good enough for now. Deploy and forget. Onwards!

  1. “I seem to have developed an allergy for power cables and wall warts all over the place…”

    Ok Nikola Tesla. BTW, may I recommend 18650 batteries?

  2. 18650 batteries are a good idea, I used some old laptop batteries from work and separated out the 18650s and nearly all of them were good.

  3. I have a GSM/GPRS USB modem that goes into a timeout state infrequently, like many days between occurrences, and can only be fixed by powering the modem down, then up again. I gave up trying to find software fixes and designed a simple USB +5V power switch for just that device. On timeouts I simply, under program control of an output GPIO bit from my beaglebone computer, switch +5V power to the modem off, then on, and restart the program.

    On even less frequent occasions the beaglebone will hang. For that I use the builtin watchdog timer (open and leave open /dev/watchdog, and write to it at less than 1 minute intervals.)

    Both solutions are simple and work but neither is elegant.

  4. Hi JCW, I’m wondering what Jeenode that is? Seems like a modified version of a Jeenode USB but without the USB… Hmm,there’s also a reset switch.

    Or am I spoiling something?

    Regards Werner

Comments are closed.