1
\$\begingroup\$

Can I use a capacitor to perform a self-reset / hardware reset of an AVR microcontroller?

The capacitor would be driven low by a pin on the microcontroller. Arduino uses this mechanism for programming via USB to UART bridges.

I would like the DTR pin to come from an internal pin, discharge the cap and pull the RESET to low.

enter image description here

\$\endgroup\$
7
  • \$\begingroup\$ Normally you’d use the watchdog to force a reset. Much easier than using a capacitor \$\endgroup\$
    – Kartman
    Feb 2, 2022 at 10:12
  • \$\begingroup\$ yes, that is a pure software reset. It doesn't completely reset the state of the MCU (registers, ram, etc.). \$\endgroup\$ Feb 2, 2022 at 10:15
  • \$\begingroup\$ Err no. It performs a hardware reset. Refer to the datasheet. Note that with an external reset, ram doesn’t get reset and only specific registers get initialised. A software reset is a jump to the start address. Very different to a watchdog reset. \$\endgroup\$
    – Kartman
    Feb 2, 2022 at 10:17
  • 1
    \$\begingroup\$ You could probably just connect a GPIO to the reset pin. Without configuration, it will be configured as input (high-Z) and the pullup will keep RESET high. To trigger a reset, the GPIO will have to become an output, but once the reset is done, the GPIO will change back to be an input (data direction registers get changed on reset). \$\endgroup\$
    – Sim Son
    Feb 2, 2022 at 10:33
  • 4
    \$\begingroup\$ DTR =0, capacitor charged, DTR=1, double voltage applied to input. Damage may be caused. \$\endgroup\$
    – user263983
    Feb 2, 2022 at 11:11

1 Answer 1

1
\$\begingroup\$

Coming back to this 9M later, it seems there is an official Microchip support answer:

If you want to perform a software reset of your AVR you should use the internal Watchdog. Simply enable it and let it time out. When the Watchdog triggers it resets the program counter back to 0, clears all the registers and performs all the other tasks. This operation gives the same result as pulling the RESET line low.

You should not try to:

  • Use another pin of the AVR to pull the external RESET line. The pins of the AVR are tristated halfway through the minimum reset time, this releases the RESET line and hence nothing happens.
  • Jump to program location 0. Jumping to program location 0 does not clear all the registers and hence you do not have a "clean" reset.

Example Code (GCC) Resetting the AVR every 30mS:

#include <avr/io.h>
#include <avr/wdt.h>

int main(void)
{
    wdt_enable(WDTO_30MS);
    while(1) {};
}

I'm still searching for a hardware alternative, since I think the Watchdog will still consume some amount of power which I'd rather save, even if it's microamps.

\$\endgroup\$
8
  • \$\begingroup\$ @user263983: since the RESET pin is capable of up to 13V and the VCC is 3V3 or 5V, wouldn't this be ok at least for the RESET pin? What do you think about the DTR pin? \$\endgroup\$ Nov 13, 2022 at 10:29
  • 2
    \$\begingroup\$ But if the WDT is enabled only when you want to do a reset, what difference it makes if it consumes few microamps for 30ms? You will spend much more current running the AVR in while loop for the 30ms before WDT resets it, and that is avoidable. And the comment why not use the GPIO to reset itself is contradictory. If nothing happens when pulse is too short, how come the GPIO pin can generate a reset to tristate GPIO to begin with to end up with too short pulse? And surely external components can be used to extend the pulse. What is it you are trying to do or achieve? \$\endgroup\$
    – Justme
    Nov 13, 2022 at 10:37
  • \$\begingroup\$ Also, how about never putting the DTR line to HIGH? (only tri-state by default + LOW to actually reset?) \$\endgroup\$ Nov 13, 2022 at 10:39
  • \$\begingroup\$ @Justme I was under the false impression the watchdog is toggled via fusebits. Since it is software-controlled this is the best approach! \$\endgroup\$ Nov 13, 2022 at 10:41
  • \$\begingroup\$ @Justme: " If nothing happens when pulse is too short, how come the GPIO pin can generate a reset to tristate GPIO to begin with to end up with too short pulse? " - the capacitor would hold the line low for the RESET to happen. \$\endgroup\$ Nov 13, 2022 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.