The Motor Drive Circuit Description


Our project consists of driving a four coil stepper motor (Rapidsyn 23H-502, 12 Volts, .44 Amps per phase).   Since the motor is larger than we could drive from the small NPN transistors in the lab, we used a IRF640 MOSFET based driver circuit.   This, in theory will allow us to drive up to a 18Amp per phase motor.   The circuit is repeated four times, once for each phase of the motor.   This is a unipolar drive circuit.


In the "cad" schematic above, the connections at the top labeled X1-2 to X1-5 are connected to the motor phase coils, and X1-1 is connected to the two common connections for those coils. The connections on connector PL1 are the four logic input signals to turn on the MOSFETS. The 10k resistors pull the MOSFETS low to shut them off in case a wire is loose, the 10 ohm resistors reduce ringing on the gate signal, and the zener diodes are optional protection for the gate. The 1N4934's across each coil are to protect the MOSFET from inductive flyback effects of the motor coils.

The stepper motor has 6 wires, 2 for positive voltage and ground, and 1 wire for each coil. As shown in the motor internal coil schematic below. We made use of a second UML91305 Dev board to connect 4 of its LED lights, one for each coil. As mentioned above, we used 4 MOSFET transistors that are capable of driving the motor with minimum of 0.44Amp per phase. As per the LogoChip boot diagram, we also used an inverter, one green and one red LEDs, a switch for start/stop, and the receive and transmit pins on the UML91305 dev board.
The basic LogoChip drive schematic is the non-cad one above. We connected the MOSFET drive signal lines to lines B4 to B7 of port B.
Next we found the correct sequence to turn our motor in each direction. To turn in the clockwise direction coils 3,2,4,1 had to be energized in order. To reverse direction, the order will be 1,4,2,3.
Internal Motor Schematic

The Network Description


Our network connection is from the computer serial port 1 to the first UML91305 dev board which is used to connect to the LogoChip and from the computer serial port 2 to the cricket IR board. The cricket IR board send an IR message to the cricket which in turn sends a message to the cricket. The cricket bus port is then connected to the LogoChip bus port (port B0) located on pin 21. As the code is written below, when the LogoChip sees code $180, it knows to start listening for movement parameters.

The Software Description


In the program, we made the LogoChip the slave and the cricket the master. We then introduced 3 global variables for number of steps, direction, and speed. For direction, we had 2 integer flags, the value 1 for clockwise, and the value 2 for counterclockwise. Next, to simulate speed, we have a short-wait variable delay function between each step. It is not enough to know the direction, the speed and the number of steps, we also need which is the next coil to energize in the sequence. For that we used a modulus 4 operator on the absolute step count. This gave us the location of the last energized coil. For instance if the result of the mod 4 operation is 0, we then set bits 4 and 5 and clear bits 6 and 7. If the mod 4 results a value of 1, we set bits 5 and 6 and clear bits 4 and 7. From this we created a function called "move :n :d :s", where ":n" is the number of steps, ":d" is the direction and ":s" is the speed.
Last we wrote a function called "slave". Inside "slave" we have 3 statements "waituntil [newbus?]", one for each expected variable. The variable is read through the network call "brcv". When all 3 variables are received, we make the "move" call.

To run the LogoChip we used:

global [steps dir speed]

to slave
   waituntil [newbus?]
   if brcv = $180 [
     flash
     waituntil[newbus?]
     setsteps brcv

     waituntil[newbus?]
     setdir brcv

     waituntil[newbus?]
     setspeed brcv

     move steps dir speed
  ]
   powerdown
slave
end

constants
[[portb 6][portb-ddr $86]
 [portc 7][portc-ddr $87]]
to init
 write portb-ddr 0
 write portc-ddr 1;sets portc as input
end


global [position]
global [dir]
global [speed]

to powerdown
  clearbit 4 portb
  clearbit 5 portb
  clearbit 6 portb
  clearbit 7 portb
end

to step :n
  if  (:n = 0) [setbit 4 portb
            setbit 5 portb
            clearbit 6 portb
            clearbit 7 portb]
  if (:n = 1) [setbit 5 portb
            setbit 6 portb
            clearbit 4 portb
            clearbit 7 portb]
  if (:n = 2) [setbit 6 portb
            setbit 7 portb
            clearbit 4 portb
            clearbit 5 portb]
  if (:n = 3) [setbit 7 portb
            setbit 4 portb
            clearbit 5 portb
            clearbit 6 portb]
end

to short-wait :n
   repeat :n [no-op]
end

to move :n :d :s
init
setposition 10000
setdir 1
if :d = 2 [ setdir -1 ]
repeat :n [
 
        setposition ( position + dir )
        step (position % 4)
        short-wait :s
        ]
end

Then to run the code, we typed in "slave" into the LogoChip command window.
And we typed the following lines into the cricket:
bsend $180  ;Tell our cricket bus device we are talking to it. (and nobody else!) 
bsend 200   ;Move 200 steps (1 full revolution).
bsend 1     ;Move clockwise (use 2 for counterclockwise)
bsend 400   ;Interstep delay (Velocity)