Stepper Module

Description

Contains the functions for initializing, homing, and stepping the stepper motor according to the potentiometer input

StepperInit()

Takes 3 arguments: two InputT , an OutputT and returns nothing. The main program uses this function to tell the Stepper Module which ports it can use for limit switches inputs and stepper control output

StepperReset()

Takes nothing and drives the stepper so that the dropper moves all the way to the right until the right limit switch is depressed.

StepperTrack()

Takes no variable and returns nothing. This function read the voltage at the potentiometer then writes appropriate values the stepper control ports so that the dropper moves ONE increment toward the corresponding desired by the user.

 

Note: In order to control the stepper at reasonable speed (hence torque), we need to pause between consecutive increments. To avoid blocking code, this timing is done only in main (see TrackTimer in main)

Left(),
Right()

These functions take no variable and rotate the stepper so that the dropper moves ONE increment to the left (right)

Implementation

Module Definition

DEADBAND=6

Module static variables

static InputT RightLimit, LeftLimit

            RightLimit and LeftLimit store input configuration data for the limit switches

static OutputT Stepper

Stepper stores output configuration data for the four stepper bits.

static unsigned int position:

position is used to keep track of the relative position of the stepper.

StepperInit()

Simply pass the argument of StepperInit (2 InputT and 1 OutputT) into the corresponding module static variables (LeftLimit, RightLimit and Stepper)

StepperReset()

While the right switch is not depressed

Right (Move the stopper ONE increment to the right)

Wait  20ms (This function is done at the beginning of the game when PLINKO is not supposed to response to any other user interaction, thus, this blocking code does no harm to the system).

Poistion=0

StepperTrack()

Read the voltage v coming out of the potentiometer

Scale v to an appropriate range

If position<v-DEADBAND

If the left limit is not depressed

            Left

Else set position=178 (max value)

If position>v-DEADBAND

If the left limit is not depressed

            Right

Else set position=0 (min value)

 

Note: The value 178 is found by experiment which assures that the dropper covers the whole track.

Right()

Write appropriate values to stepper control ports so that the dropper moves ONE increment to the right (see Stepper control sequences)

Increment position by 1

Left()

Write appropriate values to stepper control ports so that the dropper moves ONE increment to the left. (see Stepper control sequences)

Decrement position by 1