极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 615|回复: 0

LGT8F328P 與 PCA9685 16-Channel 12-Bit PWM Driver

[复制链接]
发表于 2019-9-12 18:46:31 | 显示全部楼层 |阅读模式
本帖最后由 eddiewwm 于 2019-9-13 10:28 编辑

參考 https://learn.adafruit.com/16-channel-pwm-servo-driver?view=all
PCA9685 arduino connection.JPG

重點:
1) V+ 是 Servo 的供電, VCC 是電路供電
2) OE 當低電平時,所有輸出使能;高電平時關閉所有輸出
3) 所有輸出的佔空比能獨立設定,但所有輸出的頻率相同(可設定頻率範圍:40Hz~1600Hz)
4) I2C 基礎地址是 0X40,可用 A0~A5 作設定改動,從+0X00 到 +0X3F,即設定範圍為 0X40~0X7F
5) 使用了 Adafruit_PWMServo
6) pwm.setPWMFreq(頻率) 設定頻率(可設定頻率範圍:40Hz~1600Hz),如 pwm.setPWMFreq(1000) 將輸出 1000Hz訊號
7) pwm.setPWM(通道, 起始點, 終止點)設定每個通道的佔空比,當中的起始點和終止點範圍在 0~4096,如pwm.setPWM(15, 0, 2048)將設定通道15輸出一個從0開始的50%佔空比的訊號。
8) You can set the pin to be fully on (100%) with: pwm.setPWM(pin, 4096, 0);
    You can set the pin to be fully off (0%) with: pwm.setPWM(pin, 0, 4096);   , or use:   pwm.setPWM(pin, 0, 0);

  1. #include <Wire.h>
  2. #include <Adafruit_PWMServoDriver.h>

  3. // called this way, it uses the default address 0x40
  4. Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
  5. // you can also call it with a different address you want
  6. //Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
  7. // you can also call it with a different address and I2C interface
  8. //Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(&Wire, 0x40);

  9. void setup() {
  10.   Serial.begin(9600);
  11.   Serial.println("16 channel PWM test!");

  12.   pwm.begin();
  13.   pwm.setPWMFreq(62);  // This is the maximum PWM frequency

  14.   // if you want to really speed stuff up, you can go into 'fast 400khz I2C' mode
  15.   // some i2c devices dont like this so much so if you're sharing the bus, watch
  16.   // out for this!
  17.   Wire.setClock(400000);
  18. }

  19. void loop() {
  20.       pwm.setPWM(1, 0, 500 );
  21.       pwm.setPWM(2, 500, 1000 );
  22. }
复制代码


Example Waveform.JPG
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊 ( 浙ICP备09023225号 )

GMT+8, 2019-11-18 12:55 , Processed in 0.052986 second(s), 27 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表