Cem UEnsalan, PhD, has over 20 years of experience working on signal processing and embedded systems. He received his doctorate from Ohio State University in 2003. He has published 23 papers in scientific journals and eight international books.
Duygun E. Barkana, PhD, has over 16 years of experience working on control and robotic systems. She received her doctorate from Vanderbilt University in 2007. She has published 22 papers in scientific journals and six international book chapters.
H. Deniz Gurhan is pursuing a PhD at Yeditepe University, where he received his BSc degree. He has over six years of experience working with guided microprocessors and digital signal processing.
Hardware to be Used in the Book
Throughout the book, we will not only introduce digital control concepts from a theoretical perspective, we will also implement them on embedded hardware using C and Python languages. Therefore, the reader should become familiar with the hardware to be used. This chapter aims to introduce these concepts. To do so, we will assume a novice user as our target. Besides, we will cover all hardware topics as abstract as possible. Hence, they can give insight on similar platforms. As for embedded hardware, we will pick the STMicroelectronics NUCLEO-F767ZI development board (STM32 board) and STM32F767ZI microcontroller (STM32 microcontroller) on it. These are the mediums our C and Python codes for digital control will be implemented on. Afterward, we will introduce the DC motor, its driver, and related hardware to be used in examples throughout the book. Finally, we will introduce other systems and sensors which can be used in advanced applications. As all the hardware is introduced, we will be ready to use them in practical digital control applications in solving real-life problems.
2.1 The STM32 Board
Our C and Python codes for digital control will run on the STM32F767ZI microcontroller. However, we cannot use this microcontroller alone since it needs extra hardware to operate. There should be programming and debugging circuitry accompanying the microcontroller. Hence, it can be programmed easily. For these reasons, development boards emerged. These have all the necessary circuitry on them. Therefore, they provide a complete environment to use the microcontroller. In this book, we pick the STMicroelectronics NUCLEO-F767ZI development board for this purpose. For the sake of brevity, we will call it as the STM32 board from this point on. In this section, we will provide general information about the board. We will also provide the pin layout. This will be mandatory to interface the microcontroller with outside world. We will also evaluate methods to program and power the board.
2.1.1 General Information
The STM32 board is as in Figure 2.1. This board has an STM32F767ZI microcontroller on it. Besides, it has three user LEDs, one user push button and one reset push button. It has a 32768?kHz crystal oscillator on it. Board connectors, which lead to access to all microcontroller input and output pins, are compatible with Arduino. The STM32 board has an on-board ST-LINK debugger/programmer with USB connectivity. For more information on the development board, please see https://www.st.com/en/evaluation-tools/nucleo-f767zi.html.
2.1.2 Pin Layout
Pin layout of the STM32 board is as in Figure 2.2. As can be seen in this figure, pins are gathered under four connectors as CN7, CN8, CN9, and CN10. Within each connector, there are input and output pins labeled as PA, PB, PC, PD, PE, PF, PG, and PH. The STM32 board also has two unmounted connecters called CN11 and CN12. We will not explain them here.
Pins on the STM32 board can be used for various purposes. Usage areas of each pin are summarized in Appendix A from this book's perspective. We will explore each property separately in the following sections.
We should also mention the pin connection of onboard green, blue, red LEDs, and push button on the STM32 board. The onboard green LED is connected to pin PB0. The onboard blue LED is connected to pin PB7. The onboard red LED is connected to pin PB14. The onboard user push button is connected to pin PC13. The reader should use the mentioned pins to reach the onboard LEDs and push button in the following chapters.
Figure 2.1 The STM32 board.
(Source: STMicroelectronics. Used with permission.)
Figure 2.2 Pin layout of the STM32 board.
(Source: Nucleo-F767ZI Zio Header, used with permission of STMicroelectronics.)
2.1.3 Powering and Programming the Board
The microcontroller on the STM32 board can be programmed easily by the on-board ST-LINK debugger/programmer. To do so, we should connect the board to PC via USB connection. We will introduce methods to program the microcontroller using this connection in Chapter 3.
The USB connection for debugging/programming purposes can also be used to power the board. Hence, whenever the board is connected to PC, it runs by the provided power. Likewise, we can use a USB battery pack to power the board in the same setup. We can also use an external power supply to power the board. To do so, we should use the relevant pins on the board. These will be sufficient to use the board in stand-alone applications.
The STM32 microcontroller operates within the voltage range of 1.71-3.6 V. We call this value as supply voltage () throughout the book. Let us explain the voltage range in detail. The actual working voltage level for the microcontroller is 3.6 V. This supply voltage may be decreased till 1.7 V for some low power operations. To note here, some peripheral modules will not work at this voltage level.
2.2 The STM32 Microcontroller
As mentioned earlier, the STM32 board is equipped with the STM32F767ZI microcontroller. For the sake of brevity, we will call it as the STM32 microcontroller from this point on. We will evaluate the properties of this microcontroller in this section. Let us start with the functional block diagram of the STM32 microcontroller given in Figure 2.3. As can be seen in this figure, there are several modules in the microcontroller. Besides, interconnection of these modules is complex. However, we will only cover the relevant modules to be used throughout the book here. For more information on other modules of the STM32 microcontroller, please see https://www.st.com/en/microcontrollers-microprocessors/stm32f767zi.html.
2.2.1 Central Processing Unit
Central processing unit (CPU) is the main module responsible for organizing all operations within the microcontroller. This is done by executing the code fed to it. The code can be written in C or MicroPython languages (for this book) with different execution phases. For more information on this topic, please consult a microcontroller book such as (Yiu 2013).
Figure 2.3 Functional block diagram of the STM32 microcontroller.
The CPU in the STM32 microcontroller is based on the Arm Cortex-M7 architecture. Let us explain this in more detail. Arm produces CPU cores in soft form (called as IPs). Microcontroller vendors, such as ST Microelectronics, purchase the right to use these IPs and develop microcontroller hardware. The advantage of this model is as follows. When different vendors use the same CPU core by Arm, they will have the same instruction set and properties. Therefore, the code developed for one microcontroller can be ported to another microcontroller from a different vendor. There is one important issue here. The microcontroller is not only composed of CPU. It also has peripheral units (to be explained next). These may differ for different vendors. Therefore, it may not be possible to directly port the code generated for one microcontroller to another (produced by a different vendor) when peripheral units are used.
Operations within the CPU are done in clock cycles. Before going further, let us first explain what the clock signal means. Clock is a periodic square wave generated by an oscillator. Frequency of the clock signal is measured in Hertz (Hz) which indicates how many periodic pulses occur in one second. The CPU depends on the clock signal. For the STM32 microcontroller, this clock frequency is maximum 216 MHz. The processor performs an action corresponding to an instruction execution phase with each clock cycle. Assuming that an instruction requires four clock cycles to execute, the CPU can process 54000000 instructions per second. Hence, higher the frequency of clock signal, the faster operations are performed within the CPU.
The microcontroller needs a medium to keep the code to be executed and variables to be operated on. The relevant medium in the microcontroller is called memory. Unless the microcontroller is using an additional external memory, the core memory is always on the microcontroller chip.
There are two memory regions on the microcontroller as flash and RAM. Codes to be executed are kept in the flash. As power of the microcontroller is turned down, codes remain there. Therefore, flash resembles the solid-state drive (SSD) on PC. Although the recent SSD storage size for a PC is reasonable, memory space in flash of a microcontroller is very limited. For the STM32 microcontroller, this is 2 MB. Therefore, the user should prepare his or her digital control code such that it does not exceed this limit. Fortunately, most digital control algorithms fit into this space.
The medium for temporary storage in the microcontroller is called RAM. Hence, variables to be executed in the code are kept there. This is similar to the RAM on PC with one difference. The RAM on the microcontroller is very limited in storage size. For the STM32 microcontroller, the RAM size is 512 kB. Therefore, the reader should use this space with care.
2.2.3 Input and Output Ports
A port in the microcontroller mean is a group of pins (or wires). These are used to input data to the microcontroller or output data from the microcontroller. Hence, the microcontroller can interact with the outside world through its input...