Chapter 1

Introduction

Abstract

Microcontrollers are single chip computers that include a minimum of a microprocessor, memory, and input-output module. Depending on the complexity, some microcontrollers include additional components such as counters, timers, interrupt control circuits, serial communication modules, analog-to-digital converters, digital signal processing modules, and so on. Thus, a microcontroller can be anything from a tiny single chip embedded controller to a large computer system having keyboard, monitor, hard disk, printer, and so on. A microprocessor is different from a microcontroller in many different ways with the main difference being that a microprocessor requires several additional external support chips such as memory and input-output circuits before it can be used as a digital controller. This chapter is an introduction to the principles of microcontrollers where several examples of microcontroller-based systems are described.

Keywords

Microprocessor; Microcontroller; Assembly language; High-level language; ARM; Microcontroller control system; STM32-Nucleo development board

1.1 Overview

Microcontrollers are single chip computers that include a minimum of a microprocessor, memory, and input-output module. Depending on the complexity, some microcontrollers include additional components such as counters, timers, interrupt control circuits, serial communication modules, analog-to-digital converters, digital signal processing modules, and so on. Thus, a microcontroller can be anything from a tiny single chip embedded controller to a large computer system having keyboard, monitor, hard disk, printer, and so on.

A microprocessor is different from a microcontroller in many different ways. The main difference is that a microprocessor requires several additional external support chips such as memory and input-output circuits before it can be used as a digital controller. A microcontroller on the other hand includes all these support chips on the same chip and that is why it is called a single chip computer. As a result, multiple chip microprocessor-based computer systems consume considerably more power than microcontroller-based systems. The costs of the single chip microcontroller systems are also much lower than the costs of the multiple chip-based microprocessor systems.

Microprocessors and microcontrollers operate by executing user programs. These programs are stored in the program memory of the device and consist of instructions that can be understood and obeyed by the device. The device fetches these instructions from its program memory one by one and then implements the required operations. Under the control of the user program data is received from external input devices (inputs), manipulated as requested, and then sent to external devices (outputs).

Microcontrollers (and microprocessors) have traditionally been programmed using the assembly language of the target device. The assembly language consists of many mnemonics where each mnemonic describes a basic instruction that can be carried out by the device. Although the assembly language is very fast, it has many disadvantages. Firstly, because of the syntax of the assembly language, it is difficult to learn this language. Secondly, processors developed by different manufacturers have different sets of assembly language instructions. Even in most cases the processors manufactured by the same manufacturer may have different assembly language instruction sets. As a result, the programmer may be required to learn a different assembly language every time a new processor is to be used. Thirdly, in general, it is difficult to maintain a program written using the assembly language.

Although the assembly language is still in use in some real-time applications, nowadays most applications are developed using a high-level language, such as BASIC, C, C ++, C#, Visual BASIC, PASCAL, JAVA, and so on. Perhaps the greatest advantage of the high-level languages is the ease of learning and fast program development. Large and complex programs can be developed in much shorter times compared to the assembly language. For example, to write a piece of assembly language program code to multiply two floating point numbers can take several hours or even more time and mistakes can easily be made. On the other hand, using a high-level language we just multiply the two numbers. Additionally, it is much easier to maintain a program written using a high-level language. High-level languages also have the benefit that in general the same user program can easily be transported to work on a different processor with little or no modifications. High-level languages are supported by large number of built-in libraries that make it easy to develop very complex programs in relatively short times. Finally, another advantage of using the high-level languages is that the developed program can easily be tested and this feature shortens the development time considerably.

In this book we shall be using the C language which is perhaps currently the most popular language used in microcontroller-based applications. As we shall see in the later chapters, the Mbed integrated development environment will be used to develop our projects. Mbed is an online integrated development environment that is used to develop ARM (Advanced RISC Machines) processor-based applications. Using Mbed we can write a program in C, then compile the program, and upload the executable code to the target ARM processor. The advantage of using Mbed is that it is easy to learn and use and is supported by very large number of library functions. The projects in this book are all based on the ARM processor. There are many ARM development boards available in the market. In this book we shall be using a model of the STM32-Nucleo development boards manufactured by STMicroelectronics. As will be discussed in detail in the later chapters, STM32-Nucleo boards are complete microcontroller development boards incorporating fast 32-bit ARM processors together with all the support circuitry to help develop complex projects. The STM32-Nucleo development boards are Mbed compatible which makes them ideal boards for developing complex applications in relatively short times.

1.2 Example Microcontroller-Based Control System

In this section we shall see how a microcontroller can be used in a simple control system application. Fig. 1.1 shows a liquid control system where the aim is to control the level of the liquid in the reservoir at a specified point. Water is pumped from the reservoir to the tank using a pump and pipes. In Fig. 1.1 the level of the liquid is controlled manually without using a microcontroller. Here, the person in charge observes the liquid level inside the tank and turns the pump off when the liquid level reaches the required prespecified level.

Fig. 1.1
Fig. 1.1 Manual liquid level control system.

The system shown in Fig. 1.1 is manual and requires constant attention of a person. A simple microcontroller version of this system is shown in Fig. 1.2. Here, the liquid level is read by the microcontroller via a liquid level sensor device. The program running inside the microcontroller compares the actual liquid level with the desired level and then actuates the pump automatically in order to keep the liquid at the desired level. If the liquid inside the tank is low, the microcontroller operates the pump to draw more liquid from the reservoir.

Fig. 1.2
Fig. 1.2 Microcontroller-based liquid level control system.

The system shown in Fig. 1.2 is a very simplified liquid level control system with no user interaction. In a more sophisticated system we may include a keypad to set the desired liquid level and an LCD (liquid crystal display) to see the desired and/or the actual liquid levels in the tank. Fig. 1.3 shows the block diagram of our upgraded system. Notice that here we are using two inputs and two outputs from our microcontroller.

Fig. 1.3
Fig. 1.3 Adding a keypad and an LCD.

We can make our system even more sophisticated as shown in Fig. 1.4 by adding an audible alarm to indicate when the water level is above the desired point. Also, a PC can be interfaced to the microcontroller so that, for example, the actual liquid levels can be sent to the PC at regular intervals and graphs of liquid level variations can be plotted on the PC between the required intervals.

Fig. 1.4
Fig. 1.4 Adding an audible alarm and a PC.

In Fig. 1.5, wireless interface is added to our system in the form of Bluetooth or Wi-Fi. With the help of the wireless interface we can, for example, send and save the liquid level readings on a Cloud. Additionally, we can monitor and/or control the liquid level remotely through the Cloud using, for example, a mobile phone. Because the microcontrollers are programmable and in general offer many input and output ports, we can make our system as simple or as complex as we like.

Fig. 1.5
Fig. 1.5 Adding wireless interface.

The power of microcontrollers is obvious from the simple example given in this section. Microcontrollers are classified by the number of bits they process at a time. Although some of the early microcontrollers were only 4 bits, the 8-bit devices are still the most popular and commonly used devices. Examples of some 8-bit microcontrollers are PIC16, PIC18, Arduino, 8051, and so on. The 16-bit and 32-bit microcontrollers are faster, have more memories, and are more powerful, but at the same time they are more expensive and their use may not be justified in many small applications. Examples of 32-bit microcontrollers are PIC32, ARM family, and so on. The STM32-Nucleo development boards used in this book incorporate 32-bit processors.

Memory is an important part of any microcontroller system. Currently the memory technology is very advanced and as a result the cost of memory chips have come down. Depending on the technology used we can have several different types of memories. The RAM (random access memory) is volatile where the data are retained as long as the power is applied to the device. These types of memories are used to store temporary data in our programs. RAM memories are used as data memories in microcontroller applications. The EPROM (erasable programmable read-only memory) keeps its data even after the removal of the power. These memory chips have small windows so that their contents can be erased with exposure to the ultraviolet light. The ROM (read only memory) also retains its contents after the removal of the power. These memory chips are normally programmed during the manufacturing process and once programmed their contents cannot be changed. The programmable read-only memories (PROMs) are similar to ROMs but they can be programmed once by using suitable programming devices. Flash memories are currently used in almost all microcontrollers. These memories are not volatile, that is, they keep their data even after the removal of the power. The main advantage of the flash memories is that they can be programmed many times. These types of memories are used as program memories in microcontroller systems. The USB memory sticks that we use to store data also use flash memories.

1.3 Summary

In this chapter we have learned about the following:

  •  What is a microprocessor?
  •  What is a microcontroller?
  •  The differences between a microprocessor and a microcontroller.
  •  The assembly language.
  •  High-level languages.
  •  The differences between the assembly language and high-level languages.
  •  The block diagram of a microcontroller-based liquid level control system.
  •  Different types of memories used in microcontroller systems.

1.4 Exercises

  1. 1. Explain the main differences between a microprocessor and a microcontroller.
  2. 2. Draw the block diagram of a heating control system used to control the heating in a room.
  3. 3. Draw the block diagram of a DC motor speed control system used to control the speed of the motor.
  4. 4. Explain the differences between RAM and EPROM memories.
  5. 5. It is required to control and monitor the temperature of an oven remotely using a mobile phone with Bluetooth capability. Assume that we have available a temperature sensor chip, a heater, a fan, and a Bluetooth interface module. Draw the block diagram to show how the system may be configured.
  6. 6. Repeat Exercise 5 by assuming that we wish to control and monitor the temperature with our mobile phone and Wi-Fi by sending and receiving data through the Cloud. Assume that we already have a local Wi-Fi router and a Wi-Fi interface module for our microcontroller.
  7. 7. In Exercise 6, explain the advantage of monitoring/controlling our oven through the Cloud.
  8. 8. Explain how the system block diagram in Exercise 5 should change if we wish to monitor the oven temperature via SMS messages received on our mobile phone.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.236.223.106