A bit off topic - Microcontrollers - PWM - 2 Co-ordinated channels

Joined
17 Jun 2004
Messages
7,195
Reaction score
483
Country
United Kingdom
This is going to be a rather specific post that might not really belong here, but I know there are a few on here who have done a bit with microcontrollers, so I thought I'd put it out there, as I've got a scenero that I'm not quite sure where to start with solving.

If I have two banks of LEDS and I want to control the brightness of them via PWM... not a problem if you can have them connected to indepdant transisters on separate pins. If however what you want to control has two groups of LEDS, but all on the same pair of wires, with bank A one polarity and bank B the reverse. Obviously the duty would be maximum 50% for each side (unless time was 'borrowed' from the other side)

Electrically its not too difficult, I could drive each set through a H bridge and have one pin pull the polarity one way and another pull it another way (software glitches could take out the fuses though...) But how to impliment this in PWM, because per cycle in the PWM, you'd have to activate the first output for the correct percentage of the first half, while keeping the second output off. Then at the halfway point make sure the first output goes off, then activate the second for the correct fraction of it.

The only way I can get close to an idea, rather than having the changeover done once per clock cycle, have two PWMs going aty a high frequency, then have a much slower cycle of polairty reversal, using the first PWM to drive the first H bridge input, then stopping, then driving the second with the second PWM input. But my thinking was flicker was likely to be a problem with this, like filming a CRT monitor or similar effect
 
Using polarity to select which bank illuminates will put reverse polarity on the LED elements that are OFF. That reverse polarity can overstress the LED elements.

This circuit works provided that care is taken to ensure both switches are not closed at the same time.

upload_2021-2-16_20-2-19.png
 
I understand the concern, but I do not believe that will be a problem in practice as thats how the arrangement is designed to operated.

For context, the LED load is prewired sets of christmas lights, they are wired with a two core cable and the LEDS with polarity to separate out the two channels, the supplied controller/PSU is simply revering the polairty, and I think it was about 400hz when on static, but dropped slower when doing fading pattens
 
per cycle in the PWM, you'd have to activate the first output for the correct percentage of the first half, while keeping the second output off. Then at the halfway point make sure the first output goes off, then activate the second for the correct fraction of it.

Whether this is possible will depend on the particular microcontroller’s PWM function.

The PWM in the NXP LPC microcontrollers can certainly do this. You would use four match registers to define on and off times for each of two outputs.
 
Whether this is possible will depend on the particular microcontroller’s PWM function.

The PWM in the NXP LPC microcontrollers can certainly do this. You would use four match registers to define on and off times for each of two outputs.

Thanks. What would you call this function so that I can look for it on other micros? or does it not have a specific name?
 
I don’t think there’s a specific term.
The LPC document I looked at makes a point of it being useful for 3-phase motor control, so that might be something to search for.
What microcontrollers are you considering?
 
What microcontrollers are you considering?

I was hoping to use something of the PIC family, because thats what I've got a little bit of expierence with
I've also got some of the new Pi picos to mess about with because they looked interesting
 
Back
Top