What to avoid to keep TIME working?

cpedw

Senior Member
Is there a list of commands and other things to avoid if using TIME on an M2? I'm sure this has been covered before but I can't find anything apasrt from SERVO which is mentioned in ENABLE..., DISABLE... and TIME pages of basic commands.

Derek
 

AllyCat

Senior Member
Hi,

Not AFAIK; most of the description about Interrupts (e.g. in the Programming Manual Appendices) applies primarily to X2s.

The SERVO command and the time variable use the same (20 ms) timer (T1), so if the Servo pulses are "good" then so should be the time variable. ;) Basically, the "time" variable is obtained by a system interrupt routine dividing the Servo timer by 50 (sadly this prescaler value is not accessible to the program-writer). The 20ms preload is also interrupt-driven, so when interrupts are disabled then both the 20ms period and subsequently the "time" prescaler may be corrupted (i.e. delayed). Note that the 20 ms timer continues to run whether "time" is ENABLEd or DISABLEd. You can read the T1 value by using PEEKSFR commands (it normally increments at 1 MHz from 45536 to 65535 and then overflows to generate the system interrupt).

I believe the main commands which disable interrupts are the serial communications, i.e. SERIN , SEROUT , SERTXD and DEBUG , because they use bit-banging to time the data. Apparently PULSIN , PULSOUT and COUNT do NOT disable these system interrupts, so it is their values which become corrupted if there is a conflict.

There may be other commands which disable interrupts, but you may find the text and Logic Analyser waveforms (including corruption of the Servo Pulses) of relevance HERE.

Cheers, Alan.
 

erco

Senior Member
SETFREQ to anything other than 4 Mhz will affect TIME, as will many other commands. IMO it's not particularly accurate or useful in most situations.
 

inglewoodpete

Senior Member
Refer to the second part of Appendix B in PICAXE Manual 1 for a list of commands and an explanation of what affects the clock frequency.
 

papaof2

Senior Member
If you need ACCURATE time (day/hour/minute/second) then you need a Real Time Clock (RTC). These typically have their own backup battery and are accessed via I2C; the better ones keep time in the minute-a-year range.
Assume a few milliseconds to read the time from the RTC.
 
Top