Interfacing Stepper Motor with STM32F407 Disc board
Posted: Fri May 04, 2018 10:29 am
Hello,
I am currently interfacing STM601 stepper motor with stm32f4 disc board. The stepper motor pins are PE9 , PE11, PE 13 , PE15.
I need to set the following pins sequence for Clockwise and anti Clockwise rotation.
SmAntClk = 0x0A,0x88,0xA0,0x22
SmClk = 0x22,0xA0,0x88,0x0A
In the code i have created a list of functions, for setting up each pin sequence in Clockwise / Anti Clockwise Direction. In main function, i am using a for loop which will iterate over the pin sequence function based on the rotation selected.
Problem: The program gets executed without any error, but the motor is not rotating. The for loop is working fine i guess, but it seems the sequence of pins are not sent properly OR is there any error which i cant find.
Below i have given the code. Can anyone try to help me out ?
I am currently interfacing STM601 stepper motor with stm32f4 disc board. The stepper motor pins are PE9 , PE11, PE 13 , PE15.
I need to set the following pins sequence for Clockwise and anti Clockwise rotation.
SmAntClk = 0x0A,0x88,0xA0,0x22
SmClk = 0x22,0xA0,0x88,0x0A
In the code i have created a list of functions, for setting up each pin sequence in Clockwise / Anti Clockwise Direction. In main function, i am using a for loop which will iterate over the pin sequence function based on the rotation selected.
Problem: The program gets executed without any error, but the motor is not rotating. The for loop is working fine i guess, but it seems the sequence of pins are not sent properly OR is there any error which i cant find.
Below i have given the code. Can anyone try to help me out ?
Code: Select all
from pyb import Pin
#Defining Directions
MotorClockwise = 0
MotorAntiClockwise = 1
#Defining Calibre angle of ST_Motor
CAL_ANGLE = 18
#Stepper_Motor_Pins Initialisation
st_motor_pins = [Pin('PE9'), Pin('PE11'), Pin('PE13'), Pin('PE15')]
#Stepper Motor Initialisation
def ASK25_SM_Init():
for pin in st_motor_pins:
pin.init(Pin.OUT_PP, Pin.PULL_NONE)
# @brief This function rotates stepper motor in desired direction and angle
# @param StMotorDirection specifies direction of rotation
# This parameter should be: StMotorClockwise
# StMotorAntiClockwise
# @param Angle specifies rotation angle
# @param Delay specifies delay between steps
def ASK25_SM_Rotate (StMotorDirection, Angle, Delay):
i = Count = 0
Count = ((Angle * 10) / CAL_ANGLE)
for x in range (Count):
ASK25_SM_Send_Sequence(StMotorDirection, Delay)
#Sequence of Stepper Motor Pins
def pins_reset():
st_motor_pins[0].value(0)
st_motor_pins[1].value(0)
st_motor_pins[2].value(0)
st_motor_pins[3].value(0)
#Function to set the Pins Sequence
def Zero_A():
st_motor_pins[0].value(1)
st_motor_pins[1].value(1)
def Eight_Eight():
st_motor_pins[1].value(1)
st_motor_pins[3].value(1)
def A_Zero():
st_motor_pins[2].value(1)
st_motor_pins[3].value(1)
def Two_Two():
st_motor_pins[0].value(1)
st_motor_pins[2].value(1)
# This function will send sequence to Stepper motor
# StMotorDirection specifies direction of rotation
# This parameter should be: StMotorClockwise
# StMotorAntiClockwise
# @param Delay specifies delay between steps
def ASK25_SM_Send_Sequence(StMotorDirection, Delay):
SmAntClk = [Zero_A, Eight_Eight, A_Zero, Two_Two]
SmClk = [Two_Two, A_Zero, Eight_Eight, Zero_A]
for x in range(4):
if (StMotorDirection == MotorClockwise):
pins_reset()
SmClk[x] #Sending the appropriate sequence from list
print("Clockwise")
elif (StMotorDirection == MotorAntiClockwise):
pins_reset()
SmAntClk[x] #Sending the appropriate sequence from list
pyb.delay(Delay)
def main():
# Initialize Stepper Motor pins
ASK25_SM_Init()
# Rotate stepper motor 360 degree with delay 60
ASK25_SM_Rotate(MotorClockwise,360,60)
main()