This is the most core part of the program in this internship, that is, the control and realization of PWM. First give the initial value of the timer, timing 500 microseconds, is equivalent to the switching frequency of 2000Hz, the timer every 1000 sampling, equivalent to the speed of the sampling cycle of 0.5s. The motor generates 24 pulses in one turn, so the pulse generated by the reading motor in 0.5s divided by 24 and multiplied by 120 is the speed of one minute. This method is the M method to measure the speed. At low speed, the error is relatively large, while at high speed, it is relatively accurate. If a PWM cycle is completed, it will update the value of PWM, which is related to the number of times the acceleration and deceleration buttons are pressed. If the acceleration leads to the duty cycle exceeding 100%, the motor will slow down to 0 and start counting again.