Microcontroller Embedded C Programming Lecture 56| What is Microcontroller?

 

Microcontroller

 

 

What is Microcontroller and how it works?

  • Microcontroller(also abbreviated as MCU, which stands for microcontroller unit) is a small computer system on a single chip.

But its resources and capabilities such as memory, speed, external interfaces are very much limited than of a desktop computer because of MCU targets embedded applications.

  • A typical microcontroller includes a processor, volatile and non-volatile memories, input/output(I/O)pins, peripherals, clock unit, bus interfaces everything on a single chip. That’s why a microcontroller is also called as a system on chip.

 

Figure 1. Microcontroller
Figure 1. Microcontroller

 

  • Processor unit, which is also called a CPU. 
  • Peripherals
    • Analog peripherals → ADC, DAC
    • Timing related peripherals →  TIMERS
    • Connectivity peripherals →  UART, USB
  • Different types of memories
    • Volatile memory → SRAM
    • Non-volatile memory → FLASH, ROM, EEPROM 
  • Clock unit
  • Bus interface 

so everything is implemented or fabricated on a single chip, which we call a microcontroller. 

 

 

Anatomy of a Typical Small Microcontroller

Let’s take a closer look at what’s inside a microcontroller. Figure 2 illustrates a basic diagram, though the internal structure of modern microcontrollers is often much more complex.

Figure 2. Anatomy of a Typical Small Microcontroller (MCU)
Figure 2. Anatomy of a Typical Small Microcontroller

 

A microcontroller typically contains a CPU, also known as the Central Processing Unit.

The central processing unit(CPU) executes instructions(your program instructions), and those instructions are stored in Program memory.

Usually, program memory is a non-volatile memory. That means, once you store your program into the program memory, that is permanent. I mean, you can erase it, and you can write different programs, but even if you take out the power from the microcontroller, the program memory will not be corrupted, so your instructions will be there permanently unless you change it.

Once you give power to the microcontroller,  a CPU reads instructions from the program memory, and it executes. That means before that CPU should communicate with the program memory.

CPU is a different entity, and program memory is a different entity. CPU communicates with a program memory using bus interfaces. So, there is a bus called the Address Bus. Because, before reading an instruction, a CPU must produce the location or the address of that instruction, which is there in the program memory.

So, the CPU first produces the address on the Address Bus. After that, the instruction will then come into the Instruction Bus, or you can also call it a Data Bus, and from there, instruction will reach to the CPU. The CPU has something called an instruction decoder,  so the CPU decodes the instruction, and according to that action will be taken.

 

How fast the CPU executes instructions depends upon the clock supply to the CPU?

All these things will see as we make progress by taking industry-standard microcontroller such as STM32.

This is the simplest diagram that I am showing to you. So, there will be one clocking unit that will supply the clock to the CPU. Depending upon the clock’s speed, the speed of code execution will be controlled.

Code memory: non-volatile, and it is used to store your program instructions.

Data memory: volatile and it is used store data of your program and also used as a scratchpad.

Apart from non-volatile memory, there is also something called volatile memory, which is called as data memory.

Basically, a program operates on data. The data part or data of the program is actually stored in the data memory. So, you can also use data memory as a scratchpad. That means, if you want to store some data temporarily, then you can use data on memory. 

Usually, the data memory of the MCU is consumed during the run-time of the program. Because, there are various occasions when a program needs to store and delete data temporarily. In that case, the program can use data memory. That’s why it makes sense to use volatile memory as data memory, as a scratchpad. So because we don’t want that data to be stored permanently, that’s why data memory is actually a volatile memory. When the power is taken off from the microcontroller, the contents of the data memory will be lost.

 

And apart from that, a microcontroller program also should communicate with the external world. You are sending some commands from your mobile phone to the microcontroller over Bluetooth.  A microcontroller should communicate with a Bluetooth module. And that can be enabled by using the I/O interfaces. So, there is something called Serial I/O, Parallel I/O.

MCU receiving data from Bluetooth and storing in data memory
Figure 3. MCU receiving data from Bluetooth and storing in data memory

 

For example, if you want to connect a Bluetooth receiver to this microcontroller, then you would be connecting that Bluetooth module through Serial I/O. That’s why I/O interfaces are very important, and almost all microcontrollers support this feature. 

 

Inside view of the Microcontroller 

Let’s take an example of one of the most famous microcontrollers produced by ST microelectronics. STM32 series of microcontrollers.

Figure 4 is a picture that is given by the ST documents. And here, we can see that it shows all the internal parts of the STM32 Microcontroller. 

What is a Microcontroller MCU
Figure 4. Inside view of the Microcontroller

 

If you look into this image(as shown in Figure 5), you can identify various parts of this microcontroller. The heart of this microcontroller is a processor which is sitting inside the microcontroller. 

The STM32F407 microcontroller is an ARM Cortex-M4 based central processing unit. That’s a processor. This processor is developed by ARM. This is not actually developed by ST. So, ARM develops processors, and then it licenses them to other microcontroller manufacturers.

In this case, it is ST microelectronics, and they take the software implementation of the processor unit and customize it according to their need,  and then they implement it on the chip. 

In this case, the ARM processor has the capacity to run at a maximum of 180 megahertz. That’s pretty fast for the Embedded application. 

Microcontroller(MCU) Embedded C Programming
Figure 5. Inside view of the Microcontroller

 

Apart from that, all these things you see here like System, Connectivity, Control, Analog are implementation of ST. They have implemented different peripherals around the processor. And all these are implementations of ARM.

If you look at the Peripheral set, they have different peripherals to serve different purposes.

For example, these are connectivity related peripherals(Figure 5). Suppose a microcontroller wants to communicate with the external world, then connectivity related peripherals will be used, such as SPI (Serial Peripheral Interface), camera interface, CAN, I2C, USB, etc.

For the Analog work, you have digital to analog converters, ADCs, Temperature sensors, and various other things.

The control related peripherals don’t communicate with the external world, but those are actually will help you to do control related activities like PWM, Wave generation, Timers, and various other things. 

The system related peripherals, such as RTC, which takes care of real-time clocking.

It has a PLL engine, which is used to boost the clock. And the microcontroller has inbuilt oscillators. They are called as Internal RC oscillators. So, even if you don’t connect any clock or any crystal to this microcontroller, this microcontroller can run by using its default oscillators which are right there inside the microcontroller. So, you need not connect any external crystal oscillators to this microcontroller. It has the capacity to make use of internal RC oscillators, so those RC oscillators produce a clock to the central processing unit and for various bus interfaces and to the peripherals.

It also has a low power control circuitry. It also has an internal power regulator, which is used to produce a regulated power supply to the microcontroller, and also it has watchdog timers.

 

Embedded memory

Let’s take a look into the Embedded memory. These are the embedded memories inside the microcontroller(as shown in Figure 6).

Figure 6. Embedded Memory
Figure 6. Embedded Memory

 

Flash is used for code memory, and SRAM is used for data memory. So, SRAM is volatile memory, and flash memory is non-volatile memory.

Inside the flash memory, you are going to store your instructions. And apart from that, it has external memory interfaces if you want to connect to more external memories such as flash memory or SDRAM memory.

And also, it has one-time programmable (OTP) memory, and all these are internal memories. And this is how a modern microcontroller looks like for embedded applications.

 

PIC Microcontroller Example

PIC stands for peripheral interface controller, a famous microcontroller in the 8-bit application domain, and this microcontroller is manufactured by a company called a microchip. If you look into its internal parts, it is almost similar to the previous one.

Microcontroller Embedded C Programming
Figure 7. PIC Microcontroller

 

Here also, there is a central processing unit, but this is not an ARM processor remember. This is a proprietary processor design from the microchip itself.

It’s their own CPU architecture, you can call it as PIC architecture. It’s their own CPU. That’s why it has its own instruction set. So,  the code you have written for STM will not run on the microchip until you cross-compile it again using the compiler which is produced by the microchip. 

Apart from that, you can see that it also has internal oscillators. So, to produce a clock, a default clock to the CPU and for the peripherals. And it has various peripherals similar to the previous one. 

Timers, it also has a program memory, data memory, and it also has an onchip EEPROM and the I/O ports to communicate with the external world. The analog peripherals, timers, and PWM are quite similar. 

 

Tiva Development Board

The Tiva Development Board, powered by Texas Instruments, and it carries a Tiva series of microcontrollers.

Tiva Development Board
Figure 8. Microcontroller development board

 

It has a microcontroller, which is also based on the ARM Cortex-M4 processor. In this case, the maximum achievable speed is 80 MHz.

This microcontroller also has various embedded memories. You can see here it also has 2 kilobytes of EEPROM. It also has all the Analog peripherals, various connectivity related peripherals, and some other peripherals.

The peripherals to include and peripherals to exclude all these are driven from the marketing end, and it depends on the application area which the microcontroller targets. So, at the end of the day, the microcontroller features are driven from the marketing end.

In the following article, let’s explore different types of code memories, which are implemented on the microcontroller.

 

FastBit Embedded Brain Academy Courses

Click here: https://fastbitlab.com/course1

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.