Hot!Advice on Power Output sharing between PWM Outputs

Page: 12 > Showing page 1 of 2
Author
davez
New Member
  • Total Posts : 21
  • Reward points : 0
  • Joined: 2015/12/11 01:04:29
  • Location: 0
  • Status: offline
2017/10/10 21:51:09 (permalink)
0

Advice on Power Output sharing between PWM Outputs

Hello,
I have a project that needs to drive 2 1100 watt heating elements. I want to be able to select which element has priority, so the element with priority will heat until its setpoint is reached (using PWM), then the second heater will use any time available, that the first heater is not using.
 
For example, PWM period is 250ms, the heater with priority is approaching setpoint, and the dutycycle is say at 10%, so,  I want the non-priority heater to be able to use the available 225ms (time available until the period has expired).
 
Once both heaters are up to setpoint, they will continue to share the time available, with the priority heater getting as much time as it needs to maintain setpoint, and the non-priority heater only getting the leftover time (so, the non-priority heater might never get to setpoint)
 
I am trying to drive these 2 heaters off a single 120VAC, 15 Amp breaker, which is why I need to stagger the run times. Once up to temperature, each heater will only require a small fraction of the time period to maintain setpoint (Like maybe on 10% of the time)
 
I am trying to implement this in a 24FJ1024GB606, using OC5 and OC6.  Ideas??
 
 
#1

24 Replies Related Threads

    maxruben
    Super Member
    • Total Posts : 3132
    • Reward points : 0
    • Joined: 2011/02/22 03:35:11
    • Location: Sweden
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/11 14:38:52 (permalink)
    0
    I am not familiar with the exact behavior of the PWM counters in PICs but you should be able to have one output active from count 0 up to the desired duty cycle count and by inverting the other output, making it active from count X up to period count. By making sure that the second compare count is always higher than the first, both outputs will never be on at the same time.
     
    /Ruben 
    #2
    davez
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2015/12/11 01:04:29
    • Location: 0
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/11 20:56:38 (permalink)
    0
    Thanks for the reply, If I understand what you are proposing, sounds like you are describing a power "sharing" solution? (drive heater A, shut it off, drive heater B, shut it off, start over?)
     
    I am looking to have heater A get up to 100% of the available power, but if it only requires for example 50 % duty cycle to maintain heater A,  use the other 50 % (or however much it needs) for heater B.
     
    Also, the program also needs to be able to switch priority, so sometimes Heater B needs to get dibs on the available duty cycles.
     
    Actually, after re-reading your post, I think I know now what you probably meant. Yes, I will try to work with that.  I have read over DS70005159A, and have some other idea's as well, will update how it works out...
    #3
    maxruben
    Super Member
    • Total Posts : 3132
    • Reward points : 0
    • Joined: 2011/02/22 03:35:11
    • Location: Sweden
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/12 12:11:45 (permalink)
    0
    davez
    Thanks for the reply, If I understand what you are proposing, sounds like you are describing a power "sharing" solution? (drive heater A, shut it off, drive heater B, shut it off, start over?)

    Yes, drive heater A to the desired PWM duty cycle and use the rest for heater B. By inverting the output for heater B it will be active from count X to the end of the period while heater A will be active from count Y to the count that represents the desired duty cycle. Count X is always higher than count Y. Only drawback is that there is no dead band between heater B off to heater A on. Perhaps there is a mode where you can set both start count and end count.
     
    davez 
    Also, the program also needs to be able to switch priority, so sometimes Heater B needs to get dibs on the available duty cycles.

     
    Calculate both the desired count X and Y and then if count X is higher than count Y either limit count X or count Y depending on which will have priority.
     
    This method is all relying on that both PWM outputs are synched to each other (using the same timer perhaps) and both have the same period time.

    /Ruben
    #4
    Ewerning
    Super Member
    • Total Posts : 77
    • Reward points : 0
    • Joined: 2017/09/08 11:02:31
    • Location: Between 1 and 0
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/12 13:22:17 (permalink)
    0
    A possible solution is to use a pwm module for the heater A, generate an interrupt when it turns off to turn heater B on and use a ccp compare to generate the pwm (or better speaking, generate a monostable) for the heater B, limiting its maximum to the rest of time available from A.
    TimeB=min( PWMb%;(1-PWMa%))*T_period
    #5
    davez
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2015/12/11 01:04:29
    • Location: 0
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/12 18:16:26 (permalink)
    0
    maxruben
     
     
    Calculate both the desired count X and Y and then if count X is higher than count Y either limit count X or count Y depending on which will have priority.
     
    This method is all relying on that both PWM outputs are synched to each other (using the same timer perhaps) and both have the same period time.

    /Ruben




    You can easily sync both PWM to the same sync source, thanks, I believe I will give this a try..
    #6
    davez
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2015/12/11 01:04:29
    • Location: 0
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/12 18:23:23 (permalink)
    0
    Ewerning
    A possible solution is to use a pwm module for the heater A, generate an interrupt when it turns off to turn heater B on and use a ccp compare to generate the pwm (or better speaking, generate a monostable) for the heater B, limiting its maximum to the rest of time available from A.
    TimeB=min( PWMb%;(1-PWMa%))*T_period



    I looked into using the Interrupts, near as I can read into it, the Interrupt can only be generated when the cycle is complete (the next cycle after OCxRS match, or the next cycle after PRx match (whichever comes first).  Would be able to do what you are suggesting (and was my first thought as well) if you could get an interrupt at OCxR match, but, documentation specifically says there is not an Interrupt generated at OCxR match event.
     
    Thanks for the reply though, definitely appreciate the assistance
    #7
    NKurzman
    A Guy on the Net
    • Total Posts : 15083
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/12 20:30:17 (permalink)
    0
    You can feed the PWM Output to an external interrupt using the PPS.
     
    I like inverting the second PWM  Then it would be inversion of the First.  You could even add a little dead band.
    #8
    davez
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2015/12/11 01:04:29
    • Location: 0
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/12 23:05:20 (permalink)
    0
    So, this is what I did.
     
                OC5R = dutyCycle[0];

                OC6R = OC5R;

                (OC6R+ dutyCycle[1]>=0x2000)?(OC6RS = 0x2000):(OC6RS = OC6R + dutyCycle[1]);


    OC5 is heater 1, OC6 is heater 2, dutyCycle[0] drives heater 1, dutyCycle[1] drives heater 2. 0x2000 is the period.
     
    OC5 is setup as edge aligned PWM, and OC6 is set up as center aligned. (havn't tested switching these around yet, for the priority switch, might cause problems?) Maybe try setting both as center aligned?
     
    I haven't exhaustively tested yet, but I have run ran it in the actual project, with a scope attached, & all appears to work fine.
     
    Still have to account for priority, but that should be easy...
     
    I am still pretty green at this game, does this look OK??
    #9
    davez
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2015/12/11 01:04:29
    • Location: 0
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/12 23:14:08 (permalink)
    0
    NKurzman
    You can feed the PWM Output to an external interrupt using the PPS.
     
    I like inverting the second PWM  Then it would be inversion of the First.  You could even add a little dead band.


    Could you explain the "feed the PWM Output to an external interrupt using the PPS" in a little more detail? I am using the dedicated OCx peripherals (OC5 and OC6), and the PC board  is already built, so, if you mean switching to an PPS  OC Pin, it is too late for that.
     
    #10
    Chris A
    Super Member
    • Total Posts : 753
    • Reward points : 0
    • Joined: 2010/07/20 04:37:07
    • Location: 0
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/13 03:35:10 (permalink)
    0
    As the PWM required is 250ms in this case, this could easily be done with code instead of H/W!  But it would be a shame not to use all the OCx :-)
    #11
    davez
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2015/12/11 01:04:29
    • Location: 0
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/13 11:03:24 (permalink)
    3 (1)
    Chris A
    As the PWM required is 250ms in this case, this could easily be done with code instead of H/W!  But it would be a shame not to use all the OCx :-)


    Yes it certainly could, and, when I first began this project, I originally coded it in software, using a much smaller processor. The project kept growing in scope, and soon enough, I was running out of program space, so, I moved the PWM to hardware to recover some program space.
     
    The project kept growing in scope (including, adding a second heater), which necessitated a move to a larger processor, so, I thought, why bother switching back to software PWM, just because it is easier? Rather, try to learn something new with the Hardware?
    #12
    al_bin
    Super Member
    • Total Posts : 112
    • Reward points : 0
    • Joined: 2011/02/11 06:28:47
    • Location: 0
    • Status: online
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/13 11:27:45 (permalink)
    0
    24FJ1024GB606 has CLC.
    So use two classic PWM, but route no priority output  throuhgh AND gate with inverted priority PWM signal.
     
    Albert
    post edited by al_bin - 2017/10/13 11:31:21
    #13
    NorthGuy
    Super Member
    • Total Posts : 4583
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/13 11:52:27 (permalink)
    0
    I think you overcomplicate things. You don't need any PWMs, just simple logic.
     
    First, create a function which makes determination:
     
    int it_is_a_good_idea_to_turn_heater1_on() {
      return (heater1_temperature <= heater1_setpoint); // or use PID here
    }

     
    Same for heater 2.
     
    Then run the following code every few seconds:
     
    if (it_is_a_good_idea_to_turn_heater1_on()) {
      heater2_off();
      heater1_on();
    } else if (it_is_a_good_idea_to_turn_heater2_on()) {
      heater1_off();
      heater2_on();
    } else {
      heater1_off();
      heater2_off();
    }

    #14
    davez
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2015/12/11 01:04:29
    • Location: 0
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/13 12:31:20 (permalink)
    0
    NorthGuy
    I think you overcomplicate things. You don't need any PWMs, just simple logic.
     
    First, create a function which makes determination:
     
    int it_is_a_good_idea_to_turn_heater1_on() {
     
      return (heater1_temperature <= heater1_setpoint); // or use PID here
     
    }

     
    Same for heater 2.
     
    Then run the following code every few seconds:
     
    if (it_is_a_good_idea_to_turn_heater1_on()) {
     
      heater2_off();
     
      heater1_on();
     
    } else if (it_is_a_good_idea_to_turn_heater2_on()) {
     
      heater1_off();
     
      heater2_on();
     
    } else {
     
      heater1_off();
     
      heater2_off();
     
    }





    These PWM for these heaters is being driven by a PID control scheme (I now realize, I should have mentioned that, but in my limited brain capacity, it seemed obvious (to me) at the time), which would nearly 100% of the time (at least once the system stabilized) require at least a few PWM cycles to maintain setpoint, so, effectively, heater 2 would almost never be driven.
    #15
    davez
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2015/12/11 01:04:29
    • Location: 0
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/13 12:39:07 (permalink)
    3 (1)
    al_bin
    24FJ1024GB606 has CLC.
    So use two classic PWM, but route no priority output  throuhgh AND gate with inverted priority PWM signal.
     
    Albert


    This looks like a very promising solution, I have not used the CLC before, but, like mentioned in a previous post, more exposure to new stuff just means more knowledge! Will definitely look into this, might be the most elegant solution proposed so far. Thanks for your input!
    #16
    Ewerning
    Super Member
    • Total Posts : 77
    • Reward points : 0
    • Joined: 2017/09/08 11:02:31
    • Location: Between 1 and 0
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/13 12:59:39 (permalink)
    0
    davez
    ...
    Will definitely look into this, might be the most elegant solution proposed so far. Thanks for your input!


    Really interesting proposal, just not to overstress PID2 with error when PID1 moves (and so keep both independent from each other, since they have enough to care about and introducing noise is never a good idea), make the time for PWM2 be additional to PWM1

    Time_PWM1=Out_PID1;
    Time_PWM2=Time_PWM1+Out_PID2;
    if(Time_PWM2>0x2000) {
    Time_PWM2=0x2000
    }
    #17
    NKurzman
    A Guy on the Net
    • Total Posts : 15083
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/13 15:34:46 (permalink)
    4 (1)
    Are those pins capable of being set to be an external interrupt input? A PPS pin can be a PPS output and multiple PPS inputs at the same time.
    #18
    Bob White
    Super Member
    • Total Posts : 147
    • Reward points : 0
    • Joined: 2010/11/06 19:52:38
    • Location: Denver, Colorado
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/14 15:46:18 (permalink)
    3 (1)
    Given the very slow PWM frequency (4 Hz, 250 ms period), I think I would code this as a state machine.
     
    There are three valid states:
    1: Heater 1 Off, Heater 2 Off
    2: Heater 1 On, Heater 2 Off
    3: Heater 1 Off, Heater 2 On
     
    Start in State 1. Enter State 2 at the beginning of the PWM pulse and stay there for the length of the PWM pulse.  Check during that time whether or not Heater 2 needs to be on.
     
    At the end of the PWM pulse exit State 2 and enter either State 1 or State 3 depending on whether Heater 2 needs to be on.
     
    If you entered State 3, exit to State 1 if Heater 2 turns off before the end of the !PWM pulse or if Heater 2 is still on when !PWM pulse ends turn off Heater 2 and exit to State 2.
     
     
    #19
    qhb
    Superb Member
    • Total Posts : 6257
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Advice on Power Output sharing between PWM Outputs 2017/10/14 17:08:42 (permalink)
    0
    Interesting idea Bob, But you're essentially disabling the PWM, and forcing it to run 100% heater 1 or heater 2.
    That could work if the system has a lot of thermal inertia, that's up to the OP to decide.
     
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2017 APG vNext Commercial Version 4.5