Introduction: Augmenting a Microcontroller
Microcontrollers (MCUs) are fantastic little ICs that give an extra element of versatility to your electronics, robotics or other project. But they're really not much use on their own. To function, all MCUs need some sort of support components, and a board to live on — one example of course being the famous Arduino. These boards are called 'augmented microcontrollers'. And why not make one yourself?
This instructable will guide you through the generic steps of designing and building an augmented microcontroller board. I have purposefully made it generic so that I do not limit it to a particular make or model of MCU, and I'll try to mention alternative ways of doing things to make it a bit easier for you.
I'm going to be designing and making an augmented microcontroller board for a 28 pin Microchip PIC, the 16F886. My example is going to be for a robot, so I'm going to include motor driver circuits, digital and ADC headers and some indication LEDs.
A generic list of materials/tools:
MCU and assorted supporting components (caps, resistors, headers)
A breadboard for prototyping
Some way of permanently building the circuit (I'll be etching copper board)
So — let's get started.
Step 1: Designing the Main Circuit
For the purposes of this instructable I'm assuming that you'll be programming a blank MCU via some sort of in-circuit programming interface (I'm using Microchip 6 pin ICSP). Bootloaders and USB programming are a bit out of my programming depth as of writing!
The most obvious element of the circuit is the microcontroller. Surrounding it will probably be:
Power Supply Regulation
External Clock (If you need one)
Let's deal with these one at a time…
Power Supply Regulation
Your MCU and surrounding circuitry will probably run at either 5v or 3.3v. I'm using 5v, but similar methods apply for 3.3v. There are two main types of DC-DC power regulation, linear and switching. Linear is easy, switching is more efficient. Linear involves one device, usually a three pin IC, and some capacitors, whereas switching will require a larger IC and various other components.
You need to include at least three power supply caps: ~10uF Aluminium across the unregulated supply, ~4.7uF across the regulated supply, and 0.1uF ceramic across the power rails of the MCU. If you don't have one elsewhere in your circuitry, you should have a ~300uF aluminium cap across the unregulated power too. A power indication LED is nice, too. One in series with a 1K ohm resistor, running off the regulated power is a nice touch. Make it green. We like green.
Most MCUs have some sort of reset or mclear pin that, when bought to a certain state, resets the MCU and makes it start it's program again. On the PIC16F886, this pin should be held high to enable the MCU to operate, but we'll add a reset switch which momentarily brings it low, resetting the MCU if we need to. Some MCUs have built in P/U resistors, so just a switch to GND is needed.
This is where the MCU connects to your computer to receive it's program. PICs and AVRs both use six pin headers, but in different formats. I'll be using a 6 pin RJ-45 socket, as they're hardy and will put up with me constantly plugging and unplugging as I try desperately to correct the errors in my programs! Consult relevant datasheets to see what the pinout of the connector is, and which pins of the MCU they need to connect to.
Sometimes there can be problems with adjacent data/clock lines, and some people recommend putting an R/C filter on one or both of the lines. This can help reduce crosstalk and interference, meaning less headaches later on. I'm not including a filter in this project.
Not all MCUs have an internal oscillator (an oscillator somewhere is required to give the MCU a synchronised 'beat' that all of it's sub-systems can work to), and even if it does, you might want a particularly high/low operating frequency, or a more accurate beat for intense timing applications. These can take various forms:
R/C Oscillator: Cheap and inaccurate. Only use this if your MCU has no int. oscillator, and you don't want to spend any money.
Crystal: More accurate and the metal cans look awesome on a PCB ;) They will require a couple of small caps. to function.
Canned oscillator: Is essentially a crystal and the caps in a little box/ceramic (as shown by schematic). I'll be using one of these.
These are usually very simple: A male or female header, connected to relevant pins. You could also use terminal blocks for more heavy-duty use. Most MCUs will not need Pull up/down resistors, but you might choose to add them to 'default' the pins to high/low. I suggest 47K-67K ohms, to +V or Gnd.
On the other hand, you might choose to add some extra circuitry between the MCU and the external connections. Leading conveniently onto the next step!
Step 2: Designing Auxiliary Circuits
If you want to make an ultra-multipurpose, generic microcontroller board, then what I've covered already is enough. It's the bare basics that will get your MCU up and running and expandable. But if you want to make yourself something a bit less generic, more powerful, application-specific and cool-looking (i.e. a really augmented microcontroller), then consider adding some extra circuitry.
This is for a mobile robot, so I'm adding two MOSFET H-Bridge motor drivers (the schematic for one is shown). But you could add an LCD screen, USB/Parallel communication hardware, supporting circuitry for photodiodes, etc. Depending on your level of ability, maybe even some kind of bluetooth, WiFi or other RF communications facility!
Basic principles of circuit design apply: Whatever you add must run off the same power supply as the rest of the circuit (Actually, my motor drivers will partially use unregulated power, but they share a common ground). It must not generate noise that interferes with the MCU, must not create large voltage spikes that could destroy the MCU, and must interface with it at current/voltage levels that the MCU can provide (hence the 4427 driver, not just a direct connection to the MOSFETs).
So for my motor driver, I'm going to use 4427 chips to drive the MOSFETs, controlled by the low current 5v signals from the MCU. I'm going to include EMF protection diodes, and capacitors of various sizes and chemistries to support the circuit's power requirements. In practical terms, this means: a 47uF Electrolytic Capacitor and a 20uF Tantalum cap. in parallel across the power rails, and a 0.1uF ceramic/other cap. across the power rails of every IC, just like on the MCU.
(A tip for recognising MOSFET types from the diagram: The arrow always points to N semiconductor)
I'm also going to add two LEDs, a green and a yellow, controlled by the MCU. They just need a 1K ohm resistor in series with them, and they can plug straight in to a spare pin. They'll be used as generic indicators, which are very useful during debugging.
Step 3: Prototyping the Entire Thing
Get everything together onto a breadboard and see if the thing works. Obviously don't bother plugging headers in, just put the circuit together and download a program. Check voltages, make sure LEDs light up. Make sure any auxiliary circuits work too — probably best to do this separate to the main one, to save you from a breadboard nightmare.
At this point, you need to think about how you're going to make the actual board. I'm drawing the circuit onto copper board in permanent marker pen and then etching it, but you might want to get a board professionally made. Other alternatives include point-to-point wiring, or stripboard. I wouldn't recommend soldering it freeform, but I suppose you could if you really wanted to…
If you have an idea about what you're going to use the board for (I'm assuming you do…), consider layout carefully. On a robot, for example, is the programming header in a convenient place? Will the motor leads be long enough to reach the terminals? Will I be able to see the indicator LEDs?
Also, consider how the board is going to attach to your application. A screw hole in each corner makes the most sense, but really huge boards might need some more. I like spacing my screw holes at multiples of 1 LU (Lego Unit), so that I can use lego to build a chassis quickly. Same applies for other things: Dimensions of chassis, dimensions of any other boards you want it to interface with, etc.
Step 4: Creating the Board
Lay the major structural components out on the board and fiddle around with the layout. Odds are you're not as crazy as me and are going to use a sensible shape of board — but, who knows!.
I'm etching copper board, using a mixture of SMD and TH components. What you do is entirely up to you. Some of the alternatives, in more details:
Etching Copper Board
My favourite way of creating permanent/semipermanent circuits. It's not too difficult, just requires some time and experience. The pattern is printed onto the board in some way (I draw it with permanent markers), then the board is submerged in a chemical that dissolves away all the metal it can reach, leaving you with the bits you want. Can be single or double layer. I like double layer. Some pointers:
On the bottom layer, keep as much of the copper as you can (called a copper flood) and ground it. This creates a 'ground plane' that not only makes circuit design easier (as you can connect to Gnd from pretty much anywhere), but reduces noise problems too. You can make your own vias (top-bottom layer joins) with a bit of wire. On single sided boards (or very crowded double sided) you might have to use wire links in places. This doesn't matter, but keep them to a minimum and keep them short.
This can be a great material, but requires careful soldering and cleaning as it's all too easy to inadvertently create a flux join between two adjacent strips. If you can get your head round board layout, it can make surprisingly efficient use of space. Cut strips wherever need be, and make use of wire links (or carefully placed components) to lay out your circuit. This can get really quite confusing for complicated circuits!
Point-To-Point Prototyping Board
This is another valid method, although one I must admit I have not tried. It looks rather awkward, makes for less stable circuits and is generally harder to debug, I infer. However, done right it can yield great results, so if you're comfortable with it, go for it.
The SMD MOSFETs I'm using to drive the motors are taking a very, very long time to arrive, so I'm publishing this 'ible now, and I'll update it with tips on designing + etching the board, as well as soldering and assembly. Thanks for reading!