; stepper.txt ; ; 06-May-2006 Keith Neufeld ; ; Test/drive bipolar stepper motor, using external 754410 driver chip. ; Two coils are driven in quadrature: ; ; ===| |=======| |=======| |=======| ; | | | | | | | ; |=======| |=======| |=======| |=== ; ; =======| |=======| |=======| |=======| ; | | | | | | | ; |=======| |=======| |=======| | ;------------------------------------------------------------------------------ ; Debug system ;------------------------------------------------------------------------------ constants [[debug 0]] ;constants [[debug 1]] ;------------------------------------------------------------------------------ ; Section to manipulate stepper motor. ; Coil 1 driven by C7/C6. Coil 2 driven by A2/A3. ;------------------------------------------------------------------------------ constants [ [coil1-port portc] [coil1-ddr portc-ddr] [coil1a-bit 7] [coil1b-bit 6] [coil2-port porta] [coil2-ddr porta-ddr] [coil2a-bit 2] [coil2b-bit 3] ] to stepper-off clearbit coil1a-bit coil1-port ; set all coil outputs low clearbit coil1b-bit coil1-port clearbit coil2a-bit coil2-port clearbit coil2b-bit coil2-port end global [steps-per-sec msec-per-step] ; timing "constants" global [coil1-pos coil2-pos] ; current coil state to init-stepper stepper-off ; shut down all coil outputs clearbit coil1a-bit coil1-ddr ; set all coil pins as outputs clearbit coil1b-bit coil1-ddr clearbit coil2a-bit coil2-ddr clearbit coil2b-bit coil2-ddr setsteps-per-sec 2 ; 2 steps per second setmsec-per-step 1000 / steps-per-sec ; precalculate wait per step setcoil1-pos 0 ; initialize quadrature to (0,0) setcoil2-pos 0 end to step-set ; push out new quadrature values ifelse debug [ send 48 + coil1-pos ; 0/1 with no CR send 32 ; space with no CR print coil2-pos ] [ ifelse coil1-pos [ clearbit coil1b-bit coil1-port ; clear before set setbit coil1a-bit coil1-port ] [ clearbit coil1a-bit coil1-port ; clear before set setbit coil1b-bit coil1-port ] ifelse coil2-pos [ clearbit coil2b-bit coil2-port ; clear before set setbit coil2a-bit coil2-port ] [ clearbit coil2a-bit coil2-port ; clear before set setbit coil2b-bit coil2-port ] ] end ; CW pattern: ; 0110.0110 ; 0011.0011 global [new1 new2] ; temps for coil values to step-cw setnew1 not coil2-pos setnew2 coil1-pos setcoil1-pos new1 setcoil2-pos new2 step-set ; do it end to step-ccw setnew1 coil2-pos setnew2 not coil1-pos setcoil1-pos new1 setcoil2-pos new2 step-set ; do it end ;------------------------------------------------------------------------------ ; Routines to tie it all together ;------------------------------------------------------------------------------ to init-all init-stepper end to powerup init-all end to startup init-all loop [ step-cw mwait 100 ] end