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)
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.
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
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Another technical solution for power-type plug-in hybrid: A brief discussion on Volvo T8 plug-in hybrid technology
- A Rapid Design Method for Monolithic Switching Power Supply
- 5V60A PWM half-bridge switching power supply
- tpms Infineon solution source code
- LTspice .subckt(3) reverse drawing
- TI blog post: Buck-boost DCDC TPS63810 in TWS headphones
- Pre-registration for the live broadcast with prizes | Detailed explanation of NXP's embedded human-machine interface solutions
- Namisoft about virtual voltmeter design and virtual digital multimeter
- I didn’t go out in the spring because of the epidemic. Here is a guide to climbing Huashan Mountain - the first day of climbing in 2020
- USB5537B, does not start after first power on, but restarts normally after power off
- Couldn't find an AF_INET address for