So who is this webpage for?
The purpose of this webpage is to help get you started building an H-bridge circuit to control a brushed DC motor. We will begin by discussing the theory of how they operate and why you would want to build such a circuit. Afterwards, we will then proceed to design and build one of our own. Finally we will discuss how to interface a programmable microcontroller with the circuit in order to drive/control the motor.
A few things to consider:
⁃ The H-bridge I describe here is probably not the most efficient (or best designed), but it is simple and serves as a good starting point that can be improved upon as your knowledge and skills increase.
⁃ I consider myself a beginner and just wanted to share what I have learned when trying to build my first H-bridge. Therefore, there are probably things about my circuit that could be tweaked or done better. (it does work "as-is" though.)
⁃ It is definitely helpful to have some understanding of basic electronics beforehand. You don't need to be a full-blown electrical engineer, but a general understanding of voltage, current, resistors, capacitors, transistors etc.. is helpful. I will touch on many of these things, but a "bottom up" explanation of every single electrical principle involved is beyond the scope of this website (and often-times my own knowledge!). An excellent reference to have alongside you is:
"Practical Electronics For Inventors", by Paul Scherz and Simon Monk
⁃ Additionally, some programming experience is necessary as we will be writing a program for the microcontroller which will drive the circuit. (In this case a Microchip PIC16F1937). The C language is pretty much the de-facto standard for programming microcontrollers and embedded work, but I will deal with PIC assembly language. Many people find assembly more difficult (and much more labor intensive), but I have found that it is an excellent way to learn how a computer actually operates without all the layers of abstraction in between you and the hardware. Assembly gives you absolute control over every single instruction processed by the chip. (More on this when we arrive at that point.) I will explain my code, but a thorough explanation of 8-bit PIC architecture is beyond the scope of this website and some prior knowledge is assumed. Probably the best reference I have seen to date on programming 8-bit PIC micros are the tutorials that can be found at:
Disclaimer: I have no affiliation with Googlium. The tutorials cost $15 for the complete PDF set (last time I checked). Trust me, it's the best $15 you will ever spend if you are serious about learning 8-bit PIC microcontrollers. (Better than most books I have seen.) The tutorials cover both Assembly and the C language.
For those just starting out Remember...
This stuff is hard and when it doesn't work right the first (or 17th) time don't quit. Suffice it to say that there are easier things to do in life than building your own circuits from bare components and running them with a microcontroller which you programmed yourself in assembly. Everytime I embark on a new "project" I experience endless cycles of the following 2 things:
- Circuit acts erratically, unpredictably or flat-out doesn't work at all
- Microcontroller code runs erratically, unpredictably or flat-out doesn't work at all
So don't worry, you aren't alone when (not if) this happens. It can take days, weeks or months to get something working correctly (depending on the complexity and the learning curve involved.) This isn't the "Arduino method" of buying a pre-assembled module and loading it up with "cut and paste" code from a library somewhere. There's nothing wrong with doing that when you already have the foundational knowledge and need to hack something together quickly. For a beginner (like myself) it's a detrement. You'll end up always being dependent on people more knowledgeable than yourself to produce a device or code library that you can easily integrate into your project. If Arduino doesn't make the module or the code in the library doesn't fit your application then what? Well, projects like this are a good step in the direction of gaining competence, so let's get started!
But first, let's discuss a little bit of the theory behind H-Bridges: Continue on to Theory