Introduction to Microcontrollers

In this article I will try to describe microcontrolers and their function. I’ll give a brief description of the parts of the microcontroller.

Microcontrollers and Microprocessors

microcontrollerWhat is the difference between Microcontrollers(MCUs) and Microprocessors (or also known as Central Processing Unit or CPU)? Well, they are very similar. The major difference is that microprocessor itself is not a complete device. It needs a lot of external components/modules to operate. Another difference is that microprocessors are usually more advanced and are used for more complex tasks. Microcontrollers on the other hand is a complete device. It has built in program memory, RAM, peripherals even system frequency oscillator. Just plug the power and it can operate.

Parts of the microcontroller

Every (or most of them) microcontroller consists of these modules:

  • Control Logic
  • Program memory
  • Data memory
  • Inputs/Outputs
  • Oscillator(s)
  • Timers
  • Peripherals

The Control Logic is the heart of the microcontroller. It is where all the instruction decoding, math and other functions happen.  I guess you won’t be completely wrong to say that the Control Logic is the microprocessor of a microcontroller … if it makes any sense.

HarddiskThe Program Memory is like the “hard disk” in the computers, except that it’s a lot smaller. And when I say “a lot” I really mean it. It’s capacity is about 10 000 to 1 000 000 times smaller than a hard disk. It could be anywhere from 256 bytes up to … Well in digital world you don’t set any upper limits because at the time you finish the sentence there is already something better and bigger. Let’s say that at the time this article is written a large number for program memory in a microcontroller would be 128kB to 512kB.  You would ask “Even 512kB  is not enough for a program … how would you fit a program in 256 bytes?”. If you want the complete answer you might have to read at least half of the articles on this site.

RAMThe Data memory serves a purpose similar to the RAM in personal computers. However if you thought program memory is too small you will be shocked of the size of the Data memory in microcontrollers. It starts from just a few bytes (let’s say 16 if you really want a number)! Some computers use 16 bytes to store just 2 numbers.  My personal computer has 16 GB RAM. That’s 1 000 000 000 times more!

ioUsing the Inputs and Outputs the microcontroller interracts with the rest of the world. They could be digital or analog. Digital inputs/outputs only have 2 levels – low and high. Usually low level is near the power supply rail and low is near the ground rail. Analog inputs/outputs are connected to different peripherals. Could be ADC or DAC or comparators, or things that you probably never heard of, designed by chip manufacturers to make your life easier.

timerTimers are important part of the microcontroller. Often you need to perform specific task in specific period, or measure time, or count something. That’s where timers help a lot. They are usually simple counters that count number of pulses. The source of the pulses could be different – internal oscillator, external signal or event in microcontroller.

peripheralsBecause microcontrollers usually have limited computing power (and by computing I mean a lot more than just calculation), the one thing that helps them to do things faster is peripherals.  There are all kind of small devices inside the microcontroller chip that do things independently while the microconroller program runs. Example of peripherals are: I2C/SPI/UART/ PWM controllers, ADC, DAC, etc. They can do all kinds of staff – measure things, communication, generate signals … etc. It’s not like without peripherals you can’t do just the same, but then the MCU will have to work on higher frequency to catch up and also you’ll have to spend the time to write the program. It takes a lot less time to write code to controll a peripheral than to write a program to do the same job.  And well some peripherals are hard to do and others – impossible. You can’t work with analog signals without having the corresponding analog peripheral – like comparators or ADCs for example. Oh, well you can always use external chip.

That’s it. I tried to be as short as possible because I know it’s boring to read pure theoretical stuff. In following articles I’ll try to give practical examples to make it more interesting.

Tagged with:
Posted in Beginners