For the motors lab, because I didn't have access to an h-bridge, I worked with Stepper motors instead of DC motors, using unipolar steppers that could be run with transitors (or transistor arrays) instead of h-bridges.

Working with the steppers went very smoothly, once the wiring of the motors were figured out. Unipolar stepper have six wires running out of them, two of which go to power and four others. There was a minor crisis with this because the notes on stepper motors on the pcomp site actually had typos in them which mixed up the wires and caused untold confusion. We wound up seeking Caryn's assistance and testing the resistance between each wire to figure out which was what.

After that was solved, the actual wiring was pretty easy. Also, we used 12 volt steppers, so we ran 12 volts from our power into another bread board, hooking up the stepper power to that, instead of running it from the micro-controller or the 5v regulator.

Here is an image of the final set up:

I them programmed the pic to step in one direction if a switch was flipped one way, and in another direction if it was flipped another from the code notes on the pcomp page.

I them changed the code to move 10 steps when a switch was flipped. Accidently declared my index variable for my for loop as a bit and not a byte, so it didn't have enough storage to count to 10 at first, but fixed that and it worked just fine.

start:

High PORTB.0

' set variables:

x VAR BYTE

steps VAR WORD

previous var bit

stepArray VAR BYTE(4)

i var byte

clear

TRISD = %11110000

PORTD = 255 input

portb.4

Pause 1000

stepArray[0] = %00001010

stepArray[1] = %00000110

stepArray[2] =%00000101

stepArray[3] = %00001001

previous = 0

main:

    if portb.4 = 1 then
        if previous = 0 then
            for i = 0 to 9
                steps = steps - 1
                portD = stepArray[steps //4] 
                pause 200
            next
        endif
        previous = 1   
    else 
        previous = 0
    endif

goto main


Page last modified April 24, 2006, at 08:05 PM