While working on the stability, I came to the realization that this thing can be used as a voltage reference too: the voltage across Rm1 is maintained by the mcu.
Here is an examle: R1/C1 is the lp filter, Q1 is the buffer, and RM1 is the measurement resistor. ROUT1, optional, isolates the high-impedance load from RM1.
J2 outputs a voltage reference, and J1 (when not shorted) outputs a current reference.
I have gotten the control algorihm stable across the full voltage band: 0-1.1v. The output current is determined by RM1 (in this case, 0 - 1.1ma).
In the particular case, Iout is set to 40ua, and fluctuates from 39.9ua to 40.1ua (20x adc gain used here).
Potential Improvements:
1) make it dual channel: since the mcu has two pwm channels, we can replicate R1/C1/Q1/RM1/ROUT1 and we have another channel. One can be dedicated to volt and other current; or they have different ranges.
2) improve resolution: the pwm duty cycle is being dithered to provide finer resolution. This creates fluctuation on the output. Another way is to utilize the unused tmr0 pwm channels OC0A and OC0B and add 8-bit resolution to the meter. Adding two resistors will do that.
3) use external adc: the biggest draw back here is the onboard adc. A better adc could help.
....
The meter has a range of 0 - 1.1v (limited by the reference voltage). It has a current output of 1.1ma full-scale (RM1 = 1K), and current resolution of 0.05ua and voltage resolution of 0.05mv (RM1 = 1K and 20x adc gain).
The meter has no UI and no calibration capability so it is entirely conceptual at this point. But it does suggest that something like this is doable.