Workshop 6: Stepper Motor Control

 

Purpose: Using the embedded controller control a stepper motor.

Objective: This workshop is designed to familiarize the student with elements of the embedded microcontroller.

Real world application: Controlling robotic appendages.

Requirements:

Hardware: Bipolar stepper motor (Supply Voltage <46Volts, Operating Current <4 Amps), L298 Stepper motor driver chip, 1K OHM potentiometer, Voltmeter

Software commands: Call AD1

Procedure: Design and implement a program that will rotate a robotic hand. The control input will taken at ADC1. Move a stepper motor in the direction and the amount based on the following table:

0-1 volt - counterclockwise, one step
1-2 volts - counterclockwise, two steps
2 - 2.5 volts - counterclockwise, one rotation
2.5 - 3 volts - clockwise, one step
3 - 4 volts - clockwise, two steps
>4 volts - clockwise, one rotation

Set the inputs to L298 to 01/ 01upon startup. Setup the program so that the it must be reset after each movement. The potentiometer should be wired to the +5 volts power supply per the diagram below:

 

 

Circuit Drawing for Workshop #6

PicBasic Code for Workshop #6

 

'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

'A program to rotate a robotic hand in the direction and magnitude
'depends on input voltage.
'Herb Wagner

'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

symbol mv=w4                          'designate mv to hold millivolt
                                                'input
set:                                              'initial stepper motor inputs
low 0: high 1: low 2: high 3

start: call ad1                            'convert analog signal at ADC0
    w0 = w10 * 6 / 5                   'to a millivolts
    w1 = w10 / 50
    w2 = w10 / 1000
    mv = w0 + w1 + w2

if mv <= 1000 then move1    'if less than or = to 1V
                                                 'move CCW one step

if mv > 1000 and mv < 2000 then move2           'if greater
                                                                            'than 1V and less than 2V
                                                                            'move CCW two steps

if mv >= 2000 and mv < 2500 then move3    'if greater
                                                                           'than or = to 2V and less
                                                                           'than 2.5V move CCW 1 rotation

if mv >= 2500 and < 3000 then move4 'if greater          'than or = to 2.5V and less
                                                                                        'than 3V move CW 1 step

if mv >= 3000 and mv < 4000 then move5       'if greater
                                                                             'than or = 3V and less than 4V
                                                                             'move CW two steps

if mv >= 4000 then move6                'if greater than 4V than
                                                         'move CW 1 rotation
goto set                                              'default

'***********************************************************

move1:
          high 0: low 1: low 2: high 3                'move hand CCW one step
         goto stop

'***********************************************************

move2:
         high 0: low 1: low 2: high 3                'move hand CCW two steps
         high 0: low 1: high 2: low 3
         goto stop

'***********************************************************

move3:
          high 0: low 1: low 2: high 3              'move hand CCW one rotation
          high 0: low 1: high 2: low 3
          low 0: high 1: high 2: low 3
          low 0: high 1: low 2: high 3
          goto stop

'***********************************************************

move4:
          low 0: high 1: high 2: low 3             'move hand CW one step
          goto stop

'***********************************************************

move5:
         low 0: high 1: high 2: low 3             'move hand CW two steps
        high 0: low 1: high 2: low 3
        goto stop

'***********************************************************

move6:
        low 0: high 1: high 2: low 3              'move hand CCW one rotation
        high 0: low 1: high 2: low 3
        high 0: low 1: low 2: high 3
        low 0: high 1: low 2: high 3

'***********************************************************

stop:
end