In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Peter Van der Zee wrote: 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 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......... [code] 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) [/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=147178 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)