制造工程实践使用

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
lant19
Date:
Thu Oct 24 06:30:59 2019 +0000
Parent:
1:7f3c3ac6b20b
Commit message:
with Chinese

Changed in this revision

PCA9685.cpp Show annotated file Show diff for this revision Revisions of this file
PCA9685.h Show annotated file Show diff for this revision Revisions of this file
diff -r 7f3c3ac6b20b -r 1d858fcb3cb5 PCA9685.cpp
--- a/PCA9685.cpp	Fri Jul 24 09:03:58 2015 +0000
+++ b/PCA9685.cpp	Thu Oct 24 06:30:59 2019 +0000
@@ -1,17 +1,17 @@
 #include "PCA9685.h"
 #include "mbed.h"
 PCA9685::PCA9685(PinName sda, PinName scl, int addr) : i2c(sda, scl), _i2caddr(addr) {}
-
-void PCA9685::begin(void)
+//定义引脚与地址
+void PCA9685::begin(void)//初始化
 {
     reset();
 }
 
-void PCA9685::frequencyI2C(int freq)
+void PCA9685::frequencyI2C(int freq)//初始化
 {
     i2c.frequency(freq);
 }
-void PCA9685::write8(uint8_t address, uint8_t data)
+void PCA9685::write8(uint8_t address, uint8_t data)//写函数
 {
     char cmd[2];
     cmd[0] = address;
@@ -19,7 +19,7 @@
     i2c.write(_i2caddr, cmd, 2);
 }
 
-char PCA9685::read8(char address)
+char PCA9685::read8(char address)//读函数
 {
     i2c.write(_i2caddr, &address, 1);
     char rtn;
@@ -27,21 +27,21 @@
     return rtn;
 }
 
-void PCA9685::reset(void)
+void PCA9685::reset(void)//复位
 {
     write8(PCA9685_MODE1, 0x0);
 }
-void PCA9685::setPrescale(uint8_t prescale) {
+void PCA9685::setPrescale(uint8_t prescale) {    
     uint8_t oldmode = read8(PCA9685_MODE1);
     uint8_t newmode = (oldmode&0x7F) | 0x10; // sleep
     write8(PCA9685_MODE1, newmode); // go to sleep
     wait_ms(5);
-    write8(PCA9685_PRESCALE, prescale); // set the prescaler
+    write8(PCA9685_PRESCALE, prescale); // 设置预缩放
     write8(PCA9685_MODE1, oldmode);
     wait_ms(5);
     write8(PCA9685_MODE1, oldmode | 0xa1);
 }
-void PCA9685::setPWMFreq(float freq)
+void PCA9685::setPWMFreq(float freq) //设置频率
 {
     float prescaleval = 25000000;
     prescaleval /= 4096;
diff -r 7f3c3ac6b20b -r 1d858fcb3cb5 PCA9685.h
--- a/PCA9685.h	Fri Jul 24 09:03:58 2015 +0000
+++ b/PCA9685.h	Thu Oct 24 06:30:59 2019 +0000
@@ -77,23 +77,23 @@
 class PCA9685
 {
 public:
-    PCA9685(PinName sda, PinName scl, int addr = 0x80);
+    PCA9685(PinName sda, PinName scl, int addr = 0x80);//定义pca9685 地址为1+A5+A4+A3+A2+A1+A0+rw rw写为0 读为1
     void frequencyI2C(int freq);
-    void begin(void); //Initialize the controller
-    void reset(void); //Reset the controller
-    void setPrescale(uint8_t prescale);//setPrescale(prescale)
-    /** Set prescale
+    void begin(void); //初始化
+    void reset(void); //复位
+    void setPrescale(uint8_t prescale);//设置预缩放
+    /** set prescale
      *
      *  @param prescale: set scale for the PWM frequency
      *
      */
-    void setPWMFreq(float freq);//Set the pwm frequency
+    void setPWMFreq(float freq);//设置PWM频率 单位hz
     /** Set frequency
       *
       * @param frequency in Hz
       *
       */
-    void setPWM(uint8_t num, uint16_t on, uint16_t off);//SetPWM(channel, on, off)
+    void setPWM(uint8_t num, uint16_t on, uint16_t off);//SetPWM(通道数:0到15, 信号上升沿位置:0到4095, 下降沿位置:0到4095)不同舵机所需的上升沿到下降沿的长度不同
     /** Set the start (on) and the end (off) of the part of the PWM pulse of the channel
      *  @param channel : from 0 to 15 the channel the should be update
      *  @param  on: from 0 to 4095 the tick when the signal should pass from low to high