Atmel Atmega 1284p

The silent master: MicroController (Introduction)

dhwty
The Andela Way
Published in
5 min readMar 16, 2018

--

It is a common sight to spot a digital watch, a washing machine, a TV remote, Bluetooth speakers, or a microwave today. This list may seem somewhat random but there exists a common underlying technology that binds not only these but many more appliances that we have grown so dependent on in our everyday lives. The microcontroller is the common factor, this technology literally influences all aspects of our day to day lives from the shadows.

In this article, I will give you a sneak peek into the world of microcontrollers and the wonders that it can perform. This article will serve as an introduction to the technology that single-handedly delivers the futuristic life that we are living now. By the end of this article, you should know what a microcontroller is, common areas of application of microcontrollers, setting up for microcontroller development environment in your computer and finally do basics of microcontroller programming.

What is a Microcontroller?

Clearly, it is a chunk of silicon :D, but what’s inside of it? Rhetorical questions aside, it’s well worth getting the big-picture overview before we dive headfirst into flipping bits, flashing program memory, and beyond.

In this piece of silicon is a fully factional computer.

Microcontrollers are often defined as being complete computers on a single chip, and this is certainly true. At the very core of a microcontroller is a similar processor to the CPU in your computer which reads from a flash memory instead of a hard drive. Math is sent to the arithmetic logic unit (ALU), instead of a math coprocessor. Variables are stored in RAM. Some microcontrollers have dedicated hardware for communication to the outside world. So it has all the basic components that the modern computer has.

Like any computer, there are options for programming microcontrollers using a variety of languages. These include; Assembly, C, C++, Java and Python and the list goes on. Every language has its advantages, example:

  • Assembly is the most flexible and fast but it depends on hardware specifications and varies greatly from one instruction family set to another.
  • C is the most commonly used language for programming microcontrollers. It is relatively easy to learn and nearly all microcontroller chips support programming in C language or a flavour of C language. This is the language that we will be using in this article.

Some of the modern microcontrollers have developed to the point that they have a real time OS which gives much better experience than the bare metal experience. Zephr is an example of a real time OS (RTOS). Google is also developing their own version that is not based on the Linux kernel under the code name Fuchsia OS. With The RTOS the programming languages have been opened up. New entry includes JavaScript, the most popular language.

In this article, I will be using an AVR microcontroller since it is the most popular in the prototyping field. AVR microcontrollers are produced by Atmel, In the development of ARV Atmel worked closely with the GCC to make the development experience easy and fun.

These computers are not only small in size but also are very tiny in terms of memory typically the memory ranges from 1kb to 32kbs. Since the memory is limited it means that programming of microcontroller is somewhat different. This is what we will explore in the following sections.

Composition of a microcontroller

CPU -

The central processing unit (CPU) of the AVR microcontroller is basically very similar to that in your laptop or desktop computer. It is a bit of electronic circuitry that has a bunch of predefined logical and mathematical operations built in and knows where to find a list of these operations to follow (your program) and where to get the data it needs to execute them.

Memory -

AVR microcontrollers have no fewer than three different memory types, each with different uses.

1. Flash. Your compiled program code gets stored in nonvolatile flash memory. Data is not lost when the chip loses power. In fact, it’s guaranteed to only lose 1 bit per million after 100 years at room temperature.

2. RAM. Naturally, there is some memory for storing temporary variables while doing calculations and so forth.

3. EEPROM. Electrically erasable programmable read-only memory in full, is slow to write to, and there’s not much of it, but like flash program memory, it stays around when the power goes out.

Clocks -

All computers need a sense of time. In the AVR chips, there are multiple clocks that are all derived from the same common timebase but often divided down through their own individual prescalers. We’ll use the internal RC oscillator as the master clock source. It runs at around 8 MHz. The CPU clock is then divided down from the master clock and runs at 1 MHz by default, but sometimes when we need the extra speed, we’ll bump it up to the full 8 MHz.

Following the CPU clock come all the other peripheral clocks, most of which have their own prescalers relative to the CPU. There are clocks for the I/O subsystem, the analogue-to-digital converter, RAM, and Flash and EEPROM. When you’re using any of the peripheral subsystems, remember the clock prescalers - you’ll often have to set their values. These multiple clocks derived from the same source keep everything running on schedule together.

I/O (Inputs and Outputs)

Almost all pins can be set to input or output pin. This is where we give commands to peripherals or receive signals from sensors.

Microcontrollers have other components such as Serial communications, Analog to digital converter, interrupts, timers/counters and so on which I will not discuss in this article.

Recap

We have seen what a microcontroller is, some of the components that make up the microcontroller and its application. In the next article, I will be taking you through setting up your local development, writing and flashing your first program to an AVR chip. Till next time happy tinkering.

--

--