What’s a Microcontroller?

You may know what an OR gate is. An OR gate is a logic gate that takes two inputs and controls an output. You may have played with these types of gates, even possibly a DIP packaged OR gate with 4 OR gates built into it. This DIP package required a power pin and a ground pin. Electricity flowed through the IC and allowed it to operate. You may not be sure how the IC was built, but you understand that if you change the inputs, the output changes. You can do this by tying the inputs to either power (also known as VCC) or ground (GND).  You probably played with one of the DIP ICs in a breadboard. If any of this is completely alien to you, don’t fret! We’ll try to ease you into it.

A microcontroller is the same as an OR gate. You have some inputs, you have outputs. The crazy thing is that a micro runs code. Machine code to be specific. For instance, with a little bit of work, you can monitor the input of two pins A and B. And based on those inputs, you can control an output pin C. So to replicate an OR gate:

It’s C code! You can code up all sorts of different applications, compile code, load it onto a micro, power the micro, and the code runs. Very simple! Microcontrollers are used in all the electronics you take for granted such as your microwave, TV remote, cell phone, mouse, printer, there’s over 150 microcontrollers embedded into new cars! There’s one waiting for you to depress the brakes (BRAKES == 1) and for the tires to lock up (LOCK_UP == 1). When this happens, the micro releases the brakes, and you have ABS (anti-lock brake system).

In the old days, microcontrollers were OTP or one-time-programmable meaning you could only program the micro once, test the code, and if your code didn’t work, you threw it out and tried again. Now micros are ‘flash’ based meaning they have flash memory built inside that allows their code to be written and rewritten thousands of times. I’ve been programming micros for years and always burn out the microcontroller far before I hit the limit of flash programming cycles.

Flash micros are different than computers and RAM. Computers require tons of power and components to get up and running. Computers run HOT. Computers take forever and a day to boot. Micros are on and running code within milliseconds and if they’re warm enough you can feel heat coming off of them, something is very wrong and you’ve probably blown the micro. Oh – and micros cost about $2.

Now back to that OR gate IC. It had a bunch of pins, all dedicated to being either inputs or outputs of the various built-in OR gates (4 gates in one package = 8 inputs, 4 outputs, 2 power/gnd pins). 14 pins of fun. Now with a micro, the most basic pin function is GPIO – general purpose input/output. These GPIO pins can be configured as an input or an output. Very cool. Each input pin can be monitored and acted upon. Example:


then do something…

Each output pin can be pushed high or low.  Example:

Guess what that code does? It toggles a pin high/low every 2 seconds. Fancy right? This is the ‘Hello World’ of the microcontroller world. It seems trivial, but by god when you’ve been trying to get a micro up and running after 5 hours of tearing your hair out and you see that LED blinking for the first time, it’s just glorious!

What types of microcontrollers are there and how do I get one blinking?

Here’s a very shallow breakdown of the micros in my world:

  • PIC - This is the classic micro from Microchip. Very simple, very proven, but it lacks many of the features that other mfg’s are building into their chips. This is a big deal for me. I was a die-hard PIC person for years and I’ve started to see the limits of PICs and the benefits of other micros!
  • AVR - This is basically a direct competitor of PICs. They do everything a PIC does, but in my new opinion, better, faster, cheaper, and simpler.
  • MSP - These are very good micros by Texas Instruments (TI), not as beefy as AVR or PICs. However they truly excel at low-power applications. More on this later, but imagine running a complete system on one AA battery for 5 years. This is in the realm of nano-amp current consumption. Crazy!
  • ARM - Why are all these three letters? I don’t know actually… ARMs are the new kids on the block and they are huge. Very powerful, very low-cost, they are taking over the world but can be really intimidating if you’ve never played with a micro before.
  • 8051 - The ’8051 core’ was the de facto standard in 8-bit (and 4-bit!) microcontrollers. Developed by Intel in the 1980s, it still seems to be the instruction set they love to teach you in college. They are based on archaic, but field proven instruction sets. Very old tech in my humble opinion, but these ICs have been significantly improved over the years (now Flash based, ADC, SPI, etc.).
  • 68HC08/11 - Another very common instruction set developed by Motorola. Extremely popular, and a micro commonly taught at university, it’s the microcontroller I love to hate. These original micros often lack on-board RAM and flash based memory.

Google any of these for more info. I have chosen the ATmega168 as the learning IC of choice. Why?

  • 20 MIPs (million instructions per second!) is powerful enough to do some really cool projects
  • It’s cheap! $2.13 currently
  • It’s got all the goodies under the hood (UART, SPI, I2C, ADC, internal osc, PWM, kitchen sink, etc)
  • 16K of program memory is enough for almost any beginner project
  • The tools are free! (C compilers for many of the other micros cost a lot of money)
  • The programming and debugging tools are low cost ($20 will get you started)

With a little work and probably $40 worth of parts, you too can get an LED blinking. As with any new hobby (also known as a drug addiction), the extra cost of ‘goodies’ can grow very quickly.

Comments are closed