Since last week, we have been
trying to run the new brushless DC motor; however, it is still difficult to control,
let alone its speed.
Therefore, we had to pursue
our alternative motor, the mini-stepper motor that runs at 5V. Found in Arduino
starter kits, this mini-stepper motor is accompanied by its dedicated motor
driver board, the ULN2003, which is a chip containing a series of Darlington pair
transistors. An image of the stepper motor and the ULN2003 board is shown below:
Sources:
We were able to successfully
run the new mini-stepper motor with the sample code included with the Arduino
starter kit. One benefit to using the sample code is that it utilizes the Stepper
library’s functions. One use function is the setSpeed( ) function, which allows
the user to set the RPM speed of the stepper motor. We found that the maximum
speed the motor could go without twitching, or vibrating erratically, was 30 RPM.
It then calls the step( ) function to actually drive the motor.
A screenshot of the sample
code is displayed below:
The drawback to the sample
code is that the step( ) function drives the stepper in regular wave drive mode,
which involves energizing one coil at a time. This is the basic way of driving
a stepper motor, and it does not present any advantages: it does not entail stepping
the motor with hi-torque nor does it step the motor in half-steps nor
micro-steps for finer movement. Running a stepper with hi-torque involves
energizing 2 adjacent coils at a time. Running a stepper motor in half-steps
involves alternating between energizing 1 coil, then 2 coils, etc. And running
a stepper motor in micro-steps involves energizing one coil with a decreasing pulse-width-modulated
(PWM) signal and energizing the next coil with an increasing PWM signal.
We ultimately decided to run
the motor with hi-torque, as we did not need the motor to move in finer steps,
but rather we wanted the motor to be able to overcome bumps in the track.
Our code is provided below:
/********************************************************************** SUCCESS
*
* ME 106 Lab 8 Question 8 (Hi
Torque / Full Step Drive)
*
**********************************************************************/
/*
* This is Lab 8: Stepper Motor, Exercise 4,
Question 8:
* High-Torque Mode
* Using the coil sequence from Exercise 1, the
program will:
*
* Contain a function called steps_hitorque()
that implements
* high-torque mode, which works on the
principle of energizing
* two coils at the same time (Figure 5) instead
of one. Once
* again, a negative value indicates that the
motor should be
* driven in the opposite direction (CCW
direction).
*/
/* (I) Include libraries */
/* (II) Variables */
// define the connections to motor driver inputs
#define IN_1 10
#define IN_2 11
#define IN_3 12
#define IN_4 13
int CW_coilA [4] = {IN_4, IN_3, IN_2, IN_1};
int CW_coilB [4] = {IN_3, IN_2, IN_1, IN_4};
int CCW_coilB [4] = {IN_1, IN_2, IN_3, IN_4};
int CCW_coilA [4] = {IN_4, IN_1, IN_2, IN_3};
/* Delay of 6000 microseconds = 0.006 sec */
const int minDelay = 1600;
/* (III) Function Prototypes */
void steps_hitorque(int mySteps);
/* (IV) setup */
void setup()
{
// setup the pins to motor
driver as outputs
pinMode(IN_1, OUTPUT);
pinMode(IN_2, OUTPUT);
pinMode(IN_3, OUTPUT);
pinMode(IN_4, OUTPUT);
}
/* (V) loop */
void loop()
{
/* Call the steps_hitorque
function once. Rotate 2048 steps (1 revolution) CW. */
// steps_hitorque(2048);
/* Call the steps_hitorque
function once. Rotate 2048 steps (1 revolution) CCW. */
steps_hitorque(-2048);
}
/* (VI) Function Definitions */
void steps_hitorque(int stepsToMake)
{
/* Current step number (used as
a counter) */
int mySteps = 0;
/* If user inputted a pos
number, turn the stepper CW */
// int CW_coilA [4] = {IN_1,
IN_2, IN_2, IN_1};
// int CW_coilB [4] = {IN_3,
IN_3, IN_4, IN_4};
if(stepsToMake > 0)
{
while(mySteps <=
stepsToMake)
{
for(int i = 0; i < 4;
i++)
{
digitalWrite(CW_coilA[i],
HIGH);
digitalWrite(CW_coilB[i],
HIGH);
delayMicroseconds(minDelay);
digitalWrite(CW_coilA[i],
LOW);
digitalWrite(CW_coilB[i],
LOW);
mySteps++;
}
}
}
/* If user inputted a neg
number, turn the stepper CCW */
// int CCW_coilA [4] = {IN_1,
IN_2, IN_2, IN_1};
// int CCW_coilB [4] = {IN_4,
IN_4, IN_3, IN_3};
if(stepsToMake < 0)
{
while(mySteps >=
stepsToMake)
{
for(int j = 0; j < 4;
j++)
{
digitalWrite(CCW_coilB[j], HIGH);
digitalWrite(CCW_coilA[j], HIGH);
delayMicroseconds(minDelay);
digitalWrite(CCW_coilA[j], LOW);
digitalWrite(CCW_coilB[j], LOW);
mySteps--;
}
}
}
}
Comments
Post a Comment