Offline
Newbie
Karma: 0
Posts: 35
|
 |
« on: January 17, 2013, 03:39:44 pm » |
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
Offline
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #1 on: January 17, 2013, 03:44:02 pm » |
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
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #2 on: January 17, 2013, 03:46:18 pm » |
Gosh. Twice in a week.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 35
|
 |
« Reply #3 on: January 17, 2013, 04:02:43 pm » |
 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
Offline
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #4 on: January 17, 2013, 04:07:27 pm » |
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
Newbie
Karma: 0
Posts: 35
|
 |
« Reply #5 on: January 17, 2013, 04:15:30 pm » |
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
Newbie
Karma: 0
Posts: 35
|
 |
« Reply #6 on: January 17, 2013, 04:21:37 pm » |
An example of my millis method Delay. 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
Offline
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #7 on: January 17, 2013, 04:23:29 pm » |
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. 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
Faraday Member
Karma: 31
Posts: 2947
I only know some basic electricity....
|
 |
« Reply #8 on: January 17, 2013, 04:30:13 pm » |
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. 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
|
Examples can be found at Learning in the Main Site and at the Playground
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 35
|
 |
« Reply #9 on: January 18, 2013, 03:04:00 am » |
Hey Guys Thanks allot for helping me understand the overflow problem  Appreciated!! So the way my makeshift Millis() function work is good? Thanks Ard
|
|
|
|
|
Logged
|
|
|
|
|
Pittsburgh, PA, USA
Offline
Faraday Member
Karma: 31
Posts: 2947
I only know some basic electricity....
|
 |
« Reply #10 on: January 18, 2013, 03:52:35 am » |
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
|
Examples can be found at Learning in the Main Site and at the Playground
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 35
|
 |
« Reply #11 on: January 18, 2013, 08:20:18 am » |
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
Faraday Member
Karma: 31
Posts: 2947
I only know some basic electricity....
|
 |
« Reply #12 on: January 18, 2013, 12:11:43 pm » |
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
|
Examples can be found at Learning in the Main Site and at the Playground
|
|
|
|
|