Microcontrollers for Robotics
If you are reading and learning about robots, you must already be aware of microcontrollers. In simple words, a microcontroller is an entire computer integrated into a single chip which includes a processor, memory, programmable input output pins etc. Most of your automatically controlled machines like a washing machine, microwave oven, mobile, gaming devices all have a microcontroller embedded within those complex circuits, making intelligent decisions.
Microcontrollers are not as powerful as a computer. They are good enough to communicate and control with other devices like sensors, motors, displays or even another microcontroller through its input output pins. A typical microcontroller has a series of pins which can communicate with other devices by reading and writing a sequence of 0’s and 1’s. Electrically speaking, the pins can be programmed to turn high and low while interacting with other devices.
Selecting a microcontroller
There are a number of microcontroller manufactures today like AVR, PIC, 8051, ARM, etc. Each manufacturer has a catalog of different microcontrollers available under their hood based on the architecture used, amount of memory, pins available, and features in-built.
It is always difficult to decide and point a microcontroller of choice. The projects in this site mostly make use of AVR microcontrollers. This also means that it is just a choice made and microcontrollers with similar features are available with other manufacturers too. Once you are knowledgeable on one kind of microcontroller, shifting to another one is easier.
What is in a microcontroller?
A microcontroller generally contains a processing unit, RAM (volatile memory), Flash memory, and digital input/output pins. Few microcontrollers may contain additional features like Analog to digital converters (ADC), timers, Pulse width modulation (PWM), counters, interrupts, Serial transmission (UART), I2C etc.
Processor: The central processing unit (CPU) of a microcontroller which contains the ALU (Arithmetic Logic Unit), CU (Control Unit) and a set of general and special purpose registers. (No memory management unit (MU or MMU) if you are from a computers background and wondering if a CPU is missing something ;)
Memory: This is where the program is stored. Memory can be flash memory, RAM, EEPROM etc. with each serving a different purpose
Input / Output Pins (IO Pins): The most important feature of a microcontroller in a programmer’s perspective. The number of pins and available memory usually decide the power of a microcontroller. Pins can be only input pins, output pins or both input and output pins. They can either serve as analog pins or digital pins. Usually microcontrollers have a built in analog to digital converters to communicate with the real analogous world.
IO pins are generally grouped into ports where each port contains 8 pins (They may contain less than 8 physical pins, but the pins are accessed as a byte with each bit controlling a pin).
Timers/Counters: Timers are used to measure the time gap or time intervals between activities. On the other hand, counters as the name suggests are used to count the events.
Interrupts: These are rule breakers and are used to interrupt a normal program flow. Generally most microcontrollers have an interrupt function built in.
Other features: Microcontrollers are readily used for basic input and output operations. However they may also include specialized features like Analog to digital conversion, bus controllers, Ethernet support, USB interface, Serial input-output features (UART), and support to other communication protocols like I2C (TWI in AVR microcontrollers), SPI etc.
Programming a Microcontroller
The juice of a microcontroller lies in its Input/output (IO) pins. Fortunately, microcontrollers can be programmed and a set of instructions can help in controlling these IO pins. If you are already aware of programming on a PC, then programming a microcontroller should not be difficult. One important fact to be aware is that when you are programming a microcontroller, you are directly interacting with the hardware.
Programming languages
Most microcontrollers support a wide variety of languages and C language being the most prominent amongst them. Other languages like Java, C++, Basic are also supported, and assembler if you willing to scratch your head and pull your hair out, but programming in assembly gives you more control.
Since C is widely accepted, I have often argued that it is a language of choice and has a huge support community behind it, especially if you are working with AVR microcontrollers. (The fact might be “I” particularly find it easier to code in C and few argue that BASIC is much better)
Like any other software development methodologies, it is always sensible to follow a set of predefined phases (Waterfall, Agile, Iterative etc. for those into software development). But be sure to allocate maximum time to your design phase since a good design would most likely result in a successful end product.
When not to use a microcontroller
If a robot is considered to be intelligent and capable of taking decisions, you should probably use a microcontroller. However there are robots which work on hardware logics and analogue circuits which do not use a microcontroller. For example, if you are interested in building a BEAM robot (acronym for Biology, Electronics, Aesthetics, and Mechanics) and your requirement is to power the robot with solar energy and move the robot once it is charged, then all you need is a set of transistors and capacitors. If you are making an obstacle avoider robot, then a bump sensor (tactile bumper switch) with a few transistors can give you the necessary logic to control your robot.
A microcontroller is used to make your life easier by giving you an option to program it, and control its pins. If you are smart enough to experiment, then robots can be built even without using one. But why risk when you can relax and work.
For more information about microcontrollers, refer microcontroller tutorial. Since most of the robots built here are based on AVR microcontrollers, you may take a quick look at AVR tutorial.
Do you have anything to say?
Visit the Forum to discuss, learn and share anything related to robotics and electronics !!