You are on page 1of 3

'Serial driven stepper motor symbol symbol symbol symbol symbol symbol symbol symbol posrotor=b0 numturns=b2 speeddir=b7

direc=b8 pulsegap=b3 counter=b4 modrotor=b1 outbyte=b5

posrotor = 1 'set starting position start: 'main sequence - wait for command then move the motor numturns=0 'sets a default number of turns high 7 'reset ready flag serin 0,T2400,(85),numturns,speeddir 'get serial data gosub getspeed 'get the direction and speed gosub move 'perform number of steps goto start getspeed: if speeddir>128 then 'find direction and store in direc (1 is +ve, 0 is ve) direc=1 else direc=0 endif speeddir=speeddir//128 'gets the speed 0-127 negative, 128-255 positive (higher =faster) pulsegap=264-2*speeddir return move: for counter=1 to numturns pause pulsegap 'wait before moving again (set by speed) if direc=1 then posrotor=posrotor+1 'increase/decrease the step by one else posrotor=posrotor-1 endif gosub moverotor 'set the rotor position for this step next counter return moverotor: modrotor=posrotor//8 'find out where the rotor arm should be (1 of 8 positions) lookup modrotor, (0x08,0x0A,0x02,0x06,0x04,0x05,0x01,0x09), outbuyte '(%00001000,%00001010,%00000010,%00000110,%00000100,%00000101,%00000001,%0 0001001) is (0x08,0x0A,0x02,0x06,0x04,0x05,0x01,0x09) in hex 'looks up the step from the sequence and applies it to the output pins pins=outbyte return

You might also like