I was curious about loop termination test time and someone in here was curious about ADC timing recently. I set up an 18X, running at 8 MHz, and measured loop timing under different conditons using my oscilloscope.
In each loop, I included a toggle 0 instruction. I connected my 'scope to Out0 and measured the period of the positive half of the square wave.
Take the timing figures as a guide. My 'scope is an old Tek 2235, of unknown calibration state. But the numbers should be "close enough for government work," I guess.
I re-ran the ADC tests at 4 MHz, and, as expected, found that an ADC measurement at 4 MHz costs about twice as much as one performed at 8 MHz.
The results are included as comments in the code below.
Some costs:
--Adding a loop termination test to a do..loop until structure costs 160 uSec. This is true for either a pin state test or a variable calculation.
--A do..loop until structure is much cheaper than a for..next structure, by 360 uSec.
--An ADC measurement, either 8 or 10 bit, costs about 250 uSec. At 4 MHz, an ADC test costs approx 500 uSec.
HTH,
Tom
In each loop, I included a toggle 0 instruction. I connected my 'scope to Out0 and measured the period of the positive half of the square wave.
Take the timing figures as a guide. My 'scope is an old Tek 2235, of unknown calibration state. But the numbers should be "close enough for government work," I guess.
I re-ran the ADC tests at 4 MHz, and, as expected, found that an ADC measurement at 4 MHz costs about twice as much as one performed at 8 MHz.
The results are included as comments in the code below.
Some costs:
--Adding a loop termination test to a do..loop until structure costs 160 uSec. This is true for either a pin state test or a variable calculation.
--A do..loop until structure is much cheaper than a for..next structure, by 360 uSec.
--An ADC measurement, either 8 or 10 bit, costs about 250 uSec. At 4 MHz, an ADC test costs approx 500 uSec.
HTH,
Tom
Code:
#rem
Picaxe 18X v8.6 Speed Test - tjl 10/5/07
Timing obtained by monitoring Out0 with an oscilloscope
**********************************************
Costs at 8 MHz:
Loop termination test: do..loop until structure
160 uSec
For..next structure vs do..loop until structure:
360 uSec
ADC measurement, 8 or 10 bit:
approx 250 uSec (or 500 uSec at 4 MHz)
**********************************************
#endrem
Main:
setfreq m8
#rem
; Case 1: Maximum speed loop
; Result: 540 uSec / loop
; 4 MHz spot check: 1.08 mSec / loop
do
toggle 0
inc w0
loop
#endrem
#rem
; Case 2: Loop with pin state test
; Result: 700 uSec / loop
do
toggle 0
inc w0
loop until pin1 = 1
#endrem
#rem
; Case 3: Loop with termination test
; Result: 700 uSec / loop
do
toggle 0
inc w0
loop until w0 = 0
#endrem
#rem
; Case 4: Loop incorporating ADC measurement
; Result: 780 uSec / loop
; 4 MHz spot check: 1.59 mSec / loop
do
toggle 0
readadc 1,b0
inc w0
loop
#endrem
#rem
; Case 5: Loop incorporating ADC10 measurement
; Result: 790 uSec / loop
do
toggle 0
readadc 1,w1
inc w0
loop
#endrem
#rem
; Case 6: Loop incorporating ADC measurement and loop termination test
; Result: 940 uSec / loop
do
toggle 0
readadc 1,w1
inc w0
loop until w0 = 0
#endrem
#rem
; Case 7: For/next loop
; Result: 900 uSec / loop
for w1 = 0 to 65535
toggle 0
inc w0
next
#endrem
#rem
; Case 8: For/next loop with ADC measurement
; Result: 1.15 mSec / loop
for w1 = 0 to 65535
toggle 0
readadc 1,b0
inc w0
next
#endrem
low 0
do
loop
end
Last edited: