Changing analogWrite() function frequency

If your voltage and current are not too high, there are inexpensive programmable buck converters around. In that case you don't even need separate power measurement.
Just set the output current and read the power from the buck.

Ps. you have lovely profile avatar!