Measuring current via shunt resistor in DC/DC converter (buck converter)

I have made this buck converter for dimming 24 V LEDs (I can't do it with PWM due to EMC), where I need to measure current coming out of load. Op amp is configured as differential amplifier with gain 4.7.

The problem is that current measurement is working only when mosfet is fully on. When I start switching or MOSFET is off, op amp outputs approximately 800 mV. I have no idea what is wrong. These are my parameters:

1. Switching frequency: 300-350 kHz
2. Maximum current: 2 A
3. Input voltage: always 24 V

And here is the PCB (I used wrong package for op amp so I had to rewire it above):

EDIT: I have still no idea why it is not working. As I said in the comment I have measured voltages on in- and in+ inputs of operational amplifier and it makes no sense. Output is on 800 mV while in- is at 11.16 V and in+ is at 11.02. That makes 140 mV difference. I am measuring it with my oscilloscope and there are no oscillations what so ever. But when I turn MOSFET ON, 800 mV collapse to right value (depends on load).

• Technically, you still are doing it with PWM. A buck converter is basically just a PWM'd power switch followed by a filter. Jan 2 at 18:20
• According to the datasheet it should be able to take CM voltage up to Vcc-1.5 V, which should cover your needs. Can you show an oscillogram of how IN+, IN- and out looks? Jan 2 at 20:03
• Thanks for asking. On IN- is 11.16V and on IN+ 11.02. So around 140 mV difference. I have measured this when mosfet was 100 % turned off when circuit was in steady state. Also I have already switched op amp for new one to be sure it's not broken but problem persists.
– andz
Jan 2 at 22:07
• You need to add @username for people to be notified, so I missed this one. How about when switching, how does the oscillogram look? Anything odd? Jan 6 at 20:03
• I recommend the INA series of precision shunt amplifiers from TI. They are purpose-made for this application and work extremely well compared to an entirely discrete solution. Jan 7 at 16:19

Summary - it's likely a mixture of op-amp weaknesses, differential resistor mismatches and, possibly ripple artefacts from C6.

The problem is that current measurement is working only when mosfet is fully on.

Yes, that makes sense. That should be OK.

When I start switching, op amp outputs approximately 800 mV. I have no idea what is wrong.

At 300 kHz to 350 kHz switching, your AS321 op-amp is basically close to useless as a precision measurement asset: -

It has an open loop gain of around 7 dB and this is nowhere near high enough to resolve the peak current taken during the period where the MOSFET is conducting. But there's other problems...

Differential resistor mismatches

When the MOSFET is fully on, the voltage at $$\OUT-\$$ is down at GND volts and, that's fine because any slight/tiny mismatch in the differential amplifier resistors will not cause a significant error. However, when the MOSFET is switching and the $$\OUT-\$$ node is up at (say) 20 volts, there will be a significant error caused by even the slightest mismatch between R15, R16, R17 and R18. This is a very common problem with differential amplifier circuits of this type.

To verify this, what you can do is apply an external DC voltage onto $$\OUT-\$$ (MOSFET inactive). Vary that applied voltage from 0 to 20 volts and note how the op-amp output also varies.

Even a 0.1% difference between those resistors could produce a significant error voltage on the op-amp output as the voltage applied to $$\OUT-\$$ rises up to 20 volts. Here's a simulation showing the scenario of no load current and the voltage changing at node $$\OUT-\$$ (I call it CM voltage below because that's the better phrase to use). The op-amp is ideal so no errors from that bad-boy: -

The above simulation used 1% tolerance resistors in their worst-case positions and extremes.

Possible ripple voltage problems

The 470 μF capacitor (C6) that is intended to smooth the voltage across the LEDs will have an internal ESR (effective series resistance) of maybe 0.5 &ohm and this will produce a significant ripple voltage on both measurement limbs of the differential amplifier. And, it's quite possible that this ripple voltage (at 300 kHz to 350 kHz) is larger than the intended voltage measurement across the shunt resistor - this ripple is also subject to the problems mentioned earlier of resistor tolerances and may induce a further error.

• Yes, but via R_SHUNT is flowing DC current only with some ripple, or no? Or is it this ripple which make amplifier going nuts?
– andz
Jan 2 at 14:03
• Also as I said, it is working only with fully opened transistor. When transistor is fully closed op amp still outputs 800 mV.
– andz
Jan 2 at 14:27
• I can't say how much ripple is going to be present and yes there will be an element of DC due to C6 but how much is ripple and how much is the average value. You might also be getting the inputs close to the upper limit stated in the data sheet. Jan 2 at 14:28
• Fully opened in EE means fully open-circuited. I think you might mean something else. We try not to use fluid valve analogies in EE because meanings are opposite. Jan 2 at 14:29
• I didn't know tho differential amplifier is so sensitive to resistor mismatch. I have learned something new at least. I can accept your answer in 3 hours.
– andz
Jan 7 at 17:04