# 27 channel PWM with a 16F88

Status
Not open for further replies.

#### geko

##### Active Member
Here's a video of a little project I've been tinkering with.

9 RGB LEDs, 27 x 6 bit PWM channels on an 8Mhz PIC 16F88.

The LEDs are driven in 3 groups of 3. The outputs are multiplexed as well as PWM'd to get the 27 channels through 9 sink outputs and 3 source drivers.

#### futz

##### Active Member
Here's a video of a little project I've been tinkering with.

Groovy! Looks like an interesting project.

I've been meaning to get around to doing an RGB LED cube for quite a while. But other things keep distracting me...

#### nickelflippr

##### Member
Nice project. I like how you mounted the piranha led's, in case you have a dud, it's an easy replace. Need to get some of those piranha's.

##### Banned
Very nice geko, but what's the deal with Youtube clips and techno? That clip almost requires a disco song. I demand Dancing Queen!

#### geko

##### Active Member
Very nice geko, but what's the deal with Youtube clips and techno? That clip almost requires a disco song. I demand Dancing Queen!
Okay, just for you here's the DQ mix

##### Banned
Thanks geko, you just made my day.
What's this for anyways?

#### geko

##### Active Member
Nice project. I like how you mounted the piranha led's, in case you have a dud, it's an easy replace. Need to get some of those piranha's.
Actually the sockets are mainly so I can recycle the LEDs into the next project.

Oddly enough the only dud Piranah LEDs I've had came from a reputable UK distributor; all the cheap ones I've bought off eBay from HK & China have never let me down.

#### Gayan Soyza

##### Active Member
This is excellent nicely done.Good work.

Did you extend your vertical counter Pete?

#### geko

##### Active Member
Thanks geko, you just made my day.
What's this for anyways?
I was asked to do it with the requirment that it has 9 RGB LEDs and runs on a 16F628.

Initially I thought it was complicated to achieve and pointless and wasn't that keen to take it on but now I've had it running in the workshop it's quite mesmerising - the video clip doesn't do it justice.

It might yet end up a project on the website.

#### geko

##### Active Member
This is excellent nicely done.Good work.

Did you extend your vertical counter Pete?
No I haven't used vertical counters on this, it doesn't lend itself to them because it needs 27 PWM channels, and even though it's split into 3 groups that's still 9 bits so it's not byte friendly.

I just used this basic method below. Because the PWM is only 6 bits (0-63) pwm.count is initalised to 256-63 at the start of each period, and is incremented. There's a little bit more code that's not shown to pull it altogether but this is the core of the PWM generation.

Code:
              movfw       pwm.count
rrf         portb.copy,F

; ..... repeat for leds 2 thru 7

movfw       pwm.count
rrf         portb.copy,W
movwf       PORTB

; deal with that pesky 9th LED on port A
; porta is also controlling the common anode source transistors
movfw       pwm.count
skpnc
bsf         porta.copy, led9
movfw       porta.copy
movwf       PORTA
This method is also a bit more handy for experimenting with different PWM resolutions too, just change the pwm.count intialisation value.

Last edited:

#### Gayan Soyza

##### Active Member
Hi Pete thats a nice method.I like your CARRY transferring method. Let me compact it more sir .

I more prefer your way is because you are turning off the LEDs until matches the duty & sets the particular bit.This is smoother when animating LEDs.

Last edited:

##### Banned
Hey geko, what's the partnumber on those LED's and where did you buy them from?

#### Mike - K8LH

##### Well-Known Member
Here's a video of a little project I've been tinkering with.

9 RGB LEDs, 27 x 6 bit PWM channels on an 8Mhz PIC 16F88.

The LEDs are driven in 3 groups of 3. The outputs are multiplexed as well as PWM'd to get the 27 channels through 9 sink outputs and 3 source drivers.

Hi Pete,

Is the schematic for this 9-channel RGB controller somewhere on your web site Sir?

Regards, Mike

#### Mike - K8LH

##### Well-Known Member
Pete,

In my previous post I forgot to say that I think your demo' and prototype PCB looks extremely nice.

Thanks for posting the schematic. So, you're using direct drive from I/O for cathodes and source driver transistors on the common anodes as I suspected.

Did you limit software PWM duty cycle to 64 steps (6 bits) because of ISR driver "overhead" and to produce a decent refresh rate?

Regards, Mike

#### AtomSoft

##### Well-Known Member
Ok no clue how i missed this whole topic! this was awesome!!!... any code? would love it... heh...

#### Mike - K8LH

##### Well-Known Member
Hi Jason,

I just stumbled onto it yesterday too.

Pete did an extremely nice job on this project but I would like to update it with a BAM (bit angle modulation) driver of my own design which should allow for 8 or 9 bit resolution (256 or 512 steps, respectively) at extremely high refresh rates on the order of several hundred Hertz.

More later. Regards, Mike

Last edited:

#### AtomSoft

##### Well-Known Member
would be nice if i had some code to examine heh... when ready im sure it will be posted here. This is awesome tho really! Great job to the both of you. Its like thanking the guy who invented the wheel then the guy who smoothed it out heh

#### geko

##### Active Member
Pete,

Did you limit software PWM duty cycle to 64 steps (6 bits) because of ISR driver "overhead" and to produce a decent refresh rate?

Regards, Mike
I think that was why I did it that way yes.

The whole thing was done as a bit of an experiment after I was asked if it could be done - they wanted 9 RGB channels and so the challange was there and I just had a play to see what I could do. The PCB had the option for an external crystal but I think I had no crystal to hand so it started with the internal 8Mhz RC.

I can't really remember too much about it, I hacked it together over a couple of evenings and haven't been back to it since. It uses sine wave data in a look up table (calculated in Excel) to generate the duty cycles.

Depending on the 'angle' between the RG & B offsets into the table and the channel index seperation you can tune the spread of colour across all the channels (full colour spectrum or narrow colour 'window' ) and also the rate it changes through the spectrum.

The source code is a bit rough and ready and was never really finished but here it is anyway

Attachement doesn't seem to want to open so here's a link direct to my website.
http://picprojects.org.uk/pub/r9/rainbow9.zip

#### Attachments

• 42.4 KB Views: 205
Last edited:
Status
Not open for further replies.