1. Question requirements
In order to make the ADC knowledge cooperate with other modules to realize different functions, here we plan to control the position of the servo propeller by twisting the potentiometer (sliding resistor). If we twist the potentiometer clockwise, the servo propeller will also rotate from one end to the other.
2.main.c test code
#include #include #include #include #include sbit PWMOUT=P1^7; //Servo signal line interface u8 flag20ms = 0; u8 PWM_VAL = 0; void main() { u8 val; u8 str[10]; EA = 1; InitLcd1602(); //Initialize LCD screen TIM1_Init(20000,6); //Timing 20ms, 6 is fine-tuning to make the timing more accurate TIM0_Init(100,9); //Timing 0.1ms, dedicated to servos, 9 is fine-tuning to make timing more accurate LcdShowStr(6, 0, "AIN0"); while (1) { if (flag20ms) //Get the conversion value of ADC channel 0 every 20ms { flag20ms = 0; val = GetADCValue(0); //Get the conversion value of ADC channel 0 ValueToString(str, val); //Convert voltage value to string format LcdShowStr(6, 1, str); //Display the voltage of channel 0 PWM_VAL=val/14+5; //The value range of PWM_VAL is 5~23 } } } void TIM0_IRQHandler() interrupt 1 { static u8 pwm=0; TH0 = T0RH; //Reload the reload value TL0 = T0RL; pwm++; if(pwm>=200)pwm=0; //pwm changes between 0~199 with an interval of 0.1ms and a period of 20ms if(pwm } void TIM1_IRQHandler() interrupt 3 { TH1 = T1RH; //Reload the reload value TL1 = T1RL; flag20ms = 1; } Let's plug back the jumper caps that we unplugged in the previous chapter to test AD and DA. There is a potentiometer in the middle of the bottom of the development board. You can use a flat-blade screwdriver to rotate the potentiometer and observe that the servo propeller rotates. In addition, it is best to use an external power supply for the servo. Using the development board to power the servo will cause the LCD screen to lose voltage and flicker, and the stability of the servo is not very good. When I tested it, I used another 5V power supply voltage to power the servo. The connection diagram is as follows
Previous article:51 MCU-AD and DA synthesis file
Next article:51 single chip microcomputer - remote control servo
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- Industrial RTU: Remote 4-20mA current acquisition (4G version)
- [Raspberry Pi Pico Review] - AD acquisition example and serial communication
- Please help, PID control implementation of inverter
- (C-Wireless Charging Electric Car) Liaoning Province First Prize_C
- Benefits of Spread Spectrum
- Don’t sell your old phone to buy a new one, learn how to make your own server!
- Can anyone recommend an inexpensive isolation amplifier product, either a chip or a module, with an accuracy of 1% and DC signal sampling?
- Problems with STM32F767 driving Bluetooth module
- Infineon Position2Go Development Kit Review @4. Development
- HFSS Wave Ports and Lumped Ports