I see. One of the guys in the group noted that the proper way to do it is to use a microcontroller.
Seems a bit overkill for a simple design like this. Thanks, Whales.
It's not, actually.
The alternative is a rather pricey bit of kit (see above!), and will still only be so accurate (not that a lot of accuracy should be needed here). Plus you can hang an LCD off it and get V/I/P readouts live. Maybe you don't need those either, but given the opportunity, hey why not?
The other way is, if you well and truly don't need much accuracy, do foldback current limiting.
This is where a fraction of the load voltage, is fed back to the current sense signal, so that, while the opamp holds this signal constant, it means current drops as voltage rises. Think of the see-saw or lever action between the resistors doing this. (Also, you need a resistor between R4 and -IN anyway, for compensation. More on that later.) Basically, make a voltage divider from D to -IN to S, the top resistor being rather large (100s k?) so it has fairly little effect.
Note this raises the minimum control input, so if you want near-zero current at non-zero drain voltage, you have to bias it up a bit.
This gives a downward-sloping V(I) characteristic, which is not the hyperbolic curve of constant-power, but can be positioned to cut through it in two places, giving an approximated curve fit. The maximum dissipation is in the middle (half the design/maximum rating V, I) and can simply be positioned tangent to maximum power, or a slightly larger transistor can be used to handle the excess, and you can call it "50W capacity" on the nameplate, and just cheat that it'll sometimes be more, sometimes less.
Doing this as a limit rather than a continuous behavior, is harder; the feedback signal is small, so you can't just use two dividers and diode-OR their outputs (i.e., giving a kinked V(I) curve, flat below the power limit, but foldback above). You'll need another op-amp or two for that (precision rectifier type circuit; actually, a max(a, b) circuit, but same thing with suitable choice of reference voltages). Which also means having two op-amps in a loop, which definitely will need compensation. Which...
Compensation:
The series resistor mentioned above, is also so a capacitor can be placed from OUT to -IN; say 1k and 2.2nF are likely values, give or take a factor of 10 say (so, test values in coarse steps e.g. 1n, 2.2n, 4.7n, etc...). Also add some resistance from OUT to M2, because op-amps don't like driving capacitive loads.
Final evolution: some R+C may be desirable for the feedback capacitor, i.e. giving it substantial ESR, on the order of 1k, and again, adjusted by wide steps until you find optimal response. The goal is generally to get fast response, with little overshoot, while also being stable under all conditions. Performance shall be tested by monitoring the current response for a step (control) input, or load voltage step.
Don't expect accurate results from the simulator -- you'll want to do this IRL, for a series of load voltages.
You'll want to do this for a series of load impedances, as well! The MOSFET has significant Cdg, meaning there's feedback from the output. Load inductance in the 1-100uH range can be especially tricky. Usually an R+C from D-S or D-GND will do the job; ballpark 10R + 10nF say should be a good start.
Also for step turning-off response, you may find the drain voltage shoots up dangerously high (again, given an inductive load). A TVS from GND to D easily handles this. Something like SMAJ30A is no problem, an even smaller device is possible at these currents maybe. That's just kind of the smallest usual TVS family, heh.
Reference: I made this current limiting fuse, which features an analog current limiting function, for a brief duration (a few ms), so is doing essentially the same thing.
https://www.seventransistorlabs.com/Images/LimitingFuseSch.pngThe discrete circuit is rather hard to understand, but notice the common parts: Q7 power transistor, R15 shunt, P1-2 load terminals. R9/C4/D5 are output damping and protection respectively. R14 is the series resistor from the shunt (though this does not implement foldback, so there is no connection to drain voltage here). C7/R26 provide some feedback to the control circuit, though I think they ended up being unused in the physical build. (I do have simulation sources in here to try it out virtually -- it got pretty close, only a little tweaking was needed.)
The rest of the circuit acts as an op-amp, R18/R20 being the +IN voltage reference, R19/C5 being the compensation R+C (it's not from OUT to -IN, just because it's a bit better here in discrete form; when using IC op-amps, we simply aren't given this choice!), and Q5B/Q4A are the amp output transistors, controlling the gate (with fairly low currents, and compensation comes from an internal node, so a series resistor from OUT to G isn't necessary in this case). The rest is bias and timer logic, implementing a latching fuse behavior, also overtemp and a blinking LED for status.
Tim