Simple Stepper Code Snippet
Hi All;
There has been some significant activity in the forum recently in regard to software for driving stepper motors. To that end, I have·introduced a callable snippet of code that is a very simple pseudo state machine, and is easy to integrate into anyone's code by just calling it.........
The four entries in the table need to be made to match what your motor needs for each of its step positions; my selection here is arbitrary, just for demonstration.
I hope this is of some help.
Cheers,
Peter (pjv)
There has been some significant activity in the forum recently in regard to software for driving stepper motors. To that end, I have·introduced a callable snippet of code that is a very simple pseudo state machine, and is easy to integrate into anyone's code by just calling it.........
Your Code . . . call Forward ;take a step forward . . call Reverse ;take a step backwards . . . ;Step Routines ============================================================== Forward inc Position ;new forward location and desired motor coil state call Step ;lookup the new motor state mov port,w ;output the new motor coil state retp ;return to mainline Reverse dec Position ;new reverse location and desired motor coil state call Step ;lookup the new motor state mov port,w ;output the new motor coil state retp ;return to mainline Step mov w,Position ;get the new position and w,#%0000_0011 ;pay attention only to least significant four states add pc,w ;jump into the table and return with the coil combination Table00 retw %0000_0001 ;state 00 return with selected motor coil combination... can be any desired combination Table01 retw %0000_0010 ;state 01 return with selected motor coil combination... can be any desired combination Table10 retw %0000_0100 ;state 10 return with selected motor coil combination... can be any desired combination Table11 retw %0000_1000 ;state 11 return with selected motor coil combination... can be any desired combination
The four entries in the table need to be made to match what your motor needs for each of its step positions; my selection here is arbitrary, just for demonstration.
I hope this is of some help.
Cheers,
Peter (pjv)