Using Stepper Motors

locky42

New Member
I have a fare bit of past experience in using Stepper Motors and I firmly believe that they have a place in Robotics and Control.
The Picaxe 18M2 High Power Project Board goes part way to enabling this with its L293D bi-direction current driver on 'motors C and D'. However, little is said as to how to use it to step a stepper motor.

A Stepper motor requires that its 2 sets of motor windings are wired as motors C and D. Then once connected it can be stepped to use its angular precision of 3.6 degrees (or even 1.8 degrees).

The state of the windings have to sequence through 4 states
The subroutine I came up with for clockwise stepping is below:

SingleStepCW:
if StepState = 3 then
high B.5
low B.4
high B.7
low B.6
endif
if StepState = 2 then
low B.5
high B.4
high B.7
low B.6
endif
if StepState = 1 then
low B.5
high B.4
low B.7
high B.6
endif
if StepState = 0 then
high B.5
low B.4
low B.7
high B.6
endif
let StepState = StepState + 1
if StepState > 3 then
let StepState = 0
endif
pause StepTime
return

Calling it like:

let NumSteps = 100
for Cnt = 0 to NumSteps step 1
;Stepper clockwise
call SingleStepCW
next Cnt

would give a precise full rotation of the stepper motor.

I also put together a subroutine for Counter Clockwise, where the states of the windings sequence in reverse.

From here one then needs to put together control over where the motor is, where it needs to be and have many steps it needs to take.

Two final issues:
a. The need for a microswitch sensor to find and possition the motor at its 'home position'.
b. That the 18M2 High power board only has one L298D socket. If you need to use 2 stepper motors to drive Robot Wheels, you then needs to build
something like a Shield board for a 28X2 Shield Base.
 

locky42

New Member
Some rwfinement:
SingleStep:
high B.1
if CCW <> 1 then
;Use CCW variable to determine stepper motor direction.
;CCW = 0 for clockwise and 1 for Anti-Clockwise.
;Comments show the Blocky Motor C and Motor D states.
let StepState = StepState + 1
if StepState > 3 then
let StepState = 0
endif
else
let StepState = StepState - 1
if StepState > 255 then
; Stepper Motor has 4 states for its 2 windings
let StepState = 3
endif
endif
if StepState = 3 then
;Motor C Forwards
high B.5
low B.4
;Motor D Forwards
high B.7
low B.6
endif
if StepState = 2 then
;Motor C Backwards
low B.5
high B.4
;Motor D Forwards
high B.7
low B.6
endif
if StepState = 1 then
;Motor C Backwards
low B.5
high B.4
;Motor D Backwards
low B.7
high B.6
endif
if StepState = 0 then
;Motor C Forwards
high B.5
low B.4
;Motor D Backwards
low B.7
high B.6
endif
pause StepTime
low B.1
return
 

hippy

Technical Support
Staff member
If you add [code]...[/code] tags around your code you can retain the indentation and spacing of your programs.

It may also be worth looking through the forums for other posts on stepper motors as there has been previous discussions on the subject, how to achieve highest stepping speeds and so on.
 

techElder

Well-known member
Not to beat up on locky42, but to preserve the "finished projects" perhaps this project should be moved to the general active forum?
 
Top