PDA

View Full Version : PCA9685 turning all outputs on / off



Scampy
- 20th May 2016, 20:14
I'm working on a project that uses the PCA9685 chip. The chip is set up using the following code, which I confess was provided for me by a friend, but I get the gist of things in that it resets the chip and sets a pre-scaler or something !



'Initialize the PCA9685

i2cControl var BYTE 'Used for PCA chip control
i2cReadAddress var BYTE
i2cWriteAddress var BYTE
pcaAddress var BYTE
oldMode var BYTE
newMode var BYTE
pcaChannel var BYTE

i2cReadAddress = pcaAddress << 1
i2cWriteAddress = i2cReadAddress | 1
i2cControl = $0 ;Reset
I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[$0] ;PCA9685_MODE1 $0
i2cControl = $0 'PCA9685_MODE1 $0
I2CREAD SDApin,SCLpin,i2cReadAddress,i2cControl,[oldMode] ;Get old mode
newMode = (oldMode & $7F) | $10 ;MODE1 Sleep
i2cControl = $0
I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[newMode] ;PCA9685_MODE1 $0
i2cControl = $FE ;PCA9685_PRESCALE $FE
I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[6] ;Prescaler is now 6 was 11
i2cControl = $0 ;PCA9685_MODE1 $0
I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[oldMode] ;Set old mode
i2cControl = $0 ;PCA9685_MODE1 $0
I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[oldMode | $A1 ] ;Set MODE1 AutoIncrementOn | $A1



Using word variables (CH1_PWM, CH2_PWN etc) for the 0 to 4095 PWM levels the following code performs the setting of channel brightness, (the value for pcaChannel runs through from 0 to 15 for the 16 channels with each increment of CHx_PWM variable if that makes sense ?)



pcaChannel = 0
i2cControl = $6 + 4*pcaChannel
I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[0,0,CH1_PWM.lowbyte,CH1_PWM.highbyte]




The above code is called when a time condition is matched, so each channel is has its own on/off time in a 24 hour period. But I want to have a manual over-ride so that if a button is pressed it jumps to a gosub routine which makes all the outputs of the PCA chip turn on. Looking at the datasheet https://cdn-shop.adafruit.com/datasheets/PCA9685.pdf there is register setting to turn all the LEDs on or off (FA, FB, FC and FD) but I don't know how to implement this in the code, so wondered if anyone has some suggestions ?

Scampy
- 20th May 2016, 20:52
Well I got a work around



override:
LCDOUT $FE,$D4,"All On "

A=4095
For B = 0 to 15
pcaChannel = B
i2cControl = $6 + 4*pcaChannel
I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[0,0,A.lowbyte,A.highbyte]
next B


If IncButton=0 then
A=0
For B = 0 to 15
pcaChannel = B
i2cControl = $6 + 4*pcaChannel
I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[0,0,A.lowbyte,A.highbyte]
next B
Gosub SetButtonRelease
n=0
LCDOUT $FE,$D4," "
endif

Acetronics2
- 22nd May 2016, 17:51
table 4 p 13 ...

registers 250 to 255 ...

What else ??? (Nespresso ? )

Alain