1. Visiting from the US? Why not try DIYnot.US instead? Click here to continue to DIYnot.US.
    Dismiss Notice

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

Discussion in 'Home Automation' started by Adam_151, 16 Feb 2021.

  1. Adam_151

    Adam_151

    Joined:
    17 Jun 2004
    Messages:
    6,698
    Thanks Received:
    280
    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
     
  2. Sponsored Links
  3. bernardgreen

    bernardgreen

    Joined:
    3 Nov 2006
    Messages:
    25,819
    Thanks Received:
    2,568
    Location:
    Bedfordshire
    Country:
    United Kingdom
    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
     
  4. Adam_151

    Adam_151

    Joined:
    17 Jun 2004
    Messages:
    6,698
    Thanks Received:
    280
    Country:
    United Kingdom
    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
     
  5. bernardgreen

    bernardgreen

    Joined:
    3 Nov 2006
    Messages:
    25,819
    Thanks Received:
    2,568
    Location:
    Bedfordshire
    Country:
    United Kingdom
    These often use LED elements with current setting resistor and reverse polarity protection integrated into the LED element.
     
  6. Sponsored Links
  7. endecotp

    endecotp

    Joined:
    2 Dec 2013
    Messages:
    3,949
    Thanks Received:
    507
    Country:
    United Kingdom
    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.
     
  8. Adam_151

    Adam_151

    Joined:
    17 Jun 2004
    Messages:
    6,698
    Thanks Received:
    280
    Country:
    United Kingdom
    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?
     
  9. endecotp

    endecotp

    Joined:
    2 Dec 2013
    Messages:
    3,949
    Thanks Received:
    507
    Country:
    United Kingdom
    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?
     
  10. Adam_151

    Adam_151

    Joined:
    17 Jun 2004
    Messages:
    6,698
    Thanks Received:
    280
    Country:
    United Kingdom
    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
     
  11. DIYnot Local

    DIYnot Local

    Joined:
    3 Sep 2019
    Country:
    United Kingdom

    If you need to find a tradesperson to get your job done, please try our local search below, or if you are doing it yourself you can find suppliers local to you.

    Select the supplier or trade you require, enter your location to begin your search.


    Are you a trade or supplier? You can create your listing free at DIYnot Local

     

Share This Page