software reset

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

hello friends,

please help me to clear out my one doubt... can we reset a micro controller by program? if yes, then how can we reset an atmega32 micro controller by program. please help me.. thank you very much

 

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

Enable the watchdog but don't kick it. It will time out and reset the AVR.

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

As Kartman says. Use the watchdog.

 

Another 2 ways to do this (though not as good):

 

1) just JMP 0x0000 and the code will restart - note however that all the peripherals will already be configured.

 

2) use an I/O line to pull the _RESET line low. However you may need some kind of pulse extending circuitry to guarantee it is held low long enough.

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

Kartman wrote:

Enable the watchdog but don't kick it. It will time out and reset the AVR.

thanks for your reply sir.... sir it will be more helpful for me if you explain it little more clearly...what is meant by don't kick it? if we enable watchdog timer then after how much time the watch dog timer will time out?

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

ecworks wrote:
if we enable watchdog timer then after how much time the watch dog timer will time out?

You get a choice:

#define 	WDTO_15MS   0
#define 	WDTO_30MS   1
#define 	WDTO_60MS   2
#define 	WDTO_120MS   3
#define 	WDTO_250MS   4
#define 	WDTO_500MS   5
#define 	WDTO_1S   6
#define 	WDTO_2S   7
#define 	WDTO_4S   8
#define 	WDTO_8S   9

the shortest period is 15ms (the default) so once you enable the watchdog you just sit in a loop (while(1);) doing nothing and 15ms later the AVR will reset itself.

 

As for "kick" - the way you normally use a watchdog is to enable it send set the period to "longer than I expect this to take". You then enter a loop or whatever and the watchdog begins to count down. While the AVR is still "alive" you keep issuing the WDR opcode from time to time and as you do the countdown timer restarts and counts down again. As long as it never reaches 0 the AVR will never reset. Only if something goes wrong and the AVR gets stuck in a code loop where it never gets a chance to execute WDR will the counter finally reach 0 and reset the AVR.

 

The execution of WDR is known as "kicking the dog".

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

thank you all my friends, thanks clowson.. thanks for your valuable suggestions....

 sir, the below program is right? will it reset controller when get a character "r" from uart?

 

#include<avr/io.h>
#include<util/delay.h>
#include <avr/wdt.h>
#include "uart.h"
char i;

void main()
{
    uart_init(9600);

        
        uart_puts("program to reset");    

    while(1)
    {
    
        if(uart_data_ready())
         {
             i=uart_data();
             uart_write(i);
         }
        if(i=="r")
        {
              wdt_disable();  
               wdt_enable(WDTO_15MS);
        }
        
    }  //while(1)

} // main

    

 

Last Edited: Tue. May 3, 2016 - 10:20 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You would normally enable the watchdog at the beginning of your program and do wdt() regularly. If youvwant to reset, you stop doing wdt() and the watchdog times out.

Apart from your program having sone simple defects, you would add a while(1); after the wdt_enable() ensuring the watchdog will time out.

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

Kartman wrote:

You would normally enable the watchdog at the beginning of your program and do wdt() regularly. If youvwant to reset, you stop doing wdt() and the watchdog times out.

Apart from your program having sone simple defects, you would add a while(1); after the wdt_enable() ensuring the watchdog will time out.

 ok sir, thanks for your sincere reply...

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

Be also careful that the watchdog will still be enabled after the reset, so you either:

- Do as Kartman suggested and do wdt_reset() regularly, or

- Disable the watchdog at the beginning of your main() function (see your device datasheet, it is explained how to do so there).

Have a nice day,
Kraal