Design of PWM control system for DC motor based on microcontroller

[Resource download] The download address is as follows:
https://docs.qq.com/doc/DTlRSd01BZXNpRUxl

The main functions of the DC motor PWM control system include: to realize the acceleration and deceleration of the DC motor, as well as the forward rotation, reverse rotation and emergency stop of the motor, and the speed of the motor can be adjusted, which can easily realize the intelligent control of the motor.

Main circuit: the DC motor PWM control module. This part of the circuit mainly controls the acceleration and deceleration of the DC motor and the forward and reverse rotation of the DC motor by the I/O port, timing counter, and external interrupt expansion of the AT89S52 single-chip microcomputer, and can adjust the speed of the motor. intelligent control. In the meantime, the pulse signal with adjustable pulse width is generated by the AT89S52 microcontroller and input to the L298 driver chip to control the operation of the DC motor. The DC motor PWM control system consists of the following circuit modules:

Design input part: This module mainly uses the independent keyboard with interruption to realize the acceleration and deceleration of the DC motor, as well as the forward rotation, reverse rotation and emergency stop control of the motor.

Design control part: It is mainly composed of external interrupt expansion circuit of AT89S52 microcontroller. The DC motor PWM control implementation part is mainly composed of some diodes, motors and L298 DC motor drive module.

Design the display part: The LED digital display part realizes the real-time display of the duty cycle of the PWM pulse width modulation.

#include<reg52.h>    
#include<intrins.h>                        
#define uchar unsigned char	
#define uint unsigned int 
		
/**********************************************************************
							L298n接口定义
**********************************************************************/  
sbit MOTOR_A_1=P3^6;
sbit MOTOR_A_2=P3^7;																   
sbit k1=P1^0;		//定义k1为p1.0口
sbit k2=P1^1;   //定义k2为p1.1口
sbit k3=P1^2;   //定义k3为p1.2口
sbit k4=P1^3;   //定义k4为p1.3口
uchar T=0;	   //定时标记
uchar W=0;	   //脉宽值	 0~100
uchar A=0;	   //方向标记 0,1
uchar k=0;	   //按键标记
uchar i=0;    	 //计数变量

uchar code table1[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};

uchar code table2[]={0xfe,0xfb,0xfd,0xf7};
		 
void delayms(uint t);					 			 
/**********************************************************************
						数码管显示
**********************************************************************/ 
void disp(void)
{
	P2=table2[3];					
	P0=table1[W%10];			//显示占空比个位
	delayms(1); 					//延时1ms
	P2=0xff;							//P0清1

	P2=table2[2];
	P0=table1[W/100]; 		//显示占空比百位
	delayms(1); 					//延时1ms
	P2=0xff;							//P0清1
  
	P2=table2[1];
	P0=table1[W/10%10];  //显示占空比十位
	delayms(1); 				 //延时1ms
	P2=0xff;   					 //P0清1

 

Guess you like

Origin blog.csdn.net/AuroraFaye/article/details/115052963