6 channel PWM

robboski

New Member
Hi Everybody,
My first post, hope I'm in the right place!

I'm trying to achieve 6 channel PWM control of LED's. My first thoughts were to use a 08M2 connected to an SN3218 18 channel PWM driver board from PIMORONI using the I2C bus. That is until I read the SN3218 datasheet and decided that I bit off more than I could chew! Does anyone have have any code snippets of how the two connect? I have Googled the subject to death and still can't work out how to do it. Alternatively any ideas how I could achieve this 6 channel PWM control using other methods?

regards
 

AllyCat

Senior Member
Hi,

I'm trying to achieve 6 channel PWM control of LED's.
Welcome to the forum. It rather depends exactly what the "LEDs" (and the PICaxe) are required to to do.

The 3218 appears to contain 18 "constant current" LED drivers of up to 25 mA each. If you actually want to drive 6 individual LEDs with variable brightness at up to 25 mA, then the 3218 is probably the way to go. I haven't seen its full data sheet, nor the particular PIMORONI module (the PiGlow looks quite interesting), but we can probably help you through the I2C control programming if required. Links to the two data sheets could be helpful.

However, if you want 6 PWM "logic" outputs (for example to drive strings of bright LEDs via FETs), then two PICaxes might be the way to go. The 08M2 has only one "hardware" PWM output, but 3-4 outputs might be driven using software "bit bashing", if nothing much else needs to be done. But a pair of 14M2s could control 6 output pins "in the background" (using internal hardware), leaving the PICaxes to do any other functions that might be required.

Cheers, Alan.
 

hippy

Technical Support
Staff member
Welcome to the PICAXE forum.

I am not familiar with the SN3218, and do not know of any existing code to use that, but from the datasheet it seems simple enough to use -

www.si-en.com/uploadpdf/s2011517171720.pdf

It looks like one only needs to configure the device, turn channels on and ensure the chip is not shutdown -

Code:
HI2cSetup I2CMASTER, %10101000, I2CSLOW, I2CBYTE

Hi2Cout $00, ( %00000001 ) ; Bring it out of shutdown
Hi2Cout $13, ( %00111111 ) ; Enable channel 1-6
Hi2Cout $14, ( %00111111 ) ; Enable channel 7-12
Hi2Cout $15, ( %00111111 ) ; Enable channel 13-18
Then update the channel duty 0-255, ($00-$FF) ...

Code:
HI2cOut $01, ( $00 ) ; Channel 1 off
HI2cOut $02, ( $7F ) ; Channel 2 half brightness
HI2cOut $03, ( $FF ) ; Channel 3 full brightness
:
HI2cOut $12, (     ) ; Channel 18
After updating the LED channels one wishes to set it seems there needs to be an additional command to cause those levels to be output -

Code:
HI2cOut $16, ( $00 ) ; Update outputs
 

robboski

New Member
Chaps that is brilliant!
I've been scratching my head for a while. Now that hippy has spelled out the code it all makes perfect sense when I reference the SN3218 datasheet. Also thank you Alan for your kind offer of help. I'll get the breadboard out and hopefully post a completed project in the near future.

Pete
 
Top