Shop OBEX P1 Docs P2 Docs Learn Events
PWM multi phase / multi output? — Parallax Forums

PWM multi phase / multi output?

Does anyone know a snippet or an object or general outline of how to go about PWM on multiple pins, medium frequency, with multiphase?

I have started a project that involves very high power density LED's. These are not your run of the mill bright lights, the RGBW can consume 2A per color and the big white one, a CREE XHP70 can suck down up to 4.8A@4000+Lumens. I have been playing around in AVR land for a few years, a bit rusty at SPIN, but I think the prop will be well suited to help get my prototype off the ground. I'll keep scouring the internet for some kind of example I can implement with the sync.

Comments

  • What frequency and how many bits (per color)? I recently helped a friend with a giant RGBW LED like this. In that case we used two cogs, each was using a two counters to generate PWM signals. With Spin (easy code) you can get up to about 30kHz without any problems.
  • I think anywhere from about 1KHz to 30KHz would be fine, the multi-phase implementation part eludes me ATM..
    8bit would be plenty per color at 4 colors. My idea is to use one 2A power supply and do a trick similar to POV (only the colors move, not the LED)

    How to keep similar frequency but fire the LEDS one after another at different duty?
  • -edit:
    Tried looking in the OBEX-ALL, display all, CTRL+F "pwm".. Took a few minutes for the page to finally load looking for any example of multi-phase pwm.
    Or did I just confuse myself?
  • jmgjmg Posts: 15,173
    ... can suck down up to 4.8A@4000+Lumens..

    How many of these are there ?
    With lots at this power, you could need local Power switching, and at 5.8V & 4.8A/LED you could have multiple power loops.

    One example would be a 34.8V power backbone, and each led has a fixed 1:6 PWM from that
    Done with care across 6 LEDS, the backbone has no large current breaks, it always 'sees' a 4.8A load, (167W) and that cuts RFI and greatly reduces cap ripple current.

    Another PWM/SMPS regulates the 34.8V level.

    Next step from that, is a PWM setting per led, which is done as a % of the drive of a hex-set & total average power is under the backbone SMPS.

    A Prop can place edges to 12.5ns granularity, with a minimum edge-edge delay of 10 Sysclk IIRC.




  • Sorry for the confusion
    I have two very special prototype "lamps"
    each "lamp" has a CREE XHP70 and one Luminus SBM40 RGBW (2 LEDs)
    I'm attempting to have 2 constant current supplies per "lamp", 1 for the RGBW @ 2A (each color can do 2A) and another to deal with the XHP70 at 4.8A in 6V config
    The CC supplies run off of 13.8V and are linear at this stage in prototyping for easier troubleshooting and less $$, don't care about efficiency, only stability right now as these RGBW LED's are early engineering samples and VERY hard to get ahold of.

    The XHP70 PWM channel matters not, it will be on it's own supply
    Trying to use one CC supply per RGBW LED using staggered phase PWM (they fire one after another in succession)
    ..of course if this type of software PWM MultiPhase can be implemented on the prop (which I think is totally possible)

    I'm just looking for a kick in the pants as per the right direction the code should go down (a bit rusty with SPIN)

    Thanks again for ideas
  • think i got it...
    OUTLINE:
    eg:
    1024 clocks per cycle
    clk 0-255 = duty on RED PIN
    clk 256-511 = duty on GRN PIN
    clk 512-767 = duty on BLU PIN
    clk 768-1023= duty on WHT PIN

    rinse and repeat of course with a way to change these duty
  • jmgjmg Posts: 15,173
    looks good, but keep in mind the Prop has a min dT it can support, so the dynamic range is not quite 256:1
    - smallest PWM is ~ 4% of full scale @ 256 or 1% at 1024 (still ultrasonic), or 0.5% at 2048 etc
    This can be compensated for with additional overall average settings, ie a DAC on the current source value.
  • AribaAriba Posts: 2,690
    1024 clocks will not work with Spin, this would be 80kHz repeat freq.

    The following code generates 4 PWMs with 2500 clockcycles each. This results in 8 kHz loop frequency.
    You are aware that such a technik allows only 25% pulsewidth max. for every PWM channel ?
    CON
      _clkmode  = xtal1 + pll16x
      _xinfreq  = 5_000_000
    
      PIN1 = 16          'first pin of 4 contiguous PWM out pins
    
    VAR
      long  pw1,pw2,pw3,pw4             'pulswith 0..2500 each
      long  stack[10]
    
    PUB Main
      cognew(MultiPWM,@stack)           'start PWM on pins 16..19
      repeat
        pw1 := 100
        pw2 := 500
        pw3 := 1000
        pw4 := 1500
    
    PRI MultiPWM : time
      dira[PIN1+3..PIN1] := %1111
      ctra := %00100<<26 + PIN1+3       'NCO mode
      frqa := 1
      time := cnt                       '4*2500=10000 clks = 8kHz PWM freq
      repeat
        waitcnt(time += 2500)
        ctra -= 3                       'select first pin
        phsa := -pw1                    'first pulse
        waitcnt(time += 2500)
        ctra++                          'second pin & pulse
        phsa := -pw2
        waitcnt(time += 2500)
        ctra++                          'third pin & pulse
        phsa := -pw3
        waitcnt(time += 2500)
        ctra++                          'fourth pin & pulse
        phsa := -pw4
    

    Andy
  • a few years in C++ land and i'm back to zero with the prop :confused:
    Ariba , good to see you and the OG's are still around.
    The 1024 "clocks" was meant as 100uS.. 1mS.. kind of program clocks does not have to be system clocks
    but your structure kind of makes sense to me, but i'm rusty at spin. That is a good starting point for me though, thank you for the great demo to understand. It's like I have a cup of brain and a gallon of knowledge haha.
  • Ah, sorry Andy, I've had a head cold since before Christmas. I just now understood what it is that you were getting at with the 25% duty cycle on any channel.. good pointon that. This would have the same effect as putting 0.5A through a color vs the full output of 2A per color. Back to the think tank I guess.
  • The technique I use in Tachyon is to have a wave table of longs which is read at around a 2MHz rate to give up to 32 channels of 8-bit PWM at 7.6kHz. Since this is table based you have precise control of phase, duty cycle, sub-frequency, in fact each waveform.
  • Peter? was your Tachyon PWM sequential in nature? Had thought up another way to possibly PWM high power LEDs by way of a "divided" DUTY were as if the pulse was longer than say 4, the pwm would still be 4 counts, but divided over the period and so on.
    I was looking for a way to save transistors (and heat) on my prototype light project by cutting the needed 2A constant current channels x8, but as Ariba pointed out effectively a 4 channel PWM object would have the effect of only having 25% duty per channel, per cycle or 1/4 of the total power I could be feeding the LED's.

    No way around physics I suppose, power in = power out. There are examples over on the AVR side of logarithmic LUT's for adjusting the brightness curve of LED lighting in an S-shape curve so that the LED's dim nearly linearly to the human eye using traditional PWM. I wonder if a divided PWM would be beneficial in the linearity of LED dimming.. The prop is beyond fast enough for such a trial.
  • jmgjmg Posts: 15,173
    edited 2016-01-01 01:36
    Peter? was your Tachyon PWM sequential in nature?
    What Peter described, is a simple Array dump, you have a array of say 256 x 8/16/24/32b wide, and that array is simply copied in parallel, to many port pins.
    All PWMs can change at the same time, if needed.
    You do need to (re) fill the array in columns, with each PWM update - so the ease of playback, comes at some house-keeping cost.
    I was looking for a way to save transistors (and heat) on my prototype light project by cutting the needed 2A constant current channels x8, but as Ariba pointed out effectively a 4 channel PWM object would have the effect of only having 25% duty per channel, per cycle or 1/4 of the total power I could be feeding the LED's.
    No way around physics I suppose, power in = power out.
    Yes, average powers must balance, but you can do sequential pulse PWM to 4 LEDs, where each has a Max of 25%, fine, if you compensate for that 25% with a higher current source. (and are careful to never drive just one LED )

    Another PWM means save power, is to use that sequential PWM, but now ratio to a brightest-led level.
    Equal times = equal LED brightness, and as the ON time of one shrinks, the % of that drops.
    The Current source is also modulated to set the Peak - this means less current switching when you do not need full brightness on any LED.
    This has wide dynamic range, without needing large PWM step counts.



  • All things are simple once they have been demonstrated but many times the simple things are the best. The array approach runs smoothly and jitter free at up to 7.6kHz for 8-bit PWM whether it is controlling one channel or 32. You can have some outputs running at a sub-multiple of the main frequency or any waveform you want over 256 bits although the array is not limited to this either. The trick is the updating method and this is very slow in Spin unless you dedicate a PASM cog for this. In Tachyon I can run a small code module from the main application cog so there is no real overhead involved.

    Here is a link to one of my posts.
  • RinksCustomsRinksCustoms Posts: 531
    edited 2016-01-05 15:26
    yeah,had much success generating waveforms on AVR @ 16MHz generating 8bit sine with 8 bit R2R DAC, it generated a usable 4V sine at like 1MHz, using direct port manipulation and a LUT on an ATMEL mega 328.
    My gripes with the prop are more than a few, it's a niche product that was pretty cool when it came out but parallax just seems to be behind the curve with keeping up with tech. :sad:

    Edit: seems that prop 2 should be arriving maybe by Xmas 2016, that is not a date! But seems like they're finalizing the design and ironing out the the last of the kinks. Looks like a very competitive and modern Prop 2 indeed with the smart pins. UART,SPI,SERIAL, 13b ADC, DAC...
  • So I can't see how an 8-bit 16Mhz load and store to register cpu compares with eight 32-bit 20mips cores etc. When the AVR does this then that is all it can do, but with the Prop we basically say "go fetch" while the other cogs continue to do their thing.
Sign In or Register to comment.