Design of forward and reverse rotation based on STM32 control of DC motor acceleration and deceleration (program + simulation + report + explanation)

# This design is based on STM32 control of DC motor acceleration and deceleration forward and reverse design (program + simulation + report + explanation)
Simulation: proteus8.9
Program compiler: keil 5
Programming language: C language
No. C0011

Explanation video:

Function Description:

This design consists of STM32F103, L298N motor drive circuit, and button circuit.
1. The motor can be controlled by pressing the buttons, forward rotation, reverse rotation, acceleration, deceleration, and stop.
2. There are 4 gears, and you can press forward, reverse, accelerate, decelerate and stop in sequence.
3. The gear position can be customized.
Comes with related papers, one is written based on the actual object (basically consistent with the simulation function) and the other is written based on the simulation.

Opening report

Proteus simulation design based on STM32 to control DC motor acceleration, deceleration, forward and reverse rotation

1. Background and objectives of the subject

In the major assignment of this course, we will design a DC motor control system based on STM32 microcontroller. The system will be designed and verified through Proteus simulation software to achieve forward, reverse, acceleration, deceleration and stop control of the motor. The control system will be operated through buttons and has 4-level control functions.

Our goal is to verify the feasibility and effectiveness of the STM32 control system through Proteus simulation design, and deepen the understanding and application of microcontrollers, motor drive circuits and button circuits.

2. Research methods

We will use a method that combines theoretical analysis and simulation verification, first design the circuit through Proteus software, and then implement the required functions through programming control. Specific steps are as follows:

Design the circuit in Proteus: including STM32F103 microcontroller, L298N motor drive circuit and button circuit.
Write a program: Use C language to write a program and control the forward, reverse, acceleration, deceleration and stop of the motor through the GPIO port of the microcontroller.
Simulation test: Run the program in Proteus and test the control function of the motor through key operations.
3. Expected results

We expect that through the above research methods, we can achieve the following expected results:

The forward, reverse, acceleration, deceleration and stop control of the motor can be realized through buttons.
It has a 4-speed control function, which can realize the control cycle of forward rotation, reverse rotation, acceleration, deceleration and stop through the key sequence.
Verify the feasibility and effectiveness of the STM32 control system through Proteus simulation.
4. Experimental Arrangement

We estimate that it will take one month to complete the major assignments for this course. The first two weeks will be mainly used for circuit design and programming, the third week will be used for simulation testing, and the fourth week will be used for result analysis and report writing.

5. Experimental materials and methods

Experimental materials include:

STM32F103 microcontroller
L298N motor drive circuit
key circuit
Proteus simulation software
experimental methods include:

Design circuit,
write program,
simulate test
6. Experimental steps and data recording

The experimental steps are as follows:

Design the circuit in Proteus.
Use C language to write programs.
Run the program in Proteus.
Test the control function of the motor through key operations.
Record experimental data.
Analyze the experimental results.
Writing reports.
Data records include:

Key operation record: record the time, sequence and result of key operation.
Motor status recording: Record the status changes of the motor, including forward rotation, reverse rotation, acceleration, deceleration and stop.
Proteus simulation result recording: records the results of the simulation test, including the status of the motor and changes in control signals.
7. Experimental conclusion and discussion

After the experiment, we will analyze and discuss the experimental data and results to draw experimental conclusions. Possible conclusions include:

Successfully realize the forward, reverse, acceleration, deceleration and stop control of the motor.
Successfully realized the 4-speed control function.
The feasibility and effectiveness of the STM32 control system were verified through Proteus simulation.
The experimental discussion will include an analysis of the problems and difficulties encountered during the experiment, as well as directions and suggestions for future improvements.

Simulation diagram (source file provided):

New simulation 1

New simulation inversion

New simulation real transfer

3.1 System functional analysis and architecture design
3.1.1 System functional analysis
This design consists of STM32F103R6 microcontroller core board circuit + L298N motor drive circuit + button circuit + power supply circuit.
1. The motor can be controlled by pressing the buttons, including forward rotation, reverse rotation, acceleration, deceleration and stop. There are 8 gears.
2. Press the keys in sequence to rotate forward, reverse, accelerate, decelerate, and stop.
3.1.2 Overall system structure

3.2 Module circuit design
3.2.1 STM32 microcontroller core circuit design
The STM32 series processor is a 32-bit microcontroller based on the ARM 7 architecture produced by STMicroelectronics that supports real-time simulation and tracking. This control chip was chosen because this system design is not pursuing the lowest cost or smaller power consumption, but on the premise of realizing the design functions, it can provide richer interfaces and functions to facilitate the design of the experimental system required by each experimental project. peripheral expansion circuit. This control chip is relatively easy to get started after completing the microcontroller course. It is widely used in medical devices and has good learning and experimental research value.
1. The main advantages of STM32:
(1) Using ARM’s latest and advanced architecture Cortex-M3 core
(2) Excellent real-time performance
(3) Outstanding power consumption control
(4) Outstanding and innovative peripherals
(5) Max. Degree of integration
(6) Easy to develop, allowing products to enter the market quickly
2. STM32 - the best platform option
STM32 is the best choice for using the same platform for multiple project development:
(1) From From applications that require only a small amount of memory and pins to applications that require more memory and pins
(2) From performance-demanding applications to battery-powered applications
(3) From simple and cost-sensitive applications to high-end applications
(4 ) The full range of pin-to-pin, peripheral and software compatibility brings you all-round flexibility. You can upgrade your application to a specification that requires more storage space or streamline it to use less storage space/or switch to a different package without having to modify your original framework and software.
The interface circuit diagram of the STM32F103C8T6 microcontroller core board is shown in the figure below.

3.2.2 L298N motor drive module circuit design
This L298N drive module uses ST’s L298N chip. L298N is a dual H-bridge motor drive chip. Each H-bridge can provide a current of 2A. The power supply voltage range of the power part is 2.5-48v, the logic part is powered by 5v and accepts 5vTTL level. This module can directly drive two 3-30V DC motors, and provides a 5V output interface, which can power the 5V microcontroller circuit system and conveniently control the speed and direction of the DC motor.
1. Product parameters:
(1) Driver chip: L298N dual H-bridge driver chip
(2) With diode freewheeling protection
(3) DC motor speed can be controlled by PWM
(4) Drive part terminal power supply range VMS: +5V~ +35V
(5) Drive part peak current Io: 2A/bridge
(6) Logic part terminal power supply range Vss: 4.5-5.5V
(7) Logic part operating current range: 0~36mA
(8) Control signal input voltage range: high voltage Flat 4.5-5.5V Low level 0V
(9) Maximum power consumption: 20W
(10) Storage temperature: -25℃~+130℃
2. Precautions for using the motor drive module
(1) Observe the green power indicator when powering on for the first time Check whether the lamp L5 is on. If not, please cut off the power immediately and check whether the power supply is connected reversely.
(2) The driver is a power device, so please maintain heat dissipation and ventilation in the working environment; after connecting the motor, let it work continuously for a period of time and observe that the temperature rise of the motor and driver chip is normal before subsequent use.
3. Motor drive module interface description:
(1) Motor drive power input interface: VMS is connected to the positive pole, GND is connected to the negative pole
(2) Interface between driver and control port: When controlling a DC motor, IN1, IN2 and ENA are a group. They control motor A and are connected to A+ and A-. If motor A is not controlled, ENA can be left floating; if motor A Control, then ENA is connected to a PWM output. IN3, IN4 and ENB are a group. They control motor B and are connected to B+ and B-. If motor B is not controlled, ENB can be left floating; if motor B is controlled, ENB is connected to a PWM output.
4. DC motor control signal truth table
Taking motor A as an example, high level H: low level: L
input signal function:
IN1=H; IN2=L: motor A rotates forward
IN1=L; IN2=H: motor A reverse
ENA=H; IN1=IN2: Motor A emergency stop
ENA=L; IN1=X; IN2=X: Any level motor A coasts to a stop.
The L298 motor drive module has stable and reliable performance and meets the design requirements. The module interface diagram is shown in the figure below.
Insert image description here

L298N motor drive module interface diagram
The internal circuit schematic diagram of the L298N motor drive module is shown in the figure below. P1 is the main power input, GND and 5V DC power output interface. The total power supply reduces the high voltage to 5V through the L7805CV voltage stabilizing chip. L7805CV is a positive voltage regulator with an output voltage of 4.75-5.25V, a maximum input voltage of 35V, a maximum output current of 1.5A, and a quiescent current of 4.2-8mA. C1-C4 all play a filtering role to make the voltage more stable. P3 and P4 are motor interfaces. Diodes D1-D8 play a protective role to prevent the reverse induced electromotive force generated by the motor from damaging the L298N. P2 is the control pin, D9-D13 are signal indicators, and the relevant resistors play a current limiting role to protect the LED lights.

Source program (source files provided):

char dis0[6] = "Dir:+";   //暂存
char dis1[6] = "Dir:-";   //暂存
char dis2[16] = "";   //暂?
char dis3[] = "RUN ";   //暂存?
char dis4[] = "STOP";   //暂存
unsigned  char rekey = 0; //按键防止抖动
unsigned char contNum = 0; //循环计数
int main(void)
{
    
    
  
    delay_init();            //延时函数初始化
  
//    uart_init(9600);        //串口初始化为115200
    //  uart2_init(9600)    ;
    TIM3_Int_Init(10, 7199); //定时器
    LED_Init();             //初始化与LED连接的硬件接口
    KEY_Init();
    Lcd_GPIO_init();
    Lcd_Init();
    IN1 = 1;        //方向控制
    IN2 = 0;
    pwmRigh = 0;    //pwm调整,电机转速调整

    Lcd_Puts(0, 0, (unsigned char *)dis0);
    sprintf(dis2,"SPEED:%d",pwmRigh);
    Lcd_Puts(0, 1, (unsigned char *)dis2);
     Lcd_Puts(8, 0, (unsigned char *)dis3);

    while(1)
    {
    
    
        if((key1 == 0) || (key2 == 0) || (key3 == 0) || (key4 == 0) || (key5 == 0))      //检测到按键按下
        {
    
    
//            delay_ms(1);   //小抖动仿真不需要加
            if(rekey == 0)
            {
    
    
                if(key1 == 0)  //检测是否按下
                {
    
    

                    rekey = 1;
                    IN1 = 1;        //方向控制
                    IN2 = 0;                   
                    Lcd_Puts(0, 0, (unsigned char *)dis0);
                     Lcd_Puts(8, 0, (unsigned char *)dis3);
                }
                else if(key2 == 0) //设置值键
                {
    
    
                    rekey = 1;
                    IN1 = 0;        //方向控制
                    IN2 = 1;
                    Lcd_Puts(0, 0, (unsigned char *)dis1);
                     Lcd_Puts(8, 0, (unsigned char *)dis3);
                }
                else if(key3 == 0) //设置值键
                {
    
    
                    rekey = 1;
                    if(pwmRigh < 8)pwmRigh = pwmRigh + 2; //pwm 调速
                    sprintf(dis2,"SPEED:%d",pwmRigh/2);
                    Lcd_Puts(0, 1, (unsigned char *)dis2);
                }
                else if(key4 == 0) //设置值键
                {
    
    
                    rekey = 1;
                    if(pwmRigh >= 2)pwmRigh = pwmRigh - 1; //pwm 调速
                    sprintf(dis2,"SPEED:%d",pwmRigh/2);
                    Lcd_Puts(0, 1, (unsigned char *)dis2);
                }
                else if(key5 == 0) //设置值键
                {
    
    
                    rekey = 1;
                    IN1 = 0;        //方向控制
                    IN2 = 0;
                    Lcd_Puts(8, 0, (unsigned char *)dis4);
                }
            }
        }
        else
        {
    
    
            rekey = 0;  //防止重复检测到按键
        }
        delay_ms(10);
    }
}

Insert image description here

The following is part of the program. The complete program is available at the download link:

Thesis report:

Papers related to physical objects:

Insert image description here

Simulation related papers:
Chapter 1 Introduction
1.1 Background of the topic and its significance
DC motor has good starting and braking performance, can be used for smooth control in a wide range, and can also be widely used in many applications that require control or forward and reverse. In the field of electric drag. From a control perspective, DC control is the foundation of the AC drive system. Most of the early control systems were based on analog circuits, including operational amplifiers, nonlinear integrated circuits and a small number of digital circuits. The hardware part of the control system was relatively complex and simple in function, and the software system was inflexible and difficult to debug. It is not conducive to the development and application scope of DC motor control technology. With the rapid development of microcontroller control technology, many control function algorithms and software have been completed, providing greater development space for DC motor control and enabling the system to achieve higher performance. Using a single-chip microcomputer to form a control system can save human resources and reduce system costs, thereby effectively improving work efficiency.
The traditional control system uses analog components. Although it meets the production requirements, the operational reliability of the system is compromised because the components are prone to aging and are easily affected by interference during use, and the circuits are complex. The control effect is affected by factors such as device performance and temperature. And accuracy cannot be guaranteed, and accidents may even occur.
At present, the digitalization of DC motor control systems has become practical. With the rapid development of electronic technology, DC motor control has gradually transformed from analog to digital. In particular, the application of single-chip microcomputer technology has brought DC motor control technology into a new era. stage, intelligence and high reliability have become its development trends. Therefore, realizing DC stepless control is of great significance to our social production and life.
1.2 Research status at home and abroad
DC motors have good starting and braking performance and are suitable for smooth control over a wide range. They have been widely used in many electric drive fields that require control or fast forward and reverse directions. From a control point of view, DC control is also the basis of AC drive systems. The control of early DC motors was based on analog circuits, using operational amplifiers, nonlinear integrated circuits and a small number of digital circuits. The hardware part of the control system was very complex and had a single function. The system was also very inflexible and difficult to debug, which hindered the development of DC motors. Development of motor control technology and promotion of application scope. With the rapid development of microcontroller technology, many control functions and algorithms can be completed using software technology, providing greater flexibility for DC motor control and enabling the system to achieve higher performance. Using a single-chip microcomputer to form a control system can save human resources and reduce system costs, thereby effectively improving work efficiency.
In practical applications, as the main equipment for converting electrical energy into mechanical energy, electric motors must have high energy conversion efficiency; secondly, they should be able to adjust the rotational speed according to the requirements of the production process. The control performance of the motor has a direct and decisive impact on improving product quality, improving labor productivity and saving electric energy. Therefore, control technology has always been a hot research topic.
DC motors have been widely used in metallurgy, mining, chemical industry, transportation, machinery, textile, aviation and other fields. In the past, the control of DC motors was only simple control, which was difficult to control and could not be intelligent. Traditional control systems use analog components, which meet production requirements to a certain extent. However, because the components are prone to aging and are easily affected by external interference during use, and the circuits are complex and have poor versatility, the control effect is affected by factors such as device performance and temperature. Therefore, the operational reliability and accuracy of the system cannot be guaranteed, and accidents may even occur. Today, the control of DC motors is inseparable from the support of single-chip microcomputer. The rapid development of single-chip microcomputer application technology has promoted the development of automatic control technology, bringing human society into the era of automation. The cross-integration of single-chip microcomputer application technology and other subject areas has promoted Discipline development and professional renewal have triggered the continuous emergence of new interdisciplinary disciplines and technologies. The rapid development of modern science and technology has changed the world and human life. Due to the characteristics of microcontrollers such as small size, light weight, strong functions, strong anti-interference ability, flexible control, convenient application, and low price, computer performance continues to improve, and the application of microcontrollers has become more extensive, especially in control and automation in various fields. etc.
At present, the digitalization of DC motor control systems has become practical. With the rapid development of electronic technology, DC motor control has gradually transformed from analog to digital. In particular, the application of single-chip microcomputer technology has brought DC motor control technology into a new era. stage, intelligence and high reliability have become its development trends.
In recent years, with the advancement of science and technology, power electronics technology has developed rapidly, and DC motors have been used more and more widely. DC has excellent control characteristics, smooth and convenient control, wide control range; large overload capacity, can withstand frequent impact loads, and can achieve frequent stepless rapid starting, braking and reversal.
1.3 The main research content and structure of this article
Chapter 1. Mainly introduces the subject background of this design and domestic and foreign research status;
Chapter 2. Mainly explains the selection of system solutions;
Chapter 3. Mainly introduces the composition and use of hardware circuits Method;
Chapter 4. Mainly introduces software design;
Chapter 5. Mainly introduces hardware debugging;
Simulation related reports

The information list is as follows:

0. Common usage problems and solutions – a must-read! ! ! !
1. Source program
2. Simulation
3. Thesis report
4. Explanation video
5. Functional requirements
Altium Designer software information
KEIL software information
L298N detailed information.doc
Proteus software information
MCU learning
materials Table of contents.txt
defense skills
Common descriptions of design reports
double-click the mouse Open to find more 51 STM32 microcontroller course graduation project.url

Information Baidu network disk download link

Guess you like

Origin blog.csdn.net/weixin_52733843/article/details/131886935