Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved setFrequency and implemented a better getFrequency

  • Loading branch information...
commit e5bb1db5cf9a736e252dc346c8466fbf89d19f5d 1 parent 44e4d02
@brunnels authored
Showing with 2 additions and 5 deletions.
  1. +2 −4 PCA9685.cpp
  2. +0 −1  PCA9685.h
View
6 PCA9685.cpp
@@ -32,7 +32,6 @@ prog_uint16_t CIEL12[] PROGMEM = { 0, 2, 4, 5, 7, 9, 11, 12, 14, 16, 18, 20, 21,
PCA9685::PCA9685(byte address)
{
_address = address;
- _freq = 200;
}
/**
@@ -57,9 +56,8 @@ void PCA9685::wake()
*/
void PCA9685::setPWMFrequency(uint16_t freq)
{
- uint8_t prescale = (6104 / freq) - 1; // FIXME preScale =round(25000000Hz/(4096*freq))-1
+ uint8_t prescale = round(((float)25000000 / (float)(freq * (long)4096))) - 1;
PWMPreScale(prescale);
- _freq = freq;
}
/**
@@ -68,7 +66,7 @@ void PCA9685::setPWMFrequency(uint16_t freq)
uint16_t PCA9685::getPWMFrequency()
{
uint16_t freq;
- I2c.read(_address, (byte) 0xFE, (uint8_t) 4);
+ I2c.read(_address, (byte) 0xFE, (uint8_t) 1);
while (I2c.available()) {
freq = I2c.receive();
}
View
1  PCA9685.h
@@ -25,7 +25,6 @@ class PCA9685
uint16_t getPWM(uint8_t channel);
private:
byte _address;
- uint16_t _freq;
void PWMPreScale(uint8_t prescale);
};
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.