Hello everyone, I am tahir ul haq from another project. This time it was the time to do MC that was used by 2017-11-407. This is the end of the mid-term program. Hope you like it. It requires a lot of concepts and theories, so let\'s look at it first. With the emergence of computers and the industrialized process, there has been research in the history of human beings to develop methods to redefine the process, and more importantly, to use machines to control the process autonomously. The aim is to reduce human participation in these processes, thus reducing errors in these processes. Therefore, the field of \"control system engineering\" came into being. Control system engineering can be defined as the use of various methods to control the work of the process or the maintenance of a constant and preferred environment, whether manual or automatic. A simple example is to control the temperature of the room. Manual control refers to the presence of a person who checks the current conditions on site (sensor) , With expectations (processing) And take appropriate action to obtain the desired value (actuator). The problem with this approach is that it is not very reliable because one is prone to error or negligence at work. In addition, another problem is that the rate of the process the actuator starts is not always uniform, which means that sometimes it may be faster than the required speed, and sometimes it may be slow. The solution to this problem is to use a micro-controller to control the system. According to the given specification, the micro-controller is programmed to control the process of connecting in the circuit ( Discuss later) The value or condition of, thereby controlling the process to maintain the desired value. The benefit of this process is that there is no need for human intervention in this process. In addition, the speed of this process is consistent. Before we proceed, it is crucial to determine the various terms at this point: Feedback control: In this system, input at a certain time depends on one or more variables, including the output of the system. Negative feedback: In this system, reference (input) As feedback, the error is subtracted and the phase of the input is 180 degrees. Positive feedback: In this system, reference (input) Errors are added when feedback and input are in phase. Error signal: the difference between the desired output and the actual output. Sensor: a device used to detect a certain number of devices in a circuit. It is usually placed in the output or anywhere we want to make some measurements. Processor: part of the control system that is processed based on programming algorithms. It takes some input and produces some output. Actuator: in the control system, the actuator is used to perform events based on the signal generated by the micro-controller to affect the output. Closed-loop system: a system with one or more feedback loops. Open loop system: there is no system for feedback loop. Rise Time: The time required for the output to rise from 10% of the maximum amplitude of the signal to 90%. Drop Time: The time required for the output to drop from 90% to 10%. Peak overshooting: peak overshooting is the amount of output exceeding its steady state value ( Normal during system transient response). Stable Time: The time required for the output to reach a stable state. Steady-state error: the difference between the actual output and the expected output once the system reaches steady-state. The picture above shows a very simplified version of the control system. The micro-controller is the core of any control system. This is a very important component, so it should be carefully selected according to the requirements of the system. The micro-controller receives input from the user. This input defines the conditions required for the system. The micro-controller also receives input from the sensor. The sensor is connected to the output and its information is fed back to the input. This input can also be called negative feedback. Negative feedback was explained earlier. Based on its programming, the microprocessor performs various calculations and outputs to the actuator. The output-based actuator control plant attempts to maintain these conditions. An example may be the motor driver driving the motor, where the motor driver is the driver and the motor is the factory. Therefore, the motor rotates at a given speed. The connected sensor reads the status of the current factory and feeds it back to the micro controller. The micro-controller is compared again and calculated, so the loop is repeated. The process is repetitive and endless, and the micro-controller can maintain the desired conditions. Here are two main ways to control the speed of the DC motor) Manual Voltage control: in industrial applications, the speed control mechanism of the DC motor is critical. Sometimes we may need speeds that are higher or lower than normal. Therefore, we need an effective speed control method. Controlling the supply voltage is one of the simplest speed control methods. We can change the voltage to change the speed. b) Control PWM using PID: another more efficient way is to use a micro-controller. The DC motor is connected to the micro controller through the motor driver. The motor driver is an IC receiving PWM ( Pulse width modulation) Input from the micro controller and output to the DC motor according to the input. Figure 1. 2: Chapter 1 of PWM signal. Introduction 3 considering the PWM signal, the operation of PWM can be explained first. It consists of continuous pulses for a certain period of time. Time period is the time spent by a point moving at a distance equal to a wavelength. These pulses can only have binary values (HIGH or LOW). We also have two other quantities, the pulse width and the duty cycle. The pulse width is the time when the PWM output is high. The duty cycle is the percentage of the pulse width to the time period. For the rest of the time period, the output is low. The duty cycle directly controls the speed of the motor. If the DC motor provides positive voltage within a certain period of time, it will move at a certain speed. If positive voltage is provided for a longer period of time, the speed will be greater. Therefore, the duty cycle of PWM can be changed by changing the pulse width. By changing the duty cycle of the DC motor, the speed of the motor can be changed. Speed control for DC motor problems: the problem with the first speed control method is that the voltage may change over time. These changes mean uneven speed. Therefore, the first method is undesirable. Solution: We use the second method to control the speed. We use the PID algorithm to supplement the second method. PID represents the proportional integral derivative. In the PID algorithm, the current speed of the motor is measured and compared with the desired speed. This error is used for complex calculations to change the duty cycle of the motor according to time. There is this process in each cycle. If the speed exceeds the desired speed, the duty cycle is reduced and the duty cycle increases if the speed is lower than the desired speed. This adjustment is not made until the best speed is reached. Constantly check and control this speed. Here are the system components used in this project and a brief introduction to the details of each component. STM 32F407: micro-controller designed by ST Micro-section. It works on the ARM Cortex. M Architecture. It leads its family with a high clock frequency of 168 MHz. Motor driver L298N: This IC is used to run the motor. It has two external inputs. One from the micro controller. The micro-controller provides a PWM signal for it. The motor speed can be adjusted by adjusting the pulse width. Its second input is the voltage source needed to drive the motor. DC Motor: The DC motor runs on the DC power supply. In this experiment, the DC motor is operated using a photoelectric coupling connected to the motor driver. Infrared Sensor: the infrared sensor is actually an infrared transceiver. It sends and receives infrared waves that can be used to perform various tasks. IR encoder optical coupler 4N35: optical coupler is a device used to isolate the low voltage part of the circuit and the high voltage part. As the name implies, it works on the basis of light. When the low voltage part gets the signal, the current flows in the high voltage part. The system is a speed control system. As mentioned earlier, the system is implemented using PID of proportional integral and derivative. The speed control system has the above components. The first part is the speed sensor. The speed sensor is an infrared transmitter and receiver circuit. When the solid passes through the u-shaped slit, the sensor enters a low state. Normally it is in a high state. The sensor output is connected to a low-pass filter to eliminate the attenuation caused by the transient generated when the state of the sensor changes. The low-pass filter consists of resistors and capacitors. Values were selected as required. The capacitor used is 1100nf and the resistance used is about 25 ohms. The low-pass filter eliminates unnecessary transient conditions that may result in additional readings and garbage values. The low-pass filter is then output through the capacitor to the input digital pin of the stm micro-controller. The other part is the motor controlled by pwm provided by stm micro-controller. This setting has been provided with electrical isolation using the optical coupler ic. The optical coupler includes an led that emits light within the ic package, and when a high pulse is given at the input terminal, it short-circuited the output terminal. The input terminal gives pwm through a resistor that limits the current of the led connected to the optical coupler. A drop-down resistor is connected at the output so that when the terminal is short-circuited, the voltage is generated at the drop-down resistor and the pin connected to the terminal on the resistor receives a high state. The output of the photoelectric coupler is connected to the IN1 of the motor driver ic that maintains the height of the enable pin. When the pwm duty cycle changes at the optical coupler input, the motor driver pin switches the motor and controls the speed of the motor. After the pwm provided to the motor, the motor driver usually provides a voltage of 12 volts. The motor driver then enables the motor to operate. Let\'s introduce the algorithm we used in the implementation of this motor speed regulation project. The pwm of the motor is provided by a single timer. The configuration of the timer is made and set to provide pwm. When the motor starts, it rotates the slit attached to the motor shaft. The slit passes through the sensor cavity and produces a low pulse. At low pulses, the code starts and waits for the slit to move. Once the slit disappears, the sensor provides a high state and the timer starts counting. The timer gives us the time between the two slit. Now, when another low pulse appears, the IF statement executes again, waiting for the next rising edge and stopping the counter. After calculating the speed, calculate the difference between the speed and the actual reference value and give the pid. Pid calculates the duty cycle value that reaches the reference value at a given moment. This value is provided to CCR ( Comparison register) Depending on the error, the speed of the timer is reduced or increased. The Atollic Truestudio code has been implemented. STM studio may need to be installed for debugging. Import the project in STM studio and import the variables you want to view. The slight change is on the 2017-11-4xx. Change the clock frequency precisely to an h file at 168 MHz. The code snippet has been provided above. The conclusion is that the speed of the motor is controlled using PID. However, the curve is not exactly a smooth line. There are many reasons for this: although the sensor connected to the low-pass filter still provides certain defects, these are due to some unavoidable reasons for nonlinear resistors and analog electronic devices, the motor cannot rotate smoothly at small voltage or pwm. It provides assholes that may cause the system to enter some wrong value. Due to jitter, the sensor may miss some slit that provides a higher value, and the main reason for another error may be the core clock frequency of the stm. The core clock of Stm is 168 MHz. Although this problem was addressed in this project, there is a holistic concept of this model that does not provide such a high frequency. The open loop speed provides a very smooth line with only a few unexpected values. The PID is also working and provides very low motor stability time. The motor PID was tested at various voltages that kept the reference speed constant. The voltage change does not change the speed of the motor, indicating that the PID is working. Here are some segments of the final output of the PID. a) Closed loop @ 110 rpmb) Closed loop @ 120 rpmThis project could not be completed without the help of my group members. I want to thank them. Thank you for watching this project. Hope to help you. Please look forward to more. Keep blessing before that :)