Pages: [1]   Go Down
Author Topic: Hardware circuit to Trigger Board Reset through software  (Read 808 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hardware circuit to Trigger Board Reset through software - In essence, push the reset button through a software trigger

Ok, I don't know if this is the right section to post this in but I thought I would share this since I couldn't find an answer when I was searching for this so hopefully the next person needing to "push the reset button through software" will be able to find and use this.

I needed a way to reset the board through software for my project without causing issues with uploading new software to the chip. I had found one solution online but you had to disconnect the trigger pin every time you wanted to upload a new sketch which was not a viable solution to me. So I build the following circuit:
http://i1040.photobucket.com/albums/b409/Initialforce/HardwareReset_zpsfa99e2a4.jpg

Capacitor is charged by Pin 15 (on my Mega). The first transistor is triggered by Pin 14 which in turn causes the capacitor to latch the first transistor open until discharged which in turn triggers the 2nd transistor to open and ground the reset pin. When the board resets itself it automatically writes all digital Pins to LOW and the circuit closes after the capacitor is discharged. I ran my Mega through 30 some test runs in 10 second intervals and it's working great. Holds the reset pin LOW just long enough to trigger the reset. Have not tested this on any other board but in theory, if it doesn't work on another board because it does not hold it open long enough you could always bump up the capacitor value.

Code wise here is what you need (and yes I am fully aware this is not actually a HARD Reset but that's what I called it in my sketch):
Declare you pins:
const byte HardResetPowerPin = 15;
const byte HardResetTriggerPin = 14;

Write the following in void Setup:
  // Set HardResetPins to OUTPUT
  pinMode(HardResetPowerPin, OUTPUT);
  pinMode(HardResetTriggerPin, OUTPUT);
  // Set HardResetTriggerPin LOW (just in case)
  digitalWrite(HardResetTriggerPin, LOW);
  // Power Reset Capacitor
  digitalWrite(HardResetPowerPin, HIGH);

Then at any point you want to trigger the Reset:
digitalWrite(HardResetTriggerPin, HIGH);

I have read quite a few horror stories about people locking their board with some software reset loop, unable to upload a new sketch to fix it because it is constantly resetting itself, so I personally prefer this method over any others I have been able to find online because if you accidentally get it stuck in a reset loop, simple disconnect the ground from transistor #2 or disconnect the reset pin on the board.

Hope this is of help to someone out there.
« Last Edit: January 05, 2013, 02:19:16 am by InitialForce » Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

transistors are backwards to start with


* reset.jpg (15.31 KB, 448x217 - viewed 24 times.)
« Last Edit: January 05, 2013, 04:08:46 am by Osgeld » Logged


Germany
Offline Offline
Faraday Member
**
Karma: 59
Posts: 3057
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Regarding Osgeld's sketch ( which is sufficient for that task ) :
There's already a built in pullup resistor between RESET and +5V.
As this is pretty high ( 10k ? ), the other resistor is not critical. Anything  (or rather  470 ... 47k ) would do, with any npn transistor.

Main reason for more electronics than a wire between trigger pin and reset is, to allow startup with a wrong sketch.
Else a simple wire were sufficient :

Code:
// Sample software to trigger Reset
// requires nothing but a wire between Pin 9 and Reset
# define resetTriggerPin 9
boolean wannaReset=false;

void setup()
{
  digitalWrite (resetTriggerPin, HIGH);  // another pullup resistor for RESET
  digitalMode (resetTriggerPin, OUTPUT); // order matters
}
void loop()
{
   // TODO: add code to eventually set wannaReset to true
   if ( wannaReset ) digitalWrite(resetTriggerPin, LOW);
}
 

BTW: It's more challenging to setup something that inhibits a reset, but only during some critical phase in your sketch. ( Well, to temporarily avoid a reset via Serial should be doable ) 
Logged

Valencia, Spain
Online Online
Faraday Member
**
Karma: 146
Posts: 5524
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just connect the reset pin to another I/O pin...

When you want to reset set the port to OUTPUT then set it LOW.
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just connect the reset pin to another I/O pin...

When you want to reset set the port to OUTPUT then set it LOW.


Doing this will cause a reset loop and even if you force write the pin HIGH on start up this will mean you will not be able to upload a new sketch without disconnecting the pin (not sure if this is true on the UNO or Mega but my planned chip is a stand along ATMega1284P_PU without all the extra hardware on the board that we take for granted)... my project is stand alone aka disconnecting the reset pin means opening up my project box every time I want to try a new sketch.
« Last Edit: January 05, 2013, 06:22:42 am by InitialForce » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

transistors are backwards to start with

Much simpler. I went with the capacitor mainly because I had read that the manufacturer doesn't recommend using just the power of a pin without some sort of way to ensure the reset is held sufficiently long. Was I miss lead here?

As for the backwards transistor... I am new to drawing circuitry lol and the transistor I am using is bipolar (which I assume means it can go both ways because it works either way on my breadboard).
« Last Edit: January 05, 2013, 06:13:13 am by InitialForce » Logged

Valencia, Spain
Online Online
Faraday Member
**
Karma: 146
Posts: 5524
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Much simpler. I went with the capacitor mainly because I had read that the manufacturer doesn't recommend using just the power of a pin without some sort of way to ensure the reset is held sufficiently long. Was I miss lead here?

If you're using an I/O pin for reset then it's impossible to hold it for too short a time. It will be held low until reset happens, no more, no less.
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can force a hardware reset using the watchdog timer, which is what I do in my projects. The only complication is that some of the older bootloaders don't disable the watchdog when they start up. One way round this is not to use a bootloader - you don't need one anyway if it's a standalone system, you can program it via ICSP instead.
« Last Edit: January 05, 2013, 09:09:15 am by dc42 » Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just connect the reset pin to another I/O pin...

When you want to reset set the port to OUTPUT then set it LOW.


AVR cautions against using that method as it will not reliably allow a full legal reset condition. The problem is that the start of the reset process all I/O pins are set to input mode, thus losing the low being wired to the reset pin. There is a minimum length that the low reset pulse must meet to fully satisfy a hardware reset condition. Using the WDT is the only way to create a true reset condition under software only control unless you utilize some external components like a 555 timer chip to create the needed reset signal length.

Lefty
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the info guys, I just ready up on WatchDogTimer and this will defiantly help me.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 80
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dc42, could you please share the code you used to perform a full hard reset?

Many thanks in advance

Regards from Brasil, simon
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

At the start of setup() I use this code to disable the watchdog after the reset:

Code:
  // Turn off watchdog timer
  cli();
  wdt_reset();
  MCUSR = 0;    // clear watchdog reset flag
  WDTCSR |= (1 << WDCE) | (1 << WDE);
  WDTCSR = 0x00;
  sei();

When I want to reset the processor I use this:

Code:
  cli();
  wdt_reset();
  WDTCSR |= (1 << WDCE) | (1 << WDE);
  WDTCSR = (1 << WDE) | (1 << WDP2);    // reset after 0.25 sec
  for (;;) {}

This is on an atmega328p running at 8MHz. I'm not using a bootloader, so 0.25sec is ample time for the processor to be reset and control passed to setup(), provided you don't have any static initializers doing complicated things that they probably shouldn't be doing anyway.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Pages: [1]   Go Up
Jump to: