stepper motor control

timm

New Member
#1
Sorry about this but I am at a loss with the stepper motor 28BYJ 48 control and wiring. I have an 18m2 project board which I have successfully controlled dc motors with but I am needing some help with this stepper motor. I want it to turn 2/3 of a turn in approx 5 seconds (time not critical). That seems to be 1364 pulses but I do not know how to connect the motor and cannot figure out a code. I assume that I can connect the motor directly to the project board which has the Darlington and a 5v supply but how do I connect the 5 wires. There does not seem to be a negative connection anywhere. Could anyone suggest a suitable code. Thanks for any help
 

stan74

Senior Member
#3
search this forum.
I have several. they need 4 pins to control and you turn the port bits on/off in sequence or reverse sequence to reverse. each change is a pulse.each pulse moves motor part turn. these are geared.
The uln driver boards waste pins.
I used a uln2803 which drives 2 motors driven from a mcp23017 i2c driver so only 2 pic lines needed.
I posted somewhere about using with x2 and interrupt and mseries and running 2 programs.
http://www.picaxeforum.co.uk/showth...00-times-faster-in-simulator&highlight=stan74
https://www.youtube.com/watch?v=Td7yWYImjr4&t=0s&list=UUwOlmqc5IB4FhvS5XKu1sLw&index=9
A 100Hz --they run at 100Hz, interrupt to send 4 low bits ie motor 1 and upper 4 bits as i2c but adaptable.
4 phase works best ie
do
port.00001001
port.00000011
port.00000110
port.00001100
loop
'This will be called when the Timer overflows
Sub motors
' Set the register to 6 to give us the 10ms Interrupt.
' Use the Timer Calc' application that is part of Mister E PIC Mutl-calc tookset to calculate the value.
' Ensure you set the Prescaler in the InitTimer1 shown above
SetTimer 1, 25538 ;reset timer
;left stepper motor
if lmotforward>0 then
if lmotforward=1 Then
lmotor++
if lmotor=5 then lmotor=1
else
lmotor---
if lmotor=0 then lmotor=4
end if
;
select case lmotor
case 1
lmotval=144
case 2
lmotval=192
case 3
lmotval=96
case 4
lmotval=48
End Select
Else
lmotval=0
end if
;right stepper motor
if rmotforward>0 then
if rmotforward=1 Then
rmotor++
if rmotor=5 then rmotor=1
else
rmotor---
if rmotor=0 then rmotor=4
end if
;
select case rmotor
case 1
rmotval=9
case 2
rmotval=3
case 3
rmotval=6
case 4
rmotval=12
End Select
else
rmotval=0
end if

MCP23017_sendbyte (MCP23017_addr,MCP23017_GPIOA,lmotval+rmotval) ;sets porta to lmotval+rmotval

End Sub
 
Last edited:
Top