Pages: [1]   Go Down
Author Topic: Reset Interrupt possible?  (Read 783 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

I would like to know if it is possible to reset the arduino with code only?
I know the highest priority interrupt is the reset interrupt but how do I use it on code?

Thanks
Ard
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 636
Posts: 50275
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I would like to know if it is possible to reset the arduino with code only?
This has been discussed many, many times. The answer is almost always the same - don't do that; fix the code that is causing the problem.

So, what problem do you have that you hope resetting will solve?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26495
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Gosh. Twice in a week.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

smiley-sad  sorry...

The 50 day millis() overflow Problem.

I have some code that will ultimately after an overflow just switch on EVERYTHING it shouldn't and will do so for almost 50 days...

Unless I reset the arduino which will take like 3 seconds and then I have a new 50Days.

Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 636
Posts: 50275
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The 50 day millis() overflow Problem.
isn't a problem if you write the code correctly. Your watch overflows every day. How often does that cause you to need to be reset?
Logged

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

The last recorded millis() variable will be recorded somewhere at the end of the 50 days and because im working with " Current-Millis() - Initial-Millis() < xx " or  "  Current-Millis() - Initial-Millis() > xx "
will undoubtedly be a problem since the Millis() a.k.a " Current-Millis() " will overflow and start from 0 which will mess up method of using Millis() above.

Plus the Restart will really not be that big deal to be honest.Wont mess up anything.
Chances are that something happens in the 3 seconds the Arduino restarts are probably not much.
« Last Edit: January 17, 2013, 04:17:01 pm by ArdGuy » Logged

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

An example of my millis method Delay.

Code:
char  Track  = 0;
unsigned long InitialTime

void Example()
  {
 
    if (Track == 0)
      {
        InitialTime=millis();
        Track =1;
      }
     
      unsigned long yy = millis();
      if (yy - InitialTime < 5)
        {
         
        }
      else if (yy - InitialTime >=5 && yy - InitialTime < 10)
        {
         
         
        }
        else if (yy - InitialTime > 10)
        {
        Track =0;
        }
         
  }
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 636
Posts: 50275
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
will undoubtedly be a problem since the Millis() a.k.a " Current-Millis() " will overflow and start from 0 which will mess up method of using Millis() above.
No, it won't. Subtraction involving unsigned longs works.

You can test it, using micros(), which overflows the same way, only a whole lot sooner.

Quote
Plus the Restart will really not be that big deal to be honest.
Except that there is no guaranteed way to have the Arduino press the reset switch.
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4813
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ArdGuy;

If you use unsigned longs for time then when you subtract past from present it will be right even with rollover.

Here's a short sketch that shows unsigned math at work with numbers in decimal, hex and binary to show what goes on.

Code:
unsigned long a, b, c;

void setup() {
  Serial.begin( 9600 );
  a = 0xffffff00UL;
  b = 0x10UL;
  Serial.println( "\n unsigned math\n" );
  Serial.print( "a = ");
  Serial.print( a, DEC );
  Serial.print( " = 0x");
  Serial.print( a, HEX );
  Serial.print( " = 0b");
  Serial.println( a, BIN );
  Serial.print( "b = ");
  Serial.print( b, DEC );
  Serial.print( " = 0x");
  Serial.print( b, HEX );
  Serial.print( " = 0b");
  Serial.println( b, BIN );
  if ( b >= a ) Serial.println( "b >= a" );
  else          Serial.println( "a > b" );
  c = a - b;
  Serial.print( "a - b = ");
  Serial.print( c, DEC );
  Serial.print( " = 0x");
  Serial.print( c, HEX );
  Serial.print( " = 0b");
  Serial.println( c, BIN );
  c = b - a;
  Serial.print( "b - a = ");
  Serial.print( c, DEC );
  Serial.print( " = 0x");
  Serial.print( c, HEX );
  Serial.print( " = 0b");
  Serial.println( c, BIN );
  c = b - (b + 1);
  Serial.print( "b - (b + 1) = ");
  Serial.print( c, DEC );
  Serial.print( " = 0x");
  Serial.print( c, HEX );
  Serial.print( " = 0b");
  Serial.println( c, BIN );
}

void loop() {};

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

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

Hey Guys

Thanks allot for helping me understand the overflow problem smiley

Appreciated!!

So the way my makeshift Millis() function work is good?

Thanks
Ard
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4813
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You don't need it unless you feel a need to waste cycles, flash and ram.

Unsigned math is like a clock. From 11 to 1 is 2 hours without having to add or subtract 12.
That's what you should see in the sketch I posted above, but you have to look. How long does it take to do that? Should be far less time than you have spent asking for answers.

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

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

Ok cool I see.

I get what you are saying. One more thing though

After roughly 50 Days it will overflow meaning Millis() should be somewhere close to " 4320000000 "
Will it be possible to say if (millis() >= 4319500000) { var1 = 0 ; } ?
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4813
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The output of that sketch I posted shows that with unsigned math roll over is not a problem.
Run the sketch, change the numbers, compile and run it again. It shows the results.

You've got to let go of signed integer thinking to understand unsigned integers. Unsigned integers -can't- be negative. That's -any- unsigned integer so let's play with unsigned 8-bit, known as byte.

byte B = 1;     // binary 00000001
byte A = 250; // binary 11111010
// B - A = 7        binary 00000111 -- the 'borrow' is automatic, the results will be the lower 8 bits
B = 255;  // binary 11111111
A = 250;  // binary 11111010
// B - A = 5  binary 00000101
A = 250;  // binary 11111010
B = 7;      // binary 00000111
// A + B =   binary 100000001 -- 9 bits, you only get the lower 8, the overflow does not matter

You don't need an if(). What you do need is to spend however long to understand that it works.

What overflow can mess up is if you overflow by half or more what your bits can hold. Don't let that happen. But with 49.7 days maximum you have over 3 weeks to catch the change.

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Pages: [1]   Go Up
Jump to: