How much time?

harolds1956

New Member
Hi, I am wondering what the time delay is from instruction to instruction when using an 08M @4meg. Lets say I write a simple program that reads adc10 on pins 1,2,and 4 to word variable, compares each of the variables to a # then loops back to reading pins 1,2,4 etc. I know some lines require more time to process than others but I just need an idea of the frequency that the pins are read and compared.
 

adub

New Member
You could write a small test program to read the adc fiddle a bit then toggle an led on/off. Do that, say a hundred or a thousand times and time how long it takes to what ever accuracy you need. Stop watch or count 1 - one thousand, 2 - one thousand, etc.

enjoy
 

inglewoodpete

Senior Member
ReadADC does take a little time. ReadADC10 takes longer. Arvin's suggestion is a good one: if nothing else, it will give you a little more experience with the PICAXE.

Edit: ReadADC and ReadADC10 commands are faster than I thought:

Code:
#picaxe 08m
Start:	Toggle 1
	For w0 = 1 to 10000
		ReadADC 4, b2
	Next w0
	GoTo Start
...cycles about every 16 seconds. That's about 1.6mS per loop. And so does the following:
Code:
#picaxe 08m
Start:	Toggle 1
	For w0 = 1 to 10000
		ReadADC10 4, w2
	Next w0
	GoTo Start
I have read that the command takes different amounts of time depending on the analogue value being read.
 
Last edited:

harolds1956

New Member
Okay, here's the program I wrote, and my results;

Test: readadc10 1, w1
readadc10 2, w2
readadc10 4, w4
if w1=500 then Stop
if w2=500 then Stop
if w4=500 then Stop
toggle 0
goto Test
Stop: stop

I tied pins 1,2,&4 to ground so the program never "stops". Hooked up my frequency counter to pin 0 and recorded 115HZ. Would I be correct to say I can read and compare 3 analog voltages 115x per second?
 

BCJKiwi

Senior Member
It would be interesting to see if you get any difference if you tie the inputs to 5V (bigger number to compare).

If that is all the program is doing then you might get close to that but presumably your program will be doing other things as well so those processing times would have to be taken into account as well.

You would normally have a conditional statement rather than an = to test the value.
e.g.

if w1 => 450 OR w1 =< 550 then stop
or something similar rather than just the precise number - after all the voltage you are testing will drift a bit and you might never see a precise 500!

So perhaps a little more testing with a few variations might be in order.
 
Last edited:

hippy

Ex-Staff (retired)
Would I be correct to say I can read and compare 3 analog voltages 115x per second?
Probably 300x per second. You're taking a reading and then transitioning Pin 0, I expect the frequency counter is counting high+low cycles so will be half the transition count.

While you're testing, it would be interesting to see what happens when you replace the three IF's with the single ...

- if w1=500 or w2=500 or w4=500 then Stop

Still keep your pins tied to ground so it doesn't stop but you should see a speed improvement.
 
Top