see attached for linked schematic

Sorry for underestimating you motivation. On the subject of doubting you built the circuit, I guess my only reply is that if you had this schematic in your possession since the beginning of your post and didn't post it or link it, but rather added it to the op amp subtractor without mentioning this schematic or linking it, there was no reason to believe that you knew the component values (since you did not provide them). That being said, thanks for finnally linking the (complete "real" )schematic. Since most new posters are newbies this one place where you don't get the "benefit of the doubt".
For better or worse, here on the forum, if you don't post it , it's because you don't know it. If you know it and don't post it , you are expected to "volunteer" to post it:
ie:
"Here's a rough sketch of the circuit. I can post the complete schematic on request"
The reason for this attitude , is that if you are posting for help. it is assumed you realize we need ALL THE INFORMATION relevant to the issue or circuit. I would think that would be obvious. How else can we help you. Anyway, now you know.
Perhaps I should have waited a week.

(I might be guilty of being impatient)
I don't have time for detailed reply at the moment but that op amp driving the fet is looking more like a comparator configuration with setpoint input on +V and Feedback on -V.
ComparatorIf V
IN=SETPOINT
V
Ref = FEEDBACK
Let Setpoint = 3.7V
Feedback = 3.705 V
If the voltage dropped across the shunt > setpoint then (the BATTERY is CHARGED)
Vin < Vref => Vout = -Vcc (0 v) FET TURNS OFF
Looks like a comparator, works like a comparator...
If it looks like duck, walks like a duck and quacks like a duck...it's a duck...
All component values shown. That's a complete schematic alright.
rom which link did you get the exact circuit that you built? I think you might be showing how circuits that are simple in the cartoons are actually difficult to implement as real schematics.
I sort of winged it. I built each section and then modified that section to work best with the others. I needed a lot of gain to amplify the shunt voltage.(
my shunt is 50 mohm,
(1/20th the resistance of the OP's shunt) The dac runs off 5V and everything else runs on 12V. The integrator was your idea.(from the Load box schematic)
I did determine that all the extra code other than the dac output code is causing the time between fet on pulses to extend. If I remove everything but dac code the fet drive signal looks like the posted screenshot. Now that I've add all the other code , this are long off times between the fet on pulses. (timing details later) If basically lowers the switching frequency.
I did some testing of the latest schematic I posted which includes the op amp subtractor and I used serial prints to indicate "Below setpoint...charging" and "Above setpoint, not charging.." By putting two 150 ohm 3 W resistors in parallel with the battery, I was able to force the circuit to hover at the setpoint , alternately charging and discharging simultaneously to observe the circuit behavior. It would alternately print "charging" and print the charging current or "not charging " and no current was drawn from the supply
(which has a current LCD display). By removing the 150 ohm load resistors, I could force the circuit to stop at the setpoint and remain there without charging. I have the Terminal Capture files of the serial prints. and I tried plotting the battery voltage but I was having a little problem with Excel so I don't have any plots yet. I'l take a look at the schematic of the "kitchen current sink" circuit and compare it to mine and see where to go from there.
I may try building the current sink to compare it's performance with my current circuit.
At is stands, I could technically say I have a current controlled battery charger that stops charging at the setpoint. The charging current setpoint is hard coded (the "current" variable)
uint32_t current_setpoint =20;
I need to generate a more detailed current lookup table. (see Reply#39 for lookup table)
Maybe the op amp is having difficultly driving the gate capacitance? The cartoons show a "gate driver" block for a reason, even though it's sometimes as simple as two resistors.
The only gate drivers I have on hand are digital TC4427s. I need a linear gate driver. I am using an
IRF730AI made the mistake of trying a Logic Level mosfet (FQP30N06 from Sparkfun) and quickly discovered it switched to on full as soon as the gate voltage reached some threshold. The IRF730?A works fairly well in the linear region. I might be able to build a gate driver using an op amp.