"Time" variable

Yex2

Well-known member
Hi all,

Is "time" variable a word variable, i.e. limited to 65535?
What happen when it reach the end, does it goes funny or simply start from 0 again?

Is there another variable that can give the time in smaller unit like micro sec. or mili sec?

One more thing, is it precise enough to use it as a daily counter over a week?

Thanks,

Yves
 

AllyCat

Senior Member
Hi,
Is "time" variable a word variable, i.e. limited to 65535?
What happen when it reach the end, does it goes funny or simply start from 0 again?
Yes it's a word variable that will wrap (cleanly) back to zero (and upwards again) after about 18 hours. Or your software can reset it back to zero (or any other value) at any time (e.g. hourly). Check the command reference to see what happens at other clock (SETFREQ) speeds
Is there another variable that can give the time in smaller unit like micro sec. or mili sec?
Not a system variable, but you can access the chip hardware with PEEKSFR commands. "Timer 1" increments once every microsecond (if a 4 MHz clock) but PICaxe Basic is too slow to read the Low byte usefully. However, its High byte is arranged to rollover (from 255) exactly every 20 ms, which can potentially be used as a 20ms / 50 Hz "tick" for suitably designed software. It's the "prescaler" for the time variable, also used for the Servo pulses.
.. is it precise enough to use it as a daily counter over a week?
Probably not. The basic accuracy of the PIC(axe) is about +/-1% (~14 minutes per day) but certain commands (e.g. SERIN, SEROUT,PULSIN, COUNT, etc.) can cause it to lose enormous amounts of time (many hours per day).

Cheers, Alan.
 
Last edited:

hippy

Technical Support
Staff member
Is "time" variable a word variable, i.e. limited to 65535?

Yes.

What happen when it reach the end, does it goes funny or simply start from 0 again?

It rolls over to zero and starts again.

Is there another variable that can give the time in smaller unit like micro sec. or mili sec?

No. But one can use the 'timer 1' on-chip peripheral as AllyCat suggests.

I recall that can be used to create an every half second polled tick which is as accurate as the crystal or resonator on an X2, but is not as capable and more difficult to use on an M2.

One more thing, is it precise enough to use it as a daily counter over a week?

Unlikely, but it really depends on the rest of the code in a program. In most programs the 'time' variable will increment slower than real time. By how much, and how consistent the divergence will be, greatly depends on what a program is doing and how consistently.
 

mikeyBoo

Senior Member
hi Yex2,
The Picaxe onboard timer won’t be very accurate (been there done that).
It's fairly easy to make a very accurate elapsed time counter using the 1Hz output from a DS1307 (or other clock) into a Picaxe pin.
I use it as a "time on water" & "AmpHours Used" display. It tracks perfectly with my Samsung phone & GPS.
However, the resolution is 1 second (albeit dead-on).
The only limiting factor is that your main loop must be less than 500 milliseconds (not an issue with most apps).
look at subroutine ElapsedTime_Get (subroutine init shows the clock setup) in the Picaxe BASIC app
Picaxe Kayak Control System.bas
https://picaxeforum.co.uk/threads/picaxe-kayak-control-project.28063/
Good luck with your project!
 
Top