Author Topic: Surviving a power failure  (Read 4829 times)

Stewart

  • Newbie
  • *
  • Posts: 2
Surviving a power failure
« on: October 20, 2015, 05:49:42 pm »
I have a Digispark model A with USB permanently connected to a Zotac BI320 running Windows 10. Digispark function is turning digital outputs on and off in response to characters sent over the USB, via the send.exe supplied with the IDE.

It normally runs fine, but if AC power fails and is later restored, the Digispark shows as Unknown (device descriptor read failed).  The Zotac powers its USB ports whenever AC power is present.  The BIOS is set to automatically boot when power is applied.

Once the device shows as unknown, rebooting the PC (or shutting it down then manually pressing power) does not help.  During this time, although the USB interface is nonfunctional, Digispark application code is otherwise running "ok".  Unplugging and reconnecting the device brings it back online.

Strangely, once the Digispark is working, it will survive rebooting the PC (or shutting it down then manually pressing power).

As a test, I added code to setup() that blinks the LED for 60 seconds, before DigiUSB.begin() is called.  With this mod when it's working, Device Manager shows 'Digispark Bootloader' while the light is blinking; it changes to 'DigiUSB' when DigiUSB.begin is called.  When it's not working, Windows boots up and I can log in, start Device Manager and see 'unknown device', all while the LED is still flashing, yet the call to DigiUSB.begin does not get the interface started.

Though I've read that the reset pin is disabled (so it can be used for user I/O), on my unit pulsing it low does reset the ATtiny and it recovers from the unknown device issue.  So, I was thinking of putting some sort of keep-alive function in the app -- if it gets no commands from the PC for e.g. one minute, it would reset itself.  However, I have a few questions:

1. Is this reset function dependable (is it supposed to be disabled, will a future release disable it)?
2. Can I activate it by writing PB5 low, or would hardware be needed?
3. Can I just "jump into the bootloader" instead?  Or, is a hardware reset likely needed?
4. Is there a better way to bring the Digispark back on line?

Thanks,

Stewart

Stewart

  • Newbie
  • *
  • Posts: 2
Re: Surviving a power failure
« Reply #1 on: October 21, 2015, 06:43:37 pm »
... I suspect the Digispark's clock calibration procedure fails when the PC is started from cold state.
Ralf, you are brilliant; many thanks.

I just needed to delay the Digispark startup a little, to allow the PC's USB logic to stabilize.  I found a really low-tech solution: a 2.2 uF capacitor connected from reset to ground, giving ~20 ms extra delay.

In general, this wouldn't be very robust -- a power interruption of just the right length wouldn't discharge the cap enough, so calibration would fail.  But my application has a UPS with ~2 hour runtime; it's extremely unlikely that a failure lasting two hours would hit a window less than 100 ms.

And, if it does calibrate wrong, it turns out that the Zotac does interrupt USB VCC for ~100ms on restart, so rebooting Windows will get it going again.  I hadn't noticed that in previous testing, because the calibration would fail each time, so I was unaware that anything had happened.

Thanks again.