I don't get the resistance.
In a 100% FET mode you can't regulate it period. We're talking about having regulated middle modes. We already have that for the all 7135 mode but it just depends how many 7135s you have on how long that can stay in regulation, and when it goes out, so do all the modes under it above one 7135. You MUST at least take into account pwming all channels even in fet modes or you just won't get this right at all, but if you don't take into acount in one way or another the 7135 output, you'll also end up with modegroups that are a confusing out-of-order mess that depends on battery level. The thing that kept them in order was leaving the 7135s on full while the FET is on, but you just can't do that now, well not without even more work to sort it out. And then you might as well just do things right:
This is what makes sense:
#define ALL7135_MAXVF // the Vf expected at the current level provided by all 7135s
#define ONE7135_MAXVF // the Vf expected at the current level provided by one 7135s
target_vf=vf_targets[mode_idx];
while (1){
actual_voltage=get_voltage();
if(target_vf>actual_voltage) {// Set a target we can actually reach. Correct for voltage sag next time around.
target_vf=actual_voltage; // better yet would be to lock out a mode once the target_vf of the next lower mode is>= voltage
}
if (target_vf>ALL7135_MAXVF){ // More than 7135's can handle, use everything.
PWM=light_output(target_vf)/light_output(actual_voltage);
PWM_ALL_CHANNELS(PWM);
} else if (target_vf > ONE7135_MXVF){// Using all 7135s
// compare desired light to what we'll actually get at the lesser of this voltage or the max 7135 voltage
// Note if target_vf is set equal to ALL7135_MAXVF we'll still have a no PWM mode.
PWM=light_output(target_vf)/light_output(actual_voltage);
PWM_ALL7135s(PWM);
} else { // Using one 7135
.. ok using voltage down here in the weeds probably doesn't make much sense.
.. just translate these to fixed single PWM levels.
}
// loop to keep up with voltage sag and drain.
}
light_output is the normalized lumens expected at a particular Vf. We rarely see this curve actually, but we have vf vs current curves and current vs light curves so you can combine them and work it out. I've never seen it.
The ratios are the thing to be approximated and can probably be done by
255-(actual_voltage-target_vf)*LED_CAL
Instead of by division.
It seems that multiplication by a constant isn't very expensive. The optimizer works out a a fixed algorithm for it.
I think it's multiplication or division of two variables that is expensive.
The hard part here is just knowing what the Vf corresponding the current of your ALL7135s is.
That depends on how many 7135s, and both that and LED_CAL will depend on the LED in use.
If configured right this will keep all the modes in order and all regulated as long as possible.
edit: removed a redundant comparison in second conditional.