Slow lookup routine?

wlie

Member
Is lookup command very slow? I have worked with a small stepper motor and has been a little bit confused. In an attempt to make my program a little more elegant, I have rewritten SlowCW routine to FastCW routine as shown here.
Code:
#picaxe 14M2
#No_Data

Symbol rest = 1
DirsB = %00011110

do
	gosub SlowCW
	Pause 1000
	gosub FastCW
	pause 1000
loop

SlowCW:
	for w4= 1 to 3000  
		for b2 = 0 to 3
			lookup b2, ($06,$0C,$18,$12), pinsB
			pause rest
		next b2 
	next w4
return  

FastCW:
	for w4= 1 to 3000  
		let PinsB = $06
		pause rest
		let PinsB = $0C
		pause rest
		let PinsB = $18 
		pause rest
		let PinsB = $12  
		pause rest  
	next w4
return
SlowRW would in my opinion do exactly as FastCW, but FastCW run my stepper motor twice as fast ..
What have I missed?
 

AllyCat

Senior Member
Hi William,

Yes, a number of commands in PICaxe Basic are rather slow. That LOOKUP (with 4MHz clock) probably takes about 1400us, but a simple RETURN from a subroutine can take as long.

Many measurements (and measuring techniques) are given in this thread with LOOKUP specifically discussed from #12 onwards.

But it's probably the extra nested FOR... loop that's causing the slowness.

Cheers, Alan.
 

westaust55

Moderator
With the slow routine, try removing the Line
PAUSE rest
or change to
PAUSE 0
For a much reduced pause (~0.25 ms instead of ~1.25ms)
To compensate for the time spent (of the order of 1.1 ms based on past timing experiments) in the inner loop incrementing the FOR...NEXT counter variable and testing if complete.
 
Last edited:

wlie

Member
When I remove the break routine in SlowCW this routine become twice as fast as FastCW routine.
I can not remove the four pause routines in FastCW as the stepper motor then refuse to move. I guess that routine then becomes too fast for the mechanics.
But the fastes is when using EEPROM as nick12ab suggest.
Thanks for all the answers.
 

hippy

Technical Support
Staff member
I can not remove the four pause routines in FastCW as the stepper motor then refuse to move. I guess that routine then becomes too fast for the mechanics.
You can use SETFREQ to make the code run faster and then add PAUSE or PAUSEUS to slow things down so you don't exceed mechanical limitations. This would be the best way to get the fastest possible speed out of your steppers if you want that.
 
Top