LPC812 MAX Experiment: Stepping Motor

Experiment: Stepping Motor

In this experiment you will learn how to control a http:en.wikipedia.org/wiki/Stepper_motor.

Hardware

In this lab you will need:

  • 1x breadboard
  • 1x 330 ohm resistor
  • 1x trimming potentiometer
  • 1x step motor
  • 1x L293D step motor driver
  • cables

Mount the components on the breadboard and connect the breadboard to the LPC812 as show in the image below.

Breadboard Setup

Information

The stepper motor in the experiment kit does not look exactly like the stepper motor in the image above. The connector will differ but the important thing is that the order of the cables from the breadboard to the motor is either 1-2-3-4 or 4-3-2-1.

The pin(s) are specified in the mbed library with the actual pin names as well as some useful aliases:

Schematic Namembed Pin NameArduino Shield AliasDescription
AIN0_XPIO0 (SJ5 in 1-2 pos)N/AA0Trimming Potentiometer
PIO0_13P0_13D10Step Motor Driver pin 1A
PIO0_14P0_14D11Step Motor Driver pin 2A
PIO0_15P0_15D12Step Motor Driver pin 3A
PIO0_12P0_12D13Step Motor Driver pin 4A

1) Description

The stepper motor has four control signals (1A and 3A) and the inverse of those (2A and 4A) so to move it one step clockwise you have to control the outputs in this sequence:

1A2A3A4A
1010
1001
0110
0101

To get it one step anti-clockwise the sequence is the reverse so:

1A2A3A4A
0101
0110
1001
1010

The step motor in the experiment kit is specified to have a step angle of 18o or 20 steps per revolution.

Use the following program as a starting point:

main.cpp

#include "mbed.h"

DigitalOut ph1(D10);
DigitalOut ph2(D11);
DigitalOut ph3(D12);
DigitalOut ph4(D13);

int main()
{
    // Delay between steps
    float number = 0.5;

    // Initialize outputs
    ph1=1;
    ph2=1;
    ph3=1;
    ph4=1;

    while(1) {
        ph1 = 1;
        ph2 = 0;
        ph3 = 1;
        ph4 = 0;
        wait(number);
        ph1 = 1;
        ph2 = 0;
        ph3 = 0;
        ph4 = 1;
        wait(number);
        ph1 = 0;
        ph2 = 1;
        ph3 = 0;
        ph4 = 1;
        wait(number);
        ph1 = 0;
        ph2 = 1;
        ph3 = 1;
        ph4 = 0;
        wait(number);
    }
}

Experiment with different values of the delay (not recommended to go below 0.05) to see how it affects the speed.

Change the direction of the rotation by reversing the different steps.

2) Description

In the previous step the delay was fixed, it is now time to control it with the trimming potentiometer. Use the PCF8591 class from the Analog Input experiment to read the value of the trimming potentiometer and convert it into a reasonable delay.

Import library

Public Member Functions

PCF8591 (PinName sda=P0_10, PinName scl=P0_11, int i2cAddr=0x9E)
Create an interface to the PCF8591 chip.
int read (AnalogIn port)
Reads one value for the specified analog port.

An alternative is to use the trimming potentiometer for both direction and speed. If the value is above 128 it turns one way and if it is below it turns the other way. The 0 and 255 are maximum speeds in the respective directions.

3) Description

This experiment the goal is to use absolute positioning of the stepper motor. Each step is 18o so the input will not be more accurate than that. Use the trimming potentiometer to give the position.

Solution(s)

Import programlpc812_exp_solution_stepper-motor

Solutions for the Stepper Motor experiments for LPC812 MAX


1 comment on LPC812 MAX Experiment: Stepping Motor:

28 Nov 2014

There is an inconsistency in the tables for clockwise/anti-clockwise rotation. Steps 3 and 4 seem to be switched. The program works for me correct.

Please log in to post comments.