Introduction to Microcontrollers

By | May 8, 2014

Microcontrollers can be found in almost any complex electronic device – from portable music devices to washing machines to your car. They are programmable, cheap, small, can handle abuse, require almost zero power, and there are so many varieties to suit every need. This is what makes them so useful for robotics – they are like tiny affordable computers that you can put right onto your robot. One of the important applications of microcontroller is in Vehicle Monitoring and Security System.

I. Introduction to Microcontrollers

A microcontroller is a microprocessor that controls everyday appliances such as microwaves and wristwatches. The micro kits used by computer engineering classes use a Motorola HC11 microcontroller for all of the processing. The HC11 microkits have 8 input switches, a single interrupt request button (IRQ), 8 output LEDs, and a two-line liquid crystal display (LCD). The HC11 kit also has a pulse accumulator, or a counter, which is incremented once per clock cycle.
In a pure sense, a microcontroller is just an IC (integrated circuit, or a black chip thing with pins coming out of it). However it is very common to add additional external components, such as a voltage regulator, capacitors, LEDs motor driver, timing crystals rs232, etc to the basic IC. Formally, this is called an augmented microcontroller.

Microcontroller IC

Fig. 1 Microcontroller IC

Augmented microcontroller

Fig. 2 Augmented microcontroller

What comes with the IC?

The important feature on a microcontroller is the I/O ports. Input ports are used for taking in sensor data, while output is used for sending commands to external hardware such as servos. There are two types of I/O ports, analog and digital.

A. Analog Input Ports.

They receive analog signals and convert them to a digital number within a certain numerical range. So what is analog? Analog is a continuous voltage range and is typically found with sensors. However computers can only operate in the digital realm with 0’s and 1’s. So how does a microcontroller convert an analog signal to a digital signal? First, the analog is measured after a predefined period of time passes. At each time period, the voltage is recorded as a number. This number then defines a signal of 0’s and 1’s as shown:

Analog signals

Fig. 3 Analog signals

The advantage of digital over analog is that digital is much better at eliminating background noise. Cell phones are all digital today, and although the digital signal is less representative than an analog signal, it is much less likely to degrade since computers can restore damaged digital signals. This allows for a clearer output signal to talk to your mom or whoever. MP3’s are all digital too, usually encoded at 128 kbps. Higher bit rates obviously mean higher quality because they better represent the analog signal. But higher bit rates also require more memory and processing power.
Most microcontrollers today are 8 bit, meaning they have a range of 256 (2^8=256). There are a few that are 10 bit, 12 bit, and even 32 bit, but as you increase precision you also need a much faster processor.

B. Digital I/O Ports

Digital ports are like analog ports, but with only 1 bit (2^1=2) hence a resolution of 2 – on and off. Digital ports obviously for that reason are rarely used for sensors, except for maybe on/off switches . . . What they are mostly used for is signal output. You can use them to control motors or LEDs or just about anything. Send a high 5V signal to turn something on, or a low 0V to turn something off. Or if you want to have an LED at only half brightness, or a motor at half speed, send a square wave. Square waves are like turning something on and off so fast that its almost like sending out an analog voltage of your choice.

Digital Signals

Fig. 4 Digital Signals

Fig. 4 Digital Signals

These square waves are called PWM, short for pulse width modulation. They are most often used for controlling servos or DC motor H-Bridges.

C. Serial Communication, RS232, UART

A serial connection on your microcontroller is very useful for communication. You can use it to program your controller from a computer, use it to output data from your controller to your computer (great for debugging), or even use it to operate other electronics such as digital video cameras. Usually the microcontroller would require an external IC to handle everything, such as an RS232.

D. Timers

A timer is the method by which the microcontroller measures the passing of time – such as for a clock, sonar, a pause/wait command, timer interrupts, etc.
E. Programming Languages
The lowest form of programming languages is the machine language. Microcontrollers need to be programmed with this. An example of machine language:
3A 10 51
32 38 00
Obviously neither of us could ever memorize what all those seemingly random numbers and letters do, so we would program in a higher language that makes much more sense:

If (language = = easy)
print “yay!”;

These higher languages would then be compiled automatically into a machine language, which then you can upload into your robot. Probably the easiest language to learn would be BASIC, with a name true to itself. The BASIC Stamp microcontroller uses that language. But BASIC has its limitations, so if you have any programming experience at all, I recommend you program in C. This language was the precursors to C++, so if you can already program in C++, it should be really simple for you to learn. What complicates this is that there is no standard to programming microcontrollers. Each has its own features, its own language, its own compiler, and its own uploading to the controller method.

Please Share: Tweet about this on TwitterShare on FacebookShare on Google+Share on RedditPin on PinterestShare on LinkedInDigg thisShare on StumbleUponShare on TumblrBuffer this pageShare on VKEmail this to someone

Leave a Reply

Your email address will not be published. Required fields are marked *