stm32+pca9685 control servo mechanical arm

Publisher:cxx7848653Latest update time:2018-06-19 Source: eefocusKeywords:stm32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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. 
Write the picture description here 
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. 
Write the picture description here 
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. 
Write the picture description here

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.


Keywords:stm32 Reference address:stm32+pca9685 control servo mechanical arm

Previous article:STM32 controls the rotation of the servo
Next article:STM32 controls two servos

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号