PICAXE instruction times (partial list)

hungarian

New Member
PICAXE "time" variable vs clock frequency


Symbol:k31k250k500m1m2m4m8m16m32
Actual frequency:31kHz250kHz500kHz1MHz2MHz4MHz8MHz16HMz32MHz
Time increments every:untesteduntested33.3s16.7s2s1s2s1s0.5s
Assumed frequency:untesteduntested15kHz60kHz4MHz4MHz16MHz16MHz16MHz

Under the instructions "enabletime" and "disabletime" the PICAXE PDF states that:
Effect of increased clock speed:
The time function will work correctly at 4MHz or 16 MHz.
At 2MHz or 8MHz the interval will be 2s.
At 16MHz the interval will be 0.5s


It is inconsistent about 16MHz. In fact the last statement is false.


Instuction tests


Instructions were timed using variations of the following code, using 10000, 20000, 40000 or 50000 for n:
w3=time
for w6=1 to n
next
w4=time
for w6=1 to n
instruction under test
next
w5=time


us=microseconds. Times are +/- 100us
Instruction Under Test (IUT)IUT Time
Clock
b4=85550us4MHz
b4=b0+851050us4MHz
b4=b0+b21050us4MHz
b4=b0*131200us4MHz
b4=b0/141300us4MHz
w2=w0*2511250us4MHz
w2=w0+218451200us4MHz
lookup b0,( ten byte constants ),b22350us4MHz
lookup b0,( ten word constants ),w13600us4MHz
goto850us4MHz
gosub {& return}2350us4MHz
if b0>85 then gotoFALSE850us4MHz
if b0>85 then gotoTRUE1300us4MHz
if b0>85 then gosub {& return}FALSE1300us4MHz
if b0>85 then gosub {& return}TRUE4050us4MHz
if b0>85 then: endifFALSE1300us4MHz
if b0>85 then: endifTRUE850us4MHz
if b0>85 then: else: endifFALSE1300us4MHz
if b0>85 then: else: endifTRUE1700us4MHz
readADC C.1,b4800us4MHz
pauseus 1650us4MHz
pauseus 1: pauseus 11300us4MHz
pauseus 2700us4MHz
pauseus 4750us4MHz
pauseus 8750us4MHz
pauseus 10800us4MHz
pauseus 20950us4MHz
pauseus 401100us4MHz
pauseus 801500us4MHz
pauseus 10013300us500kHz
pauseus 1006700us1MHz
pauseus 1003300us2MHz
pauseus 1001675us4MHz
pauseus 100850us8MHz
pauseus 100425us16MHz
pauseus 100220us32MHz


Conclusions

For timing purposes (Note ¶ represents new line):

Source: if x then gosub label0
Equivalent: if not(x) then goto label1 ¶ gosub label0 ¶ label1:

Source: if x then ¶ <x-is-true> ¶ endif
Equivalent: if not(x) then goto label0 ¶ <x-is-true> ¶ label0:

Source: if x then ¶ <x-is-true> ¶ else ¶ <x-is-false> ¶ endif
Equivalent: if not(x) then goto label0 ¶ <x-is-true> ¶ goto label1 ¶ label0: ¶ <x-is-false> ¶ label1:

"pauseus n" is supposed to be a pause of about n*10 microseconds but the actual length is about (640+10*n)*4/f microseconds, where f is the clock frequency in MHz

Hope this is useful.
 

hippy

Ex-Staff (retired)
Before putting too much effort into determining instruction timings it may be worth reading other posts on the forum on the subject.

Because the PICAXE uses an interpreter and interprets variable-sized tokens, instruction timing depends on a number of factors including where the it is in memory. At best one can determine what the minimum and maximum instruction times may be and even that will be inaccurate because changing the code under test alters the timing of the code doing the timing. Using the 'time' variable will also bring its own inaccuracies.

Westaust55 has previously undertaken analysis of instruction timings and has documented his findings in the PDF files linked in this thread ...

http://www.picaxeforum.co.uk/showthread.php?17782-PICAXE-program-Size-Optimisations-and-Speed
 
Top