Q: RESET under AVR program control?

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

I have a situation where I want to cause the AVR to reset itself (i.e. re-execute from the beginning of the code, like a power-on reset).

Is there a way to do this under program control? I am using WinAVR GCC.

For the Cypress PSoC compiler, I just extern'd the symbol "__Start" as a function and executed _Start().

Thanks,

Steven

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1) Just rjmp to the beginning of the program.

2) Use the watchdog to do the reset. With the watchdog enabled, and of course properly serviced, you can jump to a line of code that jumps to itself. This would stop the watchdog being reset and it will reset the processor.

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

While on the subject, does anyone know how to get the hardware in the AVR device to be reset to the default state - this is mostly about I/O and registers.

Rick

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's why using the watchdog was mentioned. When you enable the watchdog timer AND you sit in an infinite loop without resetting the watchdog (also called kicking the watchdog), the the watchdog will timeout and cause a processor reset. When this happens, all the processor registers will be reset to their default state. This is highly desirable when doing a reset as then your code will go through the normal initialization routines and the registers will then be in a known state. If you do a "soft" reset by jumping to the beginning of the program, then the register may not be in the correct default state (unless your program touches every single register during an init routine).

avr-libc (The C library portion of WinAVR) contains a watchdog API. See the documentation here:

Also here are 3 articles about watchdog timers:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also, for GCC specific questions (this also means WinAVR), post in the AVR GCC Forum.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

By the way I clear all used RAM and ALL REGISTERS as part of the inint routine. This starts the program with all variables in a known state. It saves lots of headache chasing initial bugs that are caused by something not being in the state it should have been.

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah. And personally I think it's also advisable after initializing numerous port pins to their application specific default states to put in a little break (100ms or more) to let things settle down - especially if your pins are supposed to drive capacitive and inductive peripheral loads.

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"By the way I clear all used RAM and ALL REGISTERS as part of the inint routine. This starts the program with all variables in a known state. It saves lots of headache chasing initial bugs that are caused by something not being in the state it should have been."

I hope you are referring to general-purpose registers, not I/O registers.

SRAM and general-purpose registers have undefined values at reset. C prologue by definition will initialize global variables to 0 (if no specific intializer). Local variables in >>any>not<< have the correct values after the appropriate reset type, the chip is defective and should be discarded.

Lee

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

>I hope you are referring to general-purpose registers, not I/O registers.

Yes R0-R31.

>. C prologue by definition will initialize

Us 'real" programmers that use assembler have to that ourselves :-))

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Us 'real" programmers that use assembler ..."

But OP spec'ed GCC.

Lee

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

True, but WinAVR comes with an assembler too. In fact it's necessary for GCC.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Steven.

If you need a really fast (full) reset, you may hardwire an unused I/O pin to the /Reset pin, and configure it as output @ HI state.
You may also use a resistor/capacitor/diode network in order to be able to use the /Reset line externally, too. All you have to do is to clear it (cbi PORTx,PBy) to have a hardware reset; in 2 only cycles.

Regards, Giorgos.