I am currently interfacing stepper motor with stm32f407 disc board. I have created a list of functions. This functions are basically for setting different GPIO pins.
So problem that i face is one of this : it's not properly iterating or the pins are not getting reset for the appropriate time. As i saw i oscilloscope the duration of pins value going low is very less as compared to the desired result.
I have given another piece of code in last, which worked. there i just pass functions directly instead of passing functions from the list and it worked. So do you have any idea, where i am going wrong in ASK25_SM_Send_Sequence() function.
So here goes my function for setting pins up.
Code: Select all
#Clearing the 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)
#Sequence of Stepper Motor Pins
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)
Now i have made a function to test the directions, and if its clockwise it will iterate through clockwise functions list and vice versa for anti clockwise.
This function rotates stepper motor in desired direction:
Code: Select all
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)
And here is the function that will be sending Sequence of pins to Set and reset
Code: Select all
def ASK25_SM_Send_Sequence(StMotorDirection, Delay):
temp = 0
SmAntClk = [Zero_A, Eight_Eight, A_Zero, Two_Two]
SmClk = [Two_Two, A_Zero, Eight_Eight, Zero_A]
while True:
if (temp < 4):
if (StMotorDirection == MotorClockwise):
pins_reset()
SmClk[temp]()
elif (StMotorDirection == MotorAntiClockwise):
pins_reset()
SmAntClk[temp]() #Sending the appropriate sequence from list
pyb.delay(60)
temp+=1
if (temp == 4):
temp = 0
And here goes my main function . Passing clockwise diection with 360 angle and 60ms delay
Code: Select all
def main():
# Initialize Stepper Motor pins
ASK25_SM_Init()
# Rotate stepper motor 360 degree with delay 60
ASK25_SM_Rotate(MotorClockwise,360,60)
main()
Here is the function that worked.
Code: Select all
def ASK25_SM_Send_Sequence(StMotorDirection, Delay):
if (StMotorDirection == MotorClockwise):
pins_reset() #Clearing the pins
Two_Two() #sending step 0x22
pyb.delay(Delay) #Delay
pins_reset()
A_Zero() #Sending step 0xA0
pyb.delay(Delay)
pins_reset()
Eight_Eight() #Sending step 0x88
pyb.delay(Delay)
pins_reset()
Zero_A() #Sending step 0x0A
pyb.delay(Delay)
elif (StMotorDirection == MotorAntiClockwise):
pins_reset() #Clearing the pins
Zero_A() #sending step 0x0A
pyb.delay(Delay) #Delay
pins_reset()
Eight_Eight() #sending step 0x88
pyb.delay(Delay)
pins_reset()
A_Zero() #sending step 0xA0
pyb.delay(Delay)
pins_reset()
Two_Two() #sending step 0x22
pyb.delay(Delay)