eddiewwm 发表于 2019-9-12 18:46:31

LGT8F328P 與 PCA9685 16-Channel 12-Bit PWM Driver

本帖最后由 eddiewwm 于 2019-9-13 10:28 编辑

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


重點:
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);

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

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

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

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

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

void loop() {
      pwm.setPWM(1, 0, 500 );
      pwm.setPWM(2, 500, 1000 );
}

页: [1]
查看完整版本: LGT8F328P 與 PCA9685 16-Channel 12-Bit PWM Driver