'************************ 'Stepper Motor Controller 'Picaxe 18M2 'Unipolar & Bipolar- Set variable for correct type 'PJW 4/2011 '************************ 'Variables setfreq M32 symbol StepPulse = pinc.0 symbol Direction = pinc.1 symbol enabled = pinc.2 symbol limitout = c.7 symbol limitin = pinc.6 symbol reset1 = b0 symbol stepcount = b1 ' 1 to 4 symbol stepout = b2 symbol mm = b3 symbol Unipolar =b4 symbol counter = w3 symbol delay = w4 symbol counter1 = w5 Unipolar = 1 '1 for Unipolar, 0 for Bipolar let delay =10 let dirsB = %11111111 let dirsc = %10111000 stepcount =0 '************************ 'Test routine 'direction = 1 'goto testloop '************************ Main: if limitin = 0 then 'Not at limit low limitout if enabled = 1 then if reset1 = 0 then 'check for pulse on steppulse if steppulse = 1 then if reset1 = 0 then 'respond to rising steppulse 'step motor gosub Step1 end if reset1 = 1 end if end if else 'turn off motor pinsb = %00000000 end if else high limitout 'set limit end if if steppulse = 0 then 'reset flag reset1=0 end if goto main '************************ 'Step motor one step step1: select case direction case 1'Reverse if stepcount >0 then stepcount = stepcount - 1 end if if stepcount = 0 then stepcount =4 end if case 0 'Forward stepcount = stepcount + 1 if stepcount = 5 then stepcount = 1 end if end select If Unipolar = 1 then 'Unipolar lookup stepcount ,(0,%0011, %0110,%1100,%1001), pinsb 'full step else 'Bipolar lookup stepcount ,(0,%1001,%0101,%0110,%1010) ,pinsb'stepout 'full step end if return '********************************** 'test loop testloop: do for counter1 = 1 to 80 for counter = 1 to 200 gosub step1 next counter next counter1 pause 1000 if direction = 0 then direction = 1 else direction = 0 end if loop do for counter1 = 1 to 80 for counter = 1 to 200 gosub step1 'pause 2000 next counter next counter1 pause 1000 if direction = 0 then direction = 1 else direction = 0 end if 'debug loop