Is there a way to do a reset with code only?
Any help would be greatly appreciated.
Is there a way to do a reset with code only?
Any help would be greatly appreciated.
Option 1: Configure the watchdog timer to initiate a reset and wait for it to happen
Option 2: Jump to address 0:asm volatile ("jmp 0x0000");
Option 1 will also reset the on-chip peripherals.
Option 1: will cause you problems with most bootloaders since they don't disable the WDT and you'll get caught in a reset cycle. The "no-wait" bootloader from ladyada will get around this. This feature may make it into the bootloader supplied with the next version of the IDE. Either way you'll need a programmer to burn the bootloader onto the chip.
Option 2: Bad idea. This is not really a reset - just a jump to the first address in the program space. All of the chip's registers, settings and RAM will not be properly initialized.
Or use the typical trick with the transistor, usually associated with the XBee wireless upload (an output pin drives a transistor that grounds the reset pin).
Or use the typical trick with the transistor, usually associated with the XBee wireless upload (an output pin drives a transistor that grounds the reset pin).
Another bad idea and explicitly recommended against by the Atmel engineers.
You can't use a digital pin on an ATmega chip to pull the reset pin low. This is because as soon as the reset is initiated, the digital pins get switched to a hi-Z mode and the reset pin will no longer be kept low. According to the datasheet, there is a minimum time that the rest pin must be held low for a proper reset to ensure that the chip is properly initialized. Since the digital pin will switch to the hi-Z state, there's no way to guarantee the proper reset duration.
This will work okay if an external source (such as the XBee) is the one pulling the reset line low.
So another option would be to build some kind of time controlled external one-shot that can be triggered and will pull the reset line low for a fixed amount of time. Something like a 555 timer or a transistor/RC circuit.
Thanks for that, it makes perfect sense. I learned the trick from Rob Faludi's page, here:
http://www.faludi.com/itp_coursework/meshnetworking/XBee/XBee_program_Arduino_wireless.html
Somebody should notify him as well.
The solution is corrected in ladyada's tutorial though (and it uses simpler software as well).
So, a simple RC filter before the transistor wouldn't make it?
The problem is that you need to charge your RC network completely before the transistor gets turned on and pulls the reset low. Remember that the pin your using to supply current to the RC network will stop sourcing current the instant the reset line is pulled low.
Basically you need a precharged circuit with a one-shot trigger. A simple 555 timer in a monostable circuit will do the job (+ a couple of transistors for signal inversion).
Here's an example you could use in place of the RC network (you'll still need the transistor to pull the reset line low).
http://www.doctronics.co.uk/555.htm#monostable
Note that the 555 timer wants a low pulse to start the timer. So you could add an inverting transistor, or simply do a digitalWrite(resetPin,LOW) to trigger it (but be careful how you initialize the pin to prevent accidental resets).