Andrew Cowan
Senior Member
I'm looking to control some RGBY LED modules via serial.
These modules have built in CC drivers, and accept a PWM input of up to 2kHz. However, the inductors buzz/hum at whatever PWM frequency is used, so a 2kHz PWM results in a 2kHz hum.
Through a bit of trial and error, I've found the least annoying frequency to PWM them at is somewhere around 80 to 100Hz - this is as low as you can go without the LEDs stobing visibly. Therefore I want a PWM signal around this frequency. The solution must continuously output a PWM signal, with a duty given by background serial receive.
I've tried bit banging code for four PWM channels on a 20X2, and it can't do it fast enough - even at 64MHz, there is significant flickering. That's using code like:
My next thought was to use an 08M2 for each channel - so each 08M2 does one colour. I haven't got any 08M2s yet, but I think code like this might just be fast enough (possibly with PWM_delay being 0):
However, my maths says that even this may struggle to keep up.
My latest idea is to scrap a 255 long loop, and instead use pulsout - eg:
This seems a much better idea, and I think it would be much better at keeping up. A 08M2 would certainly be able to do a 100Hz PWM signal like this.
Is four 08M2s each running this pulsout code going to be the best (and cheapest) way of acheiving this? Are there any obvious problems to my code?
Any thought appriciated.
Andrew
Nb - all the above code is not meant to work, is missing symbol definitions, there be be typos, it uses decimals etc. - it's just showing a concept!
These modules have built in CC drivers, and accept a PWM input of up to 2kHz. However, the inductors buzz/hum at whatever PWM frequency is used, so a 2kHz PWM results in a 2kHz hum.
Through a bit of trial and error, I've found the least annoying frequency to PWM them at is somewhere around 80 to 100Hz - this is as low as you can go without the LEDs stobing visibly. Therefore I want a PWM signal around this frequency. The solution must continuously output a PWM signal, with a duty given by background serial receive.
I've tried bit banging code for four PWM channels on a 20X2, and it can't do it fast enough - even at 64MHz, there is significant flickering. That's using code like:
Code:
#PICAXE20X2
init:
setfreq m64
hsersetup B9600_64, %01001
do
get PWM levels from scratchpad
for counter = 0 to 255
if PWM_level_1 >= counter
high PWM_output_1
else
low PWM_output_1
endif
if PWM_level_2 >= counter
high PWM_output_2
else
low PWM_output_2
endif
if PWM_level_3 >= counter
high PWM_output_3
else
low PWM_output_3
endif
if PWM_level_4 >= counter
high PWM_output_4
else
low PWM_output_4
endif
pause PWM_delay
next counter
loop
Code:
#PICAXE08M2
init:
setfreq m32
hsersetup B9600_32, %01000
do
hserin PWM_level
for counter = 0 to 255
if PWM_level >= counter
high PWM_output
else
low PWM_output
endif
pause PWM_delay
next counter
loop
My latest idea is to scrap a 255 long loop, and instead use pulsout - eg:
Code:
#PICAXE08M2
Symbol frequency = 100 'hertz
Symbol period = wb0
Symbol multiplier = w1
Symbol pulsout_unit = 1.25 'microseconds at 32MHz (I know I can't use decimals, this is just example code)
period = 1000 / frequency 'milliseconds
period = period * 1000 'microseconds
multiplier = period / pulsout_unit 'which is 8000 for 100Hz
init:
setfreq m32
hsersetup B9600_32, %01000
do
hserin PWM_ontime
PWM_offtime = 255 - PWM_ontime 'so each period is 255 units long
PWM_ontime = PWMontime * multiplier
PWM_offtime = PWMofftime * multiplier
pulsout PWM_output, PWMontime
pulsout DummyPin, PWMofftime
loop
Is four 08M2s each running this pulsout code going to be the best (and cheapest) way of acheiving this? Are there any obvious problems to my code?
Any thought appriciated.
Andrew
Nb - all the above code is not meant to work, is missing symbol definitions, there be be typos, it uses decimals etc. - it's just showing a concept!