May 31 2008

Maze Table : The Motor Controller

Published by Ron at 12:22 am under Electronics

I could have gone with a microcontroller on the maze table motor controller, but I opted for using discrete components instead, with a little help from a L298 H-Bridge chip. And H-Bridge is a circuit which allows you to reverse a DC motor. The chips make things easier by handling some of the inverter and “AND” logic for you. Plus, they are built to handle nice sized inductive loads, which some low-end transistors might have a harder time with.

Here’s a photo of my completed controller board:

Maze Table Controller Board

The bottom part (from top to bottom) has a 2N3906 PNP transistor, a 10K resistor, then a small 1N914 signal diode, and finally a single pin header which will be connected to the joystick. Why the PNP setup? Because the Atari-style joystick takes a direction/pin and ties it to ground. So, the emitter (left part) of the transistor is tied to VCC (+5V) — those red wires — and the base (center) goes to the switch. When the switch is pressed, the transistor puts +5V (roughly) at it’s collector (right part), which is then sent to the H-Bridge chip.

The signal diode are there to prevent power from going “backwards”. For my setup, they probably aren’t needed. However, if I was doing an “OR” situation (ex. wanted to drive two motors at once), then there would be more diodes, in a more complicated setup. Check out David Cook’s extremely helpful article here: Controlling Robots With Atari Joystick. It helped me a lot, though my design diverges with the H-Bridge chip used (I used a more powerful one) and how the motors get driven (I’m not trying to get a robot to drive “forward”, so my stuff is easier).

Okay, above the transistors is the L298 H-Bridge chip. It can control two motors, forward and reverse. Once you get how these things work, they are very easy to use. For each motor, you have two control lines. Let’s say Input 1 and Input 2. If you do Input 1 High and Input 2 Low, the motor goes one way. Do the opposite and it switches direction. There is also an “enable” pin which must be held High for power to be supplied to the motor.

I like the L298 because it can handle some mean load (40+ volts) and it has two power levels. One for logic (running the chip), up to 7 volts. The other for motor power (up to 40 or so volts).

On the downside, it is mean for a PCB and not a perf/strip board, so the pin-layout is a big pain in the butt. I got around this by putting female headers (sockets) and by “twisting” the pins a bit. It means that there are 8 pins in one row and 7 on another (it’s a 15 pin chip). It can be very confusing, so be careful.

The PNPs collectors feed to the appropriate “input” pins on the L298. They also, through more switching diodes, trigger the “enable” pins on the chip. You must “enable” and input, otherwise you won’t get juice out. (This is by design, as it allows you to shut off motors without cutting off inbound logic. Think of it as a un-mute button.) Again, take a look at David Cook’s site. He does a good job explaining everything.

Above the Bridge you have the output area. This is where I have the output jack connections, inbound board power connections, status LEDs, etc. Nothing overly exciting, though I’d recommend this: Put status LEDs everywhere. I have an LED for logic (5V) power and another for motor (12V) power. I’m also thinking of adding some on the PNPs and maybe the output pins (to indicate power and direction). It may seem like overkill, but this is going to be re-used in the future, and having those indicators saves a LOT of time when trying to debug problems. Think of it as “breakpoints” in electronic circuits. (They can also save your life when it comes to power supplies. A simple LED alerted me to a “hot” AC connection that could have zapped me. Thank you, 5 cent part.)

After all that fun, and some heartache too (stupid me wired base to input, instead of collector to input), I got the darn thing working. The maze table now moves around with joystick control. The only problem is that the marble doesn’t like moving around my prototype board. I’ll have to try another material, but the concept is sound, so I’m moving forward.

 

Comments Off

Comments are closed at this time.