Pages: [1]   Go Down
Author Topic: Meddling with the runtime clock  (Read 387 times)
0 Members and 1 Guest are viewing this topic.
Space Coast Florida
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there some way to set the run-time clock other than waiting 49 days for the clock to turn over. I need to certify that the rollover will be uneventful.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 611
Posts: 49092
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I need to certify that the rollover will be uneventful.
Use micros(), instead. Works the same way, but a much shorter fuse.
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I use code like this in the Bitlash rollover example (https://github.com/billroy/bitlash/blob/master/examples/rollover/rollover.ino):

Code:
extern volatile unsigned long timer0_millis;

void setMillis(unsigned long newtime) {
uint8_t oldSREG = SREG;
cli();
timer0_millis = newtime;
SREG = oldSREG;
})

-br
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 481
Posts: 18737
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there some way to set the run-time clock other than waiting 49 days for the clock to turn over. I need to certify that the rollover will be uneventful.


Just build your own time machine:

http://science.discovery.com/games-and-interactives/build-your-own-time-machine.htm
Logged


Space Coast Florida
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Just build your own time machine:
This might take longer than 49 days.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 481
Posts: 18737
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Good point.
Logged


Space Coast Florida
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Use micros(), instead.Works the same way,

Instead of the run-time clock?
Please explain.
Quote
  but a much shorter fuse.
Fuse?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 611
Posts: 49092
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Instead of the run-time clock?
No, instead of millis().

Quote
Fuse?
micros() ticks 1000 times faster than millis. Results in 0.01% of the time.
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4062
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Substitute a variable in place of using millis() directly. Instead of

Code:
if ( millis() ... whatever ) { ...

use

Code:
unsigned long ms = millis();
if ( ms ... whatever ) { ...

Make sure the code works as desired that way, then to test what happens around rollover, something like this:

Code:
unsigned long ms = 4294957296;    //ten seconds before rollover
if ( ms ... whatever ) { ...
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Pages: [1]   Go Up
Jump to: