I modified the source code in first blog and rewrite it in more systematic order and more functions are added.
The port 2 of msp430 launchpad is used as it coincidently has six pins, the control of one easydriver more of less need three pins for interface, so two stepper motors control need six pins.
The pins used are shown in figure below.
The port 2.0 to 2.2 are used to control first stepper motor, the port 2.3 to 2.5 are used to control second stepper motor.
Previously mentioned, the three pins are interfaced with easydriver
(MOTOR_X_DIR_PIN,
MOTOR_X_STEP_PIN,
MOTOR_X_SLEEP_PIN).
The MOTOR_X_STEP_PIN is used to send continuous pulses from launchpad to easydriver
(post 1).
The MOTOR_X_DIR_PIN is used to decide the rotational direction of stepper motor, clock wise or anticlockwise.
The MOTOR_X_SLEEP_PIN is used to disable or enable the easydriver IC. Even when the launchpad is not sending pulses to easydriver, the easydriver still sourcing current to stepper motor to hold the motor shaft in present position. When the easydriver is sleep (by sending 0 signal), easydriver is not sourcing current and the motor shaft can be easily moved.
The pins assignment are as follow:
The stepper motors are addressed as A and B. The naming which has A indicates the first stepper motor, B indicates the second stepper motor.
In order to control two steppers motor concurrently, the instruction sent must be delivered in the same time, so the pin of stepper motor A and B are combined.
Only three functions are need in the main program
the motorsInit() function set the IO pins for interfacing with easydriver,
motorsRunCycles(int stepper_cycles) function controls the stepper motor
turn how many circles.
If stepper_cycles > 0, the stepper motor run in clockwise direction,
If stepper_cycles < 0, the stepper motor run in anti clockwise direction.
for motorsGotoPosition(int stepper_degrees) function, you can turn from -360 to 360 degree.
from 0 to 360 degrees, the stepper motor run in clockwise direction,
from 0 to -360 degrees, the stepper motor run in anti clockwise direction.
(the smallest resolution is one degree).
Last, the interfacing between launchpad, easydriver, and stepper motor is shown as follow
All the source codes are shared in github.
No comments:
Post a Comment