Very cheap stepper and driver to play with.

Dangre

New Member
This code has acceleration and deceleration with a fixed number of steps from start to finish. Tweak the values to suit.

Code:
#Picaxe 08m2
'Stepper motor driver test with acceleration
'Boris Burke May 2012

symbol prefinish=w0		'controls the start of deceleration
symbol finish=w1		'number of steps to the finish
symbol steps=w2			'counts the steps
symbol direction=b6		'2=CW 0=CCW
symbol phase=b7			'counts from 0 to 3 for CW and from 3 to 0 for CCW
symbol speed=W6			'changes with acceleration/deceleration (lower is faster, min 1)
symbol slow_limit=w7	'destination speed when starting and stopping (higher is slower)

setfreq m8				'double the Picaxe clock speed
pause 1000				'wait for the new clock speed to settle (1000=500mS at m8)
dirs=%00010111			'bit 3 cannot be used because I'm using an 08m2
slow_limit=32			'upper limit for slowest step speed during acceleration/deceleration
finish=4096				'number of steps to take
direction=2				'direction switch 0=CW 2=CCW

do
	direction=direction+2 max 3//3				'alternate direction, comment this line for single direction
	speed=slow_limit							'set delay
	for steps=1 to finish						'beging rotation loop
		prefinish=finish-steps+1				'set deceleration point
		if steps<slow_limit then				'if starting
			speed=speed-1 min 1					'then accelerate
		elseif prefinish<slow_limit then		'if stopping
			speed=speed+1 max slow_limit		'then decelerate
		endif									'end acceleration adjustmet to SPEED
		pause speed								'speed of rotation pause
		phase=phase+direction-1//4				'work out the next output bit pattern
		lookup phase,(%00011,%00110,%10100,%10001),pinsC	'move stepper motor
	next steps									'end of rotation loop
	pause 4000									'wait 2 seconds
loop
Note: When the steps stop coming, two of the motor coils are still energized. This is good for accurate position-and-stay effects, but if you want the motor to run cooler and to save power when there is no need for it to 'hold hard' to it's last position, set the outputs to LOW.
 
Top