The Electrical System!

1 The PIC
2 The Breadboard
3 The H-Bridges
4 The Other Circuitry

Section 1 -- The PIC

A PIC is a Programmable Integrated Circuit. It is the big black ractangle on our breadboard. The standard PIC used in the course was a 28-pin package, the Microchip PIC18F2455. For our project, however, we uses a more robust PIC with more advanced PWM (Pulse Width Modulation) features that we were hoping to make better use of, so we used a 40-pin package, the Microchip PIC18F4455. This more robust PIC works in almost the same way as the other when it comes to the software and the function of the inputs and outputs, which made it easy to switch to, but because it is a 40-pin package as opposed to the much smaller 28-pin package, We couldn't just drop in the new PIC. In order to successfully convert from the 28-pin PIC to the 40-pin PIC, we had to sort through the documentation on the Microchip website. Once we found the specs for the two PICs, We were able to translate from the course materials which described the PIC18F2455 and how to connect it to the circuitry, and get the technical names associated with the pins on that PIC, and then find the right pins on the new PIC (See Figure 1). Once we were done decoding the PIC, we had to build the circuit.

Figure 1: This figure shows what pins of the robust 40-pin PIC18F4455 microcontroller were used, and for what.

About the PIC - The PIC is a programmable computer with digital and 'analog' inputs and outputs. It has a USB interface which allows us to send commands and data to the PIC, and to request data from the PIC. In our circuit we only use 6 digital outputs and 3 analog inputs. These analog inputs are not really analog, but rather convert a voltage between 0 and +5V to a number between 0 and 1023. (As stated in the Code section, we lose 2 bits of resolution, so our utilized value is between 0 and 255).

Section 2 - The Breadboard

The breadboard is the white grid on which our circuit is built. The breadboard is mainly a prototyping utility which would usually be replaced with a more permenant board. In our case, however, we did not have time to make our circuit more final. More important, however, than the surface on which our circuit is built, is the circuit itself. The cuircuit has 4 main components. The first component is of course the PIC which we have already discussed in detail. Along with the PIC comes the very important PIC programmer interface, which allows us to easily connect the PIC's ICD2 (In-Circuit Debugger). This means that we can use our computers to easily transfer programs onto the PIC, without complicated rewiring. The third component is the USB port. The USB port allows us to transfer data between the control laptop and the PIC while everything is running. This means that we can control our hovercraft from the computer that is connected to the PIC via USB, and even beyond that. The final piece on the breadboard is the set of three H-Bridges.

Figure 2: This picture shows the breadboarded circuit.

Section 3 - The H-Bridges

Before we can talk about H-Bridges, we should talk about motors. The motors we used in our hovercraft were newer model LEGO motors. These motors run at a speed proportional to the voltage difference across their terminals. This means that if one terminal is grounded and another is held at our circuit's +5V, the motor will run one direction, but if these voltages are switched, the motor will run in the opposite direction. The fact that these motors can be electronically reversible can be very handy. As I mentioned before we use 6 outputs for 3 motors, so clearly we are using 2 per motor. Why, you may ask? Well, our motors must have 3 states: Forward, reverse, and off. Anyone with a little knowledge of binary can tell you that 2 binary bits is enough to create 4 distinct states. The question is how? First we will assign a name to each output pin, (A and B will do). If we do the 'simple' thing and map the value of pin A to the voltage on terminal A of the motor, and the same for B, our control should be rather simple. In this way, if A is high (+5V) and B is low (Ground), the motor will go forward. If A is low and B is high, the motor runs backward. If A and B are either both high or both low, the motor has no voltage difference so it stops. While we have a good idea at this point, just hooking up the motor to the PIC won't do, because the PIC cannot transfer enough current to run the motor. For this reason we use an H-Bridge. An H-Bridge uses electronic switches to control voltages while using components capable of handling large currents. (See Figure 3)

Figure 3: This picture shows the particular H-Bridge used in this circuit.

The H-Bridge we used was not ideal, but functonal. It could easily have used 2 p-gate mosfets and 2 n-gate mosfets, but because there were no n-gate mosfets, we had to use a combination of a transistor and diode to get the same result. Let us examine the bottom-left circle in Figure 2. This circle denotes the p-gate mosfet. This can be simplified to a simple switch where if the voltage at point G is high, then current can flow from S to D. Thus if G is on (or Motor XA Pin is high), the left side of the motor is connected to ground. Since the top-left models an n-gate mosfet which is just the opposite of a p-gate mosfet, if Motor XA is high, current cannot pass through that section so the motor is seperated from +5V. (You may notice that this is the opposite of our original plan because now motor terminal A is actually opposite what the pin A reads. This is perfectly acceptable, and will just flip directions.) Since the left and right sides are symmetrical, we have constructed a model that works like the one we wanted.

Section 4 - The Other Circuitry

Up to this point we have only discussed the output half of the circuit. But I mentioned that we had 3 inputs. Did you guess that we have 1 per motor, because that would be absolutely correct. In fact, we have a way of telling the PIC where each motor is. This is done using potentiometers. Potentiometers are variable voltage dividers, and the way these ones are varied is by rotating them. What is a voltage divider? Voltage dividers use Ohm's Law to use resistances in situations with low current to get a voltage between two extremes. In our case, the potentiometer was placed between ground and +5 so that by measuring the voltage in the center of the potentiometer, we would be able to deduce a particular angle of rotation of the potentiometer. This means that we can have a precise measurement that tells us the angle of something. We attached these potentiometers to things in our hovercraft that turned. This way we could measure the current location of our motors relative to pre-measured values.

Figure 4: This picture shows an example of our finished motor assembly including the potentiometer at the top.