1. Hardware
PCA9685 is a chip with 12-bit precision and 16-channel PWM wave output based on IIC bus communication. When the chip was first launched by NXP, it was mainly used for LED switch dimming. However, judging from the current domestic situation, it seems to be more widely used by Arduino in the field of steering gear control.
Since this module is mainly active around Aruino, it is very perfect to develop its underlying driver library using Arduino, but it is not very friendly to microcontroller developers. They need to write the underlying driver on the microcontroller according to the user manual.
The allocation of its address is determined by the short-circuit pad on the upper right of the module. From A0-A5, it represents the lowest bit to the highest bit of the address, that is, up to 2^5=32 modules can be cascaded, and the address is: 1+A5+A4+A3+A2+A1+A0+rw. If no short circuit is needed, Ax=0; if short circuit is done, Ax=1; if rw is for writing, rw=0; if rw is for reading, rw=1; so if writing data without short circuit, the address should be 1000 0000 =0x80. Many people, including Taobao merchants, mistakenly believe that the default address is 0x40, which is a rip-off.
2.IIC communication
SCL is connected to PH4, SDA is connected to PH5, VCC is connected to 3.3V, GND is connected, and V+ is simply for power supply. It is not connected when driving a high-power servo. However, the two ports of the external power supply must be connected to the positive and negative poles, otherwise it cannot supply power.
3. Procedure
First, we need the underlying driver file for IIC communication and the driver file for pca9685. The driver for pca9685 can be modified based on the driver file for pcf8574. The key lies in the following two functions:
void setPWM(u8 num, u16 on, u16 off)
void setPWMFreq(u8 freq)
Note that u8 is used instead of unsigned int.
There is one thing to note:
IIC_Send_Byte(PCA9685_adrr|0X01); //Send device address + read command
This is the r/w mentioned above. Since this is the read address, it must be 0X01.
In the main function:
PCA9685_write(PCA9685_MODE1,0x0);
setPWMFreq(50);
setPWM(0, 0, 220);
delay_ms(2000);
setPWM(2, 0,110);
delay_ms(2000);
setPWM(1, 0,130);
delay_ms(2000);
setPWM(1, 0,150);
delay_ms(2000);
setPWM(1, 0,175);
delay_ms(2000);
setPWM(1, 0,195);
delay_ms(2000);
For 180-degree servos, the only way to prevent excessive impact caused by excessive speed is to use delay and angle subdivision.
Previous article:STM32 controls the rotation of the servo
Next article:STM32 controls two servos
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Agilent6684A power supply maintenance method - Antai Instrument Maintenance
- Today is Arbor Day, happy holiday~~
- Learn electronics and Arduino from scratch: A beginner's guide to developing boards
- [NUCLEO-L452RE Review] +2.2-inch TFT display driver display
- C2000 CLA debugging and analysis
- [GD32L233C-START Review] 14. CAU encryption algorithm AES
- Setting the switching frequency of the switching power supply chip LTM4613
- Does the power layer of a four-layer board need to be made into a complete plane?
- [Register to enjoy gifts] element16 sincerely invites you to visit the 2019 Munich Shanghai Electronics Show
- E104-BT05 Test