PCA9685 driver does not support all modes (MODE2)

107 views
Skip to first unread message

Michel Lawaty

unread,
Nov 10, 2015, 10:10:14 AM11/10/15
to WebIOPi
The PCY9685 PWM chip supports different output modes.
Therefore it has a register MODE2 - Mode register 2 (address 01h) bit description
, which has following bit settings:

  • INVRT[1] R/W 0* Output logic state not inverted. Value to use when external driver used.
  • OCH R/W 0* Outputs change on STOP command[2].
  • OUTDRV[1] R/W 0 The 16 LEDn outputs are configured with an open-drain structure.
  • 0 OUTNE[1:0][4] R/W 00* When OE = 1 (output drivers not enabled), LEDn = 0.

These are important for changing the output driver.
Unfortunately the driver in webiopi does not support this. 
And my setup with connected Test-LED does not work with the actual driver.

So I tried to add following to the code, but it didn't work out. Also, I don't understand why "M1_SLEEP" is set to '1' ?? Then the chips sleeps, or not?

class PCA9685(PWM, I2C):
    MODE1   = 0x00
    MODE2   = 0x01
    PWM_BASE = 0x06
    PRESCALE = 0xFE

    M1_SLEEP    = 1<<4
    M1_AI       = 1<<5
    M1_RESTART  = 1<<7
    M2_OUTDRV   = 1<<2
    M2_OUTNE_1  = 1<<1
    M2_OUTNE_0  = 1<<0

    def __init__(self, slave=0x40, frequency=50):
        I2C.__init__(self, toint(slave))
        PWM.__init__(self, 16, 12, toint(frequency))
        self.VREF = 0

        self.prescale = int(25000000.0/((2**12)*self.frequency))
        self.mode2 = self.M2_OUTDRV | self.M2_OUTNE_0
        self.writeRegister(self.MODE2, self.mode2)

        self.mode1 = self.M1_RESTART | self.M1_AI
        self.writeRegister(self.MODE1, self.M1_SLEEP)
        self.writeRegister(self.PRESCALE, self.prescale)
        time.sleep(0.01)

        self.writeRegister(self.MODE1, self.mode1)


Reply all
Reply to author
Forward
0 new messages