// Low cost stepper motor and PCB // November 2013 // www.bypic.co.uk // // Step table for half step mode gives 8 steps constant steptable${1, 3, 2, 6, 4, 12, 8, 9 } dim cstep // // Uses 4 consecutive pins next to each other // PORTB 0 to 3 // ***************************************************************************** // set up the pins to be output and also low, low switches off the current // to the motor // ***************************************************************************** function init() dim j for j = 0 to 3 io_write(PORTB,j,LOW) io_pinMode(PORTB,j,OUT,WOFF) next cstep = 0 endf // ***************************************************************************** // each time this funcrion is called it will step once // ***************************************************************************** function step(forward) dim stepv, j if forward = 1 then cstep = cstep + 1 if cstep > 7 then cstep = 0 endif else cstep = cstep - 1 if cstep < 0 then cstep = 7 endif endif stepv = peekc(?steptable$+4+cstep) // now set pins - see text at ByPic poke(PORTB+LAT_OFF+CLR,0xf) poke(PORTB+LAT_OFF+SET,stepv) // necessary delay - set for MX1 may need increasing for MX3 for j = 0 to 1200 next endf // ***************************************************************************** // s = number of steps, d is direction 1 or 0 // ***************************************************************************** function go(s,d) dim j for j = 0 to s step(d) next endf