<> Description of duty cycle

You can think of it as the percentage of high and low level in the total cycle . That is to say, the percentage of the time that the circuit is connected to the whole circuit working cycle .

<> Design ideas

Let's define an initial duty cycle , Then when the acceleration pin signal changes , The value of the duty cycle will increase , On the contrary, it decreases . By changing the proportion of the high level , Adjust the output of the motor , In order to achieve a change in speed

<> Description of timer

Insert the code fragment here #include<reg51.h> #define uint unsigned int #define uchar unsigned
char uchar time; double count=50; // Define duty cycle , And the initial duty cycle is 50% sbit PWM=P2^0;
//P2^0 Mouth output PWM sbit key_add=P3^4; // Key for motor acceleration Of I/O mouth sbit key_dec=P3^5; // Button for motor deceleration
Of I/O mouth void delayxms(uint z); // delayed void dianji_add(); // Motor acceleration , That is to increase the duty cycle void
dianji_dec(); // Motor deceleration , That is to reduce the duty cycle void chenglu_init(); // timer 0 initialization void main() {
chenglu_init(); delayxms(5); while(1) { dianji_add(); dianji_dec(); } } void
delayxms(uint z) // delayed xms program { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); }
void dianji_add() // Motor acceleration { if(key_add==0) { delayxms(2); // It can't be too long here , Otherwise, there will be a conflict
if(key_add==0) { count+=5; // Each time the acceleration button is pressed, the duty cycle is increased 5 if(count>=80) // Limit duty cycle upper limit { count=80;
} } while(!key_add); } } void dianji_dec()// Motor deceleration { if(key_dec==0) {
delayxms(2); if(key_dec==0) { count-=5; // Each time the deceleration button is pressed, the duty cycle is reduced 5 if(count<=20) // Limit duty cycle lower limit
{ count=20; } } while(!key_dec); } } void chenglu_init() { TMOD=0x01;
// timer 0 Working in the way 1 TH0=(65536-10)/256; TL0=(65536-10)%256; TR0=1; ET0=1; EA=1; } void
chenglu_int() interrupt 1 { TR0=0; // Set timer initial value period , off timer TH0=(65536-10)/256;
TL0=(65536-10)%256; TR0=1; time++; if(time<count) //count Is the duty cycle { PWM=1; // Output high level
} else PWM=0; if(time>=100) { time=0; } }```

©2019-2020 Toolsou All rights reserved,
One is called “ Asking for the train ” A small village Finally got the train Spring Boot Lesson 16 :SpringBoot Implementation of multithreading with injection class Chrome OS, For programmers and Windows What does it mean ? Internet Marketing JAVA Convert a string to a numeric type I've been drinking soft water for three years ? What is the use of soft water and water softener You don't know ——HarmonyOS Talking about uni-app Page value transfer problem JavaScript Medium Call and ApplySparkSQL Achieve partition overlay write Character recognition technology of vehicle license plate based on Neural Network