What are microcontrollers? They are what their name suggests. Today they 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 variaties 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.
Augmented Microcontrollers and Development Boards
As a beginner it is probably best to buy an augmented microcontroller. Why? Well because they have tons of goodies built onto them that are all assembled and debugged for you. They also often come with tech support, sample code, and a community of people to help you with them. My microcontroller parts list shows the more popular types that you can buy. They tend to cost from $30 to $150 depending on the features. This will give you a good introductory to microcontroller programming without having to be concerned with all the technical stuff.
In the long term however you should build your own augmented microcontroller so that you may understand them better. The advantage to making your own is that it will probably cost you from $10-$30.
Between getting a full augmented board and doing it yourself is something called a development board. These boards come pre-augmented with just the bare basics to get you started. They are designed for prototyping and testing of new ideas very quickly. They typically cost between $15 and $40.
What comes with the IC?
For robots, ore important than any other 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.
Analog Input Ports
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:
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.
What does this bit stuff mean for ADC? For example, suppose a sensor reads 0V to an 8 bit ADC. This would give you a digital ouput of 0. 5V would be 255. Now suppose a sensor gave an output of 2.9V, what would the ADC output be?
Doing the math:
X = 2.9*255/5 = 148
So how do you use an analog port? First make sure your sensor output does not exceed your digital logic voltage (usually 0V -> 5V). Then plug that output directly to the analog port.
This bit range could also be seen as a resolution. Higher resolutions mean higher accuracy, but occasionally can mean slower processing and more succeptability to noise. For example, suppose you had a 3 bit controller which has a range of 2^3=8. Then you have a distance sensor that outputed a number 0->7 (a total of 8) that represents the distance between your robot and the wall. If your sensor can see only 8 feet, then you get a resolution of 1 bit per foot (8 resolution / 8 feet = 1). But then suppose you have an 8 bit controller, you would get 256/8=32 ~ 1 bit per centimeter - way more accurate and useful! With the 3 bit controller, you could not tell the difference between 1 inch and 11 inches.
Digital I/O Ports
This is an example of a square wave for PWM:
Also a quick side note, analog ports can be used as digital ports.
Serial Communication, RS232, UART
Another interesting note, you can stack IC's in parallel to double the allowable current and heat dissipation. Theoretically you can stack as many as you want, as long as the current is high enough to still operate the logic of the IC. This works for voltage regulators too.
An example of machine language:
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:
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 precurser 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.
This is why I do not go into too much detail because there are too many options out there to talk about. The support documents that come with the controllers should answer your specific questions. Also, if you decide to use a PIC, understand that the compiler program (at least the good ones) can cost hundred of dollars. Most microcontrollers also require a special interface device between your computer and the chip for programming which could also cost from $10-$40.
If however you are more experienced (and for some odd reason still reading this), you can customize your own circuit to do exactly what you want. Why have a motordriver when you are only using servos anyway? If you decide to buy an augmented MCU, the cost will range from about $50-$150. To compile your program, you would need to get special compiling software. Atmel and BASIC Stamps have free compilers. PIC's however have fairly expensive compilers. There are some free ones available online, but they are of poor quality in my opinion. CCSC PIC C compiler is about $125, but I think it is worth getting if you are going to use PIC's.
You will also need an uploader to transfer the program from your computer to the chip. This generally requires more special software and a special interface device. The Cerebellum PIC based controller has this built in which is really nice and convienent, but for any others expect to spend from $10-$40. People often opt to just make their own as the circuit isnt too complicated.
As a prototyper, what you probably want most is a MCU development board. These augmented microcontrollers are designed for the prototyper in mind. To find these augmented MCU's, do a search for 'pic development board,' 'atmel development board,' 'stamp development board,' etc.
Has this site helped you with your robot? Give us credit -
link back, and help others in the forums!
Society of Robots copyright 2005-2014