Microcontroller

What is this "Microcontroller" anyway?

Microcontroller

A Microcontroller is essentially a one-board computer or a PC on a chip. Your home computer uses many different modules for memory and processing that plug into a motherboard and stack up to be the large computer tower sitting next to your monitor. In contrast, a microcontroller has tiny versions of all of those individual boards built on one single board that can be the size of a postage stamp or smaller.

Wow, how do they do that?

This is accomplished when an electrical engineer miniaturizes the components that are used in the PC size board to a single component the size of a grain of rice. How is this done? Well, your computer is large because it does anything you ask it to do. If you need to write a paper, you can use a document editor. If you want to edit photos, it can do that too. In the quest to make chips small, the electrical engineer will remove this ability from the microcontroller chips so that they are only able to perform a few simple dedicated functions. And this is what a microcontroller does best: listen to and respond to the environment. Several of these minimalistic rice-size components are then assembled to make one of those small black computer chips (called Integrated Circuits or IC's) that you have probably seen in a broken calculator or other electrical device.

Several of these IC's-one for processing, one for data storage and some to regulate what gets plugged in-are attached or soldered to a computer board. This board, when completed, looks like a centipede with between 8 and 32 wire legs, each of which can be used to input data, output data, count button pushes, turn on a switch, make a sound or anything else you can imagine.

But why do you want to measure things anyway? I've never needed to push a button with a computer or to count how many times something happened!

MicrocontrollerImagine if the cable for your mouse didn't have the USB or PS/2 fitting on the end - there would just be four wires sticking out that needed to be attached to the computer (one to measure how far forward the mouse moves, one to measure how far to the side the mouse moves, and two for power).

In the microcontroller world, the two power cables would be attached to a plug or battery, and the two measurement wires would be attached to two of the "legs" of the microcontroller. Every time the mouse moves a certain distance, a signal (think of a playing card in a bicycle wheel) is sent to the microcontroller and counted. If 100 of these signals or clicks is equivalent to one mouse ball rotation, and the microcontroller has received 100 clicks in the forward direction and 50 clicks in the sideways direction, the computer, with the aid of some simple programming, can understand that the mouse has moved one ball rotation forward, and a half rotation sideways.

That's how a computer works? It seems so difficult!

It's not actually as hard as it sounds. Using some very basic logic and good programming, you can tell a computer to do anything.. As for the computer program, well, this is where a software engineer would write a piece of code in a language of his or her choice that very logically tells the computer what the signals mean. An example for the mouse would be:

PROGRAM EXPLANATION

PIN 1 = Input Y Direction

Tells the chip pin 1 is an input to measure the Y movement

PIN 2 = Input X Direction

Tells the chip pin 2 is an input to measure the X movement

If PIN 1 = CLICK

Asks, "Did I receive a click signal from pin 1? If I did, perform the following line, if not, skip the following line

Counter add 1

If pin 1 received a click, increment the counter by 1

If PIN 2 = CLICK

Asks, "Did I receive a click signal from pin 2? If I did, perform the following line, if not, skip the following line

Counter2 add 1

If pin 2 received a click, increment the counter by 1

LOOP

Go to the beginning until no more signals are transmitted, then go to the next line

Output "your mouse moved"

Display the text "your mouse moved"

Output Counter

Display the numerical value of counter

Output "clicks in the Y direction"

Display the text "clicks in the Y direction"

Output "your mouse moved"

Display the text "your mouse moved"

Output Counter2

Display the numerical value of counter2

Output "clicks in the X direction"

Display the text "clicks in the X direction"

If the mouse moved the previously stated amount, the output of this program looks like this:

"Your mouse moved 100 clicks in the Y direction"
"Your mouse moved 50 clicks in the X direction"

If you wanted more useful data, you could write a mathematical function in the program that converts clicks to mouse rotations and then to inches, if you knew the diameter or radius of the mouse ball (about a half inch) and the formula for the circumference of a circle (C=pi*D). An example of this program for the Y direction would be:

PROGRAM EXPLANATION

Pi=3.14159

Defines the value of Pi as 3.14159

D=.5

Defines the Diameter (D) as .5 inches

Yrotation = counter/100

Converts counter into revolutions
(one revolution is 100 clicks)

Ycircumference = pi*D*Yrotation

Calculates the circumference of the ball in inches (C=D*Pi) and multiplies that by revolutions

Output "your mouse moved"

Displays "your mouse moved"

Output counter

Displays the value of counter

Output "clicks"

Displays "clicks,"

Output Yrotation

Displays the value of Yrotation

Output "revolutions"

Displays "revolution, or"

Output Ycircumference

Displays the value of Ycircumference

Output "inches"

Displays "inches"

If the mouse moved the previously stated amount, the output of this program would look like this:

"Your mouse moved 100 clicks, 1 revolution, or 1.5708 inches"

Using this logic, you can have a microcontroller perform any task you can think of by adding different sensors, buttons, motors and lights. The microcontroller can even do several things like this at once-as many measurements and commands as there are input and output pins on the controller.

So why is my computer so big when this microcontroller computer can do anything the large PC can do?

There are a lot of reasons, but it comes down to storage and input and output pins. If a mouse uses 2 pins, just imagine how many a printer or a keyboard may use. And if a microcontroller usually has no more than 32 pins, you will quickly run out of places to plug things in. Additionally, there is only a very small storage device on a microcontroller. It is just large enough to store the program that controls it, and about 15 extra words or numbers (variables). That means you could only write one- or two-sentence reports on a microcontroller computer. The benefit of this is that, because the microcontroller has fewer abilities and parts, it is significantly cheaper and smaller than a desktop PC. This is no good if you want a computer that can do anything. But if you want a computer to do one or two specific things very well, there is no better option than a microcontroller. So if you need more then a few inputs and outputs, and want to store large documents and print things, you should probably stick to a large PC; but if you are looking for a small inexpensive computer that can fit in a tight space to control a simple electronics project or remote control vehicle, a microcontroller is for you.

Please report website issues to info@seaperch.org

Terms of Use & Privacy | Copyright 2020. All Rights Reserved.