Software reset?

Hi

Maybe a silly question, but is it possible to perform a software reset on the Industruino ?

I did find the following routine which seems to reset the harware but when my program starts it behaves in a different manner.

asm volatile ("  jmp 0");

Something is not quiet right but I'm not sure what..

Thanks

 

Gary Lowe
Gary Lowe
7
| 0 0 0
Asked on 3/11/17, 3:43 PM
0
vote
678 Views

Thanks Stefano, Tom.

My program uses interrupts on CH1, CH2 and CH3 and timing is critical as I need to measure the time between inputs..

Would using the watchdog cause any unecessary delays ?

Thanks

Gary

Gary Lowe
on 3/15/17, 4:46 PM

The watchdog is an hardware timer that needs resetting before it overlaps, otherwise it will reset the machine. The only thing wdt_reset() does is write a zero in a register. You can put your wdt_reset() wherever you like, as long as it gets called at least every 4 seconds. My solution is to do it when Enter is not pressed, so when I keep the Enter button pressed for more than four seconds the machine restarts.

Stefano Giuseppe Bonvini
on 3/15/17, 4:52 PM

Okay. Thanks Stafano..

Gary Lowe
on 3/15/17, 5:00 PM

Hello Gary,
here is how I do it in my projects.
I use Watchdog timer reset.


So first include the watchdog library:

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

Then setup the Watchdog in setup():

void loop() 
  {

  //Enable WDT timer
  wdt_enable(8);                                 //This is equal to WTDO_4S, which is available on AT90USB1286 but probably not reported in wdt.h file
​  }

Then I put this line at the beginning of ReadButtons():

  buttonEnterState = !digitalRead(buttonEnterPin);
  buttonUpState = !digitalRead(buttonUpPin);
  buttonDownState = !digitalRead(buttonDownPin);

  //Reset WDT if Enter not pressed
  //After 8 seconds machine will reset (actually 4)
  //Also in case it hangs for other reasons
  if(buttonEnterState == LOW) wdt_reset();

So if you press the Enter key for more than 4 seconds, the machine will reset.
Hope this is useful!

Stefano Giuseppe Bonvini
Stefano Giuseppe Bonvini
567
| 0 0 0
Answered on 3/13/17, 10:41 AM
0
vote

Hi Gary,

The most reliable way to do this is through the hardware watchdog timer. Another way is defining the function

void (*resetFunc)(void) = 0;

but that does not do a full restart (documented elsewher).

You can read more about watchdog timers at https://industruino.com/page/wdt (sorry for formatting issues)

Tom
Tom
5210
| 0 0 1
Answered on 3/12/17, 11:53 PM
0
vote

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This community is for professionals and enthusiasts of our products and services.

Read Guidelines

Question tools

33 follower(s)

Stats

Asked: 3/11/17, 3:43 PM
Seen: 678 times
Last updated: 3/15/17, 5:00 PM