DC motor speed regulation experiment based on 51 single chip microcomputer

Publisher:心灵的旅程Latest update time:2024-08-29 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Experimental Principle

PWM: Pulse Width Modulation. In an inertial system, the required analog quantity can be equivalently obtained by modulating the width of a series of pulses. It is often used for motor speed regulation, light brightness adjustment, etc.


This experiment is essentially the same as the previous LED breathing light (timer implementation) experiment. You can understand and learn from the previous article, so I will not go into details here. (The following figure refers to the LED breathing light experiment)

picture

2. Key Code


void Timer0_Routine() interrupt 1

{

TL0 = 0x66;

TH0 = 0xFF;

Counter++;

Counter%=100; //The count value range is limited to 0~99

if(Counter< Compare) //Count value is less than comparison value

{

Motor=1; //Output 1: Motor rotates (ULN2003 chip is a 7-way inverter circuit, that is, when the input terminal is high level, the output terminal of ULN2003 is low level)

}

else //The count value is greater than the comparison value

{

Motor=0; //output 0, motor stops

}





sbit Motor=P1^0;



unsigned char Counter,Compare; //Count value and comparison value, used to output PWM

unsigned char KeyNum,Speed;

//Main function

void main()

{

Timer0_Init();

while(1)

{

KeyNum=Key();

if(KeyNum==1)

{

Speed++;

Speed%=4;

if(Speed==0){Compare=0;} //Change the comparison value and PWM duty cycle

if(Speed==1){Compare=60;}

if(Speed==2){Compare=75;}

if(Speed==3){Compare=100;}

}

}

}

A PWM wave of a certain period is realized through a timer, and the duty cycle of the high level is changed by changing the comparison value Compare, thereby changing the speed of the motor.


Reference address:DC motor speed regulation experiment based on 51 single chip microcomputer

Previous article:[51 MCU] Matrix keyboard line-by-line scanning simulation experiment + ultra-detailed Proteus simulation and Keil operation steps
Next article:The difference between 89c51 MCU and 89s51 MCU, and the summary of new functions of 89s51 MCU

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号