Use the hc89s003f4 microcontroller to create a 16-channel servo controller controlled by serial port commands. It will only be applicable to digital servos; Program function description: 1. After the serial port receives the end: 0x66, the program starts to receive 16 bits representing servos 1-16 The open and close flag; 2.16-bit open and close flag: 1 is open, 0 is closed. For example: 0xB6 0x49 is received, and the binary transposition is 1011 0110 0100 1001, which means 1 is on, 2 is off, 3 is on, 4 is on, 5 is off, 6 is on, 7 is on, 8 is off, 9 is off, 10 is on, 11 is off, 12 is off, 13 is on, 14 is off, 15 Turn off 16 and turn on; 3. After receiving the 16-bit on and off flags, start to receive 16 8-bit angle data, with 0x00 representing 0 degrees, 0xb4 with a meter of 180 degrees, pwm1 angle data is sent to the control panel first, and pwm16 angle is sent to the control panel last. ;
4. After receiving the angle data, send it to the tail: 0x99 to update the servo angle;
5. OLED displays the angle and output status of each channel.
Special note:
This program version uses a microcontroller with a 12-bit PWM pulse width modulator. Because there are only three 12-bit pulse width modulators, it can only control 6 pulse widths at a time. The 16 pulse width outputs are completed in three times. Each time It only outputs 20 cycles at a time.
It takes 50Hzpwm to control the servo, 0.02 20 3=1.2s, which means it takes at least 1.2s to complete a 16-channel output. It feels like a long time, but it takes 20 seconds for the servo to turn from 0 degrees to 180 degrees. cycles to ensure completion. In fact,
you can reduce the number of cycles sent each time and send 0x99 a few more times to refresh the pwm output to improve real-time performance! This is a good idea. Well, I’ll try it after I finish writing the instructions.
* Correction : The duty cycle for controlling the 300Hz digital servo has been wrong before, resulting in the inability to use 300Hz. Now after the correction, it only takes two cycles and a total of six cycles to complete the angle control of the servo and refresh the angle of the servo. The frequency is increased to 50Hz , that is, * 0.02s * can be refreshed once. Of course, this is only a theoretical refresh speed. In fact, it still takes a certain amount of time for the servo to run to the specified angle, up to 1s. *
As mentioned earlier, only six pwm outputs can be controlled at a time. To control 16 pwm, there is naturally a priority, so I added an external priority input function. To use this function, just replace the header: 0x66 with 0x67, in ' 16-bit on and off flags are inserted into 16 8-bit priority data after sending (including four states of 0x00, 0x01, 0x02, and 0x03, 0x00 means not turned on, the rest means turned on, 0x01 has the highest priority, 0x03 has the lowest priority), The program will determine whether more than two pins controlled by the same channel of the same PWM pulse width modulator are used at the same priority level. If found, the priority will be re-planned according to the '16-bit on and off flag' sent previously. Circuit part: The circuit part is relatively simple. All available IO ports of the microcontroller are led out. 16 pins control the pwm, 2 are used for serial communication, and the JTAG debugging port is led out. The 16 pwm output pins are isolated from the outside with 74hc245, and the 74hc245 output pin Both pull down. Two of the 16 pins are reused as IIC to control the oled. The serial port lead-out line sequence is the common hc-05 Bluetooth module line sequence, which facilitates Bluetooth wireless control. The picture of the driver board is shown below.
The environment is a bit dark, but I think this little guy is quite beautiful. Log 1: The program has modified the known errors. It is unknown whether it can run. I will go to the laboratory for debugging tomorrow. No display program has been added yet. 2019-9-19; Log 2: Program debugging completed, driver board will be drawn tomorrow. 2019-9-20; Log 3: There is a bug in the compiler. After changing the input data format, the program can finally run successfully on the development board. 2019-9-26; Log 4: Today I started talking about the circuit board and completed the schematic part. 2019-9-27; Log 5: Finished drawing the pcb today. 2019-9-28; Log 6: Upload timer version. 2019-9-30; Log 7: The timer version cannot run perfectly and normally, and those who are interested can modify it by themselves. Re-upload the pwm modulator version, modify the known bugs, change it to intermittent loop output, change the frequency to 300Hz, and send the latest command every 63ms. Successfully ran on the proofing board. 2019-10-12;
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet