Strobing LED RGB PWM controlled outputs

Joel Grant

New Member
Hello,
I'm just trying to work out it in my head at this point so don't need detailed descriptions or solutions of how to but wondering if it is possible to do with the Picaxe. I would like to control the colours of a LED strip 1 colour per channel with PWM but then on top of that strobe all 3 channels at once or individually at different adjustable strobe rates between 40 to 100 hz or so.
So basically looking for the flexibility to strobe a LED strip in all its hues of colours ie. Red 20% PWM Green 50% PWM Blue 10% PWM and/or strobe the different channels at different adjustable rates ie. the Red at 60hz, Green at 50hz and Blue at 70hz or a combination of both. If the Picaxe is capable of this I would use it in a "Time Fountain" so that different drops of water at different colours would appear to fall or rise at different rates in reference to each other.
But at this point I am not sure if it is beyond the design parameters of the Picaxe chip.

Thanks
Joel
 

inglewoodpete

Senior Member
You need a PICAXE with at least 3 PWM channels (for Red, Green, Blue). You then need a fourth output, probably not PWM, to enable and disable the whole display to create your strobe effect. Not all PICAXEs will support this but I have used a 28X2 to drive up to 4 independent PWM channels into 4 strings of LEDs at once. Other members may be able to identify which other PICAXES can support 3 or 3+ independent PWM channels.
 

hippy

Technical Support
Staff member
It's going to be tricky.

You need a digital RGB LED strip to be able to set individual LED's at different colours and they take time to update so any strobing will ripple down the strip, not have them all come on simultaneously.

Another problem may be how digital LED's are driven by their controller. This is usually done by hardware counter PWM and that may limit the rate at which they an be strobed, or interfere with what is desired.

An analogue RGB LED strip will allow all LED's to be strobed simultaneously but all LED's would be the same colour.

You could use multiple analogue RGB LED strips to do it. Or separate the individual LED's and rewire them on a single analogue RGB LED strip so those multiple channels are interleaved on to one.

The ideal solution would perhaps be a PICAXE per LED or groups of LED which can have their colour and strobe rates set with some means of synchronising those.

I would start with a single digital APA102 RGB LED strip and see how well that goes. Use a 20X2 because of its high-speed capability and Scratchpad which will probably prove useful.
 

Joel Grant

New Member
Hi again,
ok...
The LED strip I have is a analogue RBG 5050 strip. I had a think and at least in my head think this option may work, what do you think...
…Rather then have the strip controlled by PWM I will just have a simple on or off control for each colour, so 3 Picaxe outputs control one colour each ie. output 1 Red, output 2 Green, output 3 Blue. This will still give me 6 colour options. I then strobe each output at the needed strobe rates ie the Red at 60hz, Green at 50hz and Blue at 70hz or something such as the Red off, Green at 50hz and Blue off etc.
ould be possible with the picaxe?
 

hippy

Technical Support
Staff member
This will still give me 6 colour options. I then strobe each output at the needed strobe rates ie the Red at 60hz, Green at 50hz and Blue at 70hz or something such as the Red off, Green at 50hz and Blue off etc.
ould be possible with the picaxe?
It seems possible to do but the real question is will it give the desired result ?

And the issue identified points to a potential problem with the other solutions suggested earlier.

The thing with a falling droplet being strobed is that it takes on the colour of the strobe no matter where it is, where it has fallen to. You can adjust an on and off strobe to make a droplet stream seem static, crawling downwards or upwards, but that effect comes from taking light away, allowing the droplet to move invisibly.

If you have more than one strobe this will cause all droplets to be the colour of the strobe when each fires. If you have three strobes, red, green and blue, every droplet will be red, green and blue as it falls, but that will mostly make it a white droplet stream.

I think you are trying to solve a problem which is impossible to solve. It would work if the stream were coloured balls falling, but not with water droplets which take on the colour of the light.
 

Buzby

Senior Member
I too am not sure how a 'Time Fountain with Different Coloured Droplets' could be built.

It would be fairly easy if the droplets appeared stationary all the time. In this case, focused beams such as lasers could illuminate each droplet independently.

But if the droplets are 'moving', then I can't see a way to colour each one differently.

Do you know of an existing machine like this on YouTube ?.

EDIT : I found one !. It's not quite what I think you are after, but it looks good anyway :
 
Last edited:

hippy

Technical Support
Staff member
I found one !. It's not quite what I think you are after, but it looks good anyway :
That seems exactly what's wanted, unless I have misunderstood. The video at 0:50 shows red droplets falling and blue droplets rising, and similar at 9:20, so I guess it can be done.

I was anticipating something like right at the end of the video, where it's a continuous stream with red, green and blue bands, except I expected the colours to merge giving white.

I think that might have come about through imagining the effects of different strobe rates where the trick seems to be that the lights aren't just strobed but sequenced. One can see the varying bands of colour moving through the light strips at 0:50 onwards.

So the key may be in how quickly one can update all the LED's in the strip. The APA102 can be driven from hardware SPI so that is up to 8 MHz, though the limiting factor would be how quickly one could feed @ptrInc to the SPI hardware.

For an SSD1306 128x64 OLED display, SPI can churn out 1024 bytes in just under 20ms at 64MHz so it seems it could be fast enough. But that's 50Hz max so maybe not. Plus one needs to manipulate the data to send which can easily halve that or worse.
 

Joel Grant

New Member
Thanks for the input guys!
Yes that's you tube video that got me thinking about it. If the Picaxe is capable of the functions which you guys think it is that will be great.

Think of it this way... Lets use Red and blue and green and lets say the rate of water falling looks stationary at 50hz. Ok lets strobe green at 50hz... we would see a stationary green droplet. Lets now add blue at 48hz it would like a blue droplet would slowly descend. Now if we added red at 52hz a droplet would look red and slowly rise. Because of "persistence of vision" they would all appear to exist at the same time but of course moving in their respective directions. At the point when the coloured droplets cross the droplet would take on the result of the combinations of colour ie. if it was red, blue and green for that moment it would appear white. So yes with more frequency's inthis case 3 we would see more droplets but only roughly 3 times more.

But hey at this point Its all theory as I have not done anything yet ha... but just didn't want to start only to find the picaxe could not do it.
Thanks
Joel
 

techElder

Well-known member
I seems like you need the red, blue and green unsynchronized to do this effect. You would have a better chance of doing it with three separate PICAXE processors; one for each color.
 

hippy

Technical Support
Staff member
If the Picaxe is capable of the functions which you guys think it is that will be great.
I'm not sure anyone's gone that far. I think there's going to be some degree of experimentation before one can say whether a PICAXE can do it or cannot.

My next step would be to try and hunt down some documentation on how that video producer did it, what technique they used.

But there's no reason not to grab a PICAXE and RGB strip and try it.
 

geezer88

Senior Member
Looks like a fun project. I think it works like this: drops are emitted at some fixed rate. A photo sensor creates a strobe signal that is synced with the drops. From that signal colored lights are triggered with varying delays.

Consider red. It's flash is triggered at a frequency that produces some number of flashes in the time of fall. If you look closely, it appears that the spacing is slightly closer at the top and increases as the drops accelerate due to gravity.

A second color oscillator, same frequency, but delayed a bit would flash in between the red flashes.

A third color could be added if desired.

It seems the picaxe load would not be all that onerous. I'd probably use several. One would be a master oscillator synced to the droplet emerging from the nozzle. Each LED color would get an picaxe PWM of it's own. Each color picaxe would simply create a flash delayed from the master.

Seems to me the really difficult part of this project is going to be deciding how to do the human / machine interface for creating effects and deciding what color mixes are pleasing. In other words, the creative content will take more time than the technical part. Maybe a joystick for each color with one axis brightness and one axis sync delay. Compared to the hours of experimenting this will take, picaxes are a bargain.

I am sure that insights discovered in playing with it will inspire other new effects.

Please keep us posted, tom
 

Buzby

Senior Member
I downloaded the RGB version of the A*****o code, and it definately looks like a Picaxe could do it.
There a some floating point variables in the code, and a few bits of trigonmetry, but nothing that a Picaxe can't handle.

The three PWM channels for the LEDs are bit-banged at the speed of the main loop. This may need changing to use 'real' PWM if a Picaxe is not fast enough to bang the bits. ( I think it probably be OK though, and the 'phasing' will be easier, but I haven't tried it. )

If I was to attempt this, I'd start by building the drop generator. A simple single-colour LED driven from a Picaxe PWM channel would make an easy 'strobe light' to get a feel for the numbers.
 

Attachments

hippy

Technical Support
Staff member
Thanks for finding the code. The good news is that it does indeed seem to be a simple analogue RGB strip varying the intensity of all LED's in parallel. That does simplify things greatly, brings it down to whether the PICAXE can do everything it needs to do quickly enough.

I'm more confident of that. Here's some 20X2 code which can deliver three channel bit-banged PWM at over 70Hz. That's with 32 step resolution @ 64MHz. Duties are 40%, 50% and 60%.

Of course, we want separate frequencies, not fixed frequency with varying duty. That's the next thing to try.
Code:
#Picaxe 20X2
#No_Data

#Macro Init( Xpin, pinN, dirN , Xduty, bN )
  Symbol Xpin  = pinN
  Symbol Xduty = bN
  dirN         = 1
#EndMacro

Init( Rpin, pinC.0, dirC.0 , Rduty, b2 )
Init( Gpin, pinC.1, dirC.1 , Gduty, b3 )
Init( Bpin, pinC.2, dirC.2 , Bduty, b4 )

Symbol cycle = b5

#Define Percent(n) n * 256 / 100

#Macro SetPwm( Xpin, Xduty )
  w0 = cycle - Xduty : Xpin = bit15
#Endmacro

SetFreq M64
Rduty = Percent(40)
Gduty = Percent(50)
Bduty = Percent(60)
Do
  SetPwm( Rpin, Rduty )
  SetPwm( Gpin, Gduty )
  SetPwm( Bpin, Bduty )
  cycle = cycle + 8
Loop
 

Attachments

Buzby

Senior Member
Hi hippy,

The multiple frequency stuff is easily done by having a different 'cycle' value for each colour. See the 'red_max_count' etc. in the original.

Cheers,

Buzby
 

hippy

Technical Support
Staff member
Three varying frequencies, nominally 40Hz, 50Hz and 60Hz but not exactly.

Added : Cross-posted with Buzby; which is sort of what I'm doing here. Not so much limiting the max count, but altering the rate of counting, by adjusting what the step value is.

Also : With "w0 = Xval : Xpin = bit15" replaced by "Xpin = Xval & $8000 Max 1"in the 'OutHz' macro the frequencies are pretty much spot on, though tweaking the 'SetHz' macro would be the actual solution to setting timing.

Code:
#Picaxe 20X2
#No_Data

#Macro Init( Xpin, pinN, dirN , Xval, Wval , Xstep, Wstep )
  Symbol Xpin  = pinN
  Symbol Xval  = Wval
  Symbol Xstep = Wstep
  dirN         = 1
#EndMacro

Init( Rpin, pinC.0, dirC.0 , Rval, w1 , Rstep, w4 )
Init( Gpin, pinC.1, dirC.1 , Gval, w2 , Gstep, w5 )
Init( Bpin, pinC.2, dirC.2 , Bval, w3 , Bstep, w6 )

#Macro SetHz( Xstep, n )
  Xstep = n * 32
#EndMacro

#Macro OutHz( Xpin, Xval, Xstep )
  w0 = Xval : Xpin = bit15
  Xval = xVal + Xstep  
#Endmacro

SetFreq M64
SetHz( Rstep, 40 )
SetHz( Gstep, 50 )
SetHz( Bstep, 60 )
Do
  OutHz( Rpin, Rval, Rstep )
  OutHz( Gpin, Gval, Gstep )
  OutHz( Bpin, Bval, Bstep )
Loop
 

Attachments

Last edited:

hippy

Technical Support
Staff member
And with phase shifts -
Code:
#Picaxe 20X2
#No_Data

#Macro Init( Xpin, pinN, dirN , Xval, Wval , Xstep, Wstep, Xphase, Wphase )
  Symbol Xpin   = pinN
  Symbol Xval   = Wval
  Symbol Xstep  = Wstep
  Symbol Xphase = Wphase
  dirN          = 1
#EndMacro

Init( Rpin, pinC.0, dirC.0 , Rval, w1 , Rstep, w4 , Rphase, w7 )
Init( Gpin, pinC.1, dirC.1 , Gval, w2 , Gstep, w5 , Gphase, w8 )
Init( Bpin, pinC.2, dirC.2 , Bval, w3 , Bstep, w6 , Bphase, w9 )

#Macro SetHz( Xstep, n )
  Xstep = n * 32
#EndMacro

#Macro SetPhase( Xphase, n )
  Xphase = n * $80 / 180 * 256
#EndMacro

#Macro OutHz( Xpin, Xval, Xphase, Xstep )
  Xpin = Xval - Xphase & $8000 Max 1
  Xval = xVal + Xstep  
#Endmacro

SetFreq M64
SetHz( Rstep, 50 ) SetPhase( Rphase,   0 )
SetHz( Gstep, 50 ) SetPhase( Gphase,  90 )
SetHz( Bstep, 50 ) SetPhase( Bphase, 180 )
Do
  OutHz( Rpin, Rval, Rphase, Rstep )
  OutHz( Gpin, Gval, Gphase, Gstep )
  OutHz( Bpin, Bval, Bphase, Bstep )
Loop
 

Buzby

Senior Member
Hi hippy,

I'm not able to spend a lot of time on this, too much domestic stuff going on today !.

However, I think your 'step size' method of generating the signals is going to be too rough. The writer of the original code explains in some comment somewhere that the duty ratio of each channel needs to be around 8% to 12%, any higher and the drops blur together into a stream. Varying that % slightly makes significant changes to the appearance of the effect.

By having the three variables, 'Red_Count', 'Red_Max_Count', 'Red_Duty', there is a lot of fine adjustment that can be made to both frequency and duty.

Cheers,

Buzby
 

hippy

Technical Support
Staff member
I think your 'step size' method of generating the signals is going to be too rough ... By having the three variables, 'Red_Count', 'Red_Max_Count', 'Red_Duty', there is a lot of fine adjustment that can be made to both frequency and duty.
You could be right. I was a little worried about having to do a number of divisions and modulos to generate the outputs but it is possible, and also quicker than IF comparisons.

The "Hz" calculation needs a little tweaking but the code below is pretty close.

I haven't determined what the resolution or accuracy would be. -- At 60Hz the max count (Xhz) is 20. That's quite low resolution, giving duty in steps of 5%.

It's really just proof of concept, seeing if even in the right ballpark. It seems so but there will be more work to do, experimenting and tweaking.
Code:
#Picaxe 20X2
#No_Data

#Macro Init( Xpin, pinN, dirN , Xval, Wval , Xhz, Whz, Xduty, Wduty )
  Symbol Xpin  = pinN
  Symbol Xval  = Wval
  Symbol Xhz   = Whz
  Symbol Xduty = Wduty
  dirN         = 1
#EndMacro

Init( Rpin, pinC.0, dirC.0 , Rval, w1 , Rhz, w4, Rduty, w7 )
Init( Gpin, pinC.1, dirC.1 , Gval, w2 , Ghz, w5, Gduty, w8 )
Init( Bpin, pinC.2, dirC.2 , Bval, w3 , Bhz, w6, Bduty, w9 )

#Define Hz( n ) 1200 / n

#Define Duty( Xhz, percent ) 100 - percent * Xhz / 100

#Macro OutHz( Xpin, Xval, Xhz, Xduty )
  Xpin = Xval / Xduty Max 1
  Xval = Xval + 1 // Xhz  
#Endmacro

SetFreq M64
Rhz = Hz(40) : Rduty = Duty( Rhz, 50 )
Ghz = Hz(50) : Gduty = Duty( Ghz, 50 )
Bhz = Hz(60) : Bduty = Duty( Bhz, 50 )
Do
  OutHz( Rpin, Rval, Rhz, Rduty )
  OutHz( Gpin, Gval, Ghz, Gduty )
  OutHz( Bpin, Bval, Bhz, Bduty )
Loop
 

geezer88

Senior Member
I agree with Buzby that a drop generator would be a good thing to get under control first.

Towards that, the ink pump in some inkjet printers might work well. I recently tore down an HP printer that was not working and therefor free. In it was a very nice peristaltic pump. The pump was driven by a dc motor with an incremental encoder that could be used for accurate volume control. The pump had a channel for each ink color, so extra channels could be used to return drops to the reservoir.

Veterinarian supply places sell hypodermic needles of varying sizes that would offer an easily size selection for dropping. I don't know if the needle would work better as-is, or ground blunt. Grinding something that small may create a challenge to debur.

If the drop falling distance is 30cm, then the fall time of each drop would be about 250 msec. To have ten drops in flight at a time would then imply drop frequency of 40 hz.

To get started, an 08m2 could control the pump motor and an output on it could be the master clock. An input could be the drop detector, if needed.

tom
 

geezer88

Senior Member
I decided to see what it might take to make drops and detect them, so this morning I played in the water.

First I set up the printer pump to suck out of the catch basin and discharge above it by about 40 cm. I did not use a nozzle, just the cut end of the rubber-like discharge hose from the pump. It seemed to make descent looking drop. I ran the motor from a bench power supply.

To begin with, I used an auto engine timing light driven by a square wave generator to view the drops. It became obvious that the drops were not uniformly initiated. This implies that either a better emitter or a drop detector will be needed to get a controlled view of the drops. I could see the drops going up with the flash rate a little high, and down with the rate a bit low.

With this in mind I worked a bit on detection. My junk box had a Keyance fiber optic photo detector that I hand-held up to the drop emitter. I don't have the fiber optic portion, so this setup is just an led and a photo detector. It has a built in indicator light that showed it was detecting the drops okay.

So, I think a picaxe cycling off a drop detector and flashing some bright LEDs would work. You would need to advance or delay the different colors to get them to do stuff, but figuring out all that would be fun once you get a test bed built.

Best luck on your project.
Tom
 

Joel Grant

New Member
Thank you guys for all you comments,
I have yet to start this project as I have been busy but look forward to doing it. I'm sure I will have more questions soon.
Thanks
Joel
 
Top