I learned today that you don't have to use a dedicated part to do high side current sensing: you can do this with plain old op amps. This was news to me, so I thought I'd write a post to introduce the other newbies to this idea.
Disclaimer: This information isn't useful for making "real" products: dedicated parts which do this can be had for under $1. This approach is of interest for educational purposes, and would be appropriate in an educational kit power supply current limiting circuit.
I was browsing
digikey and came across the
CS30. In the datasheet, they show this functional representation of how the part works:
Later, I came across a great
app note from Linear about high side current sensing, and they showed the same circuit:
I decided to throw this into LTSpice and play around with it, and sure enough it works!
However, as-is, that circuit has a few limitations. You'd have to use a rail-to-rail op amp there, because the sense voltage would be right up at VCC, and also the VCC of your circuit would be limited to what the op amp can handle. Also, you'll need a buffer on the output.
If we add in a few extra voltage dividers and op amps, we have a usable circuit:
This can be implemented with a quad op amp, 9 resistors, and a 2N3904.
I've attached the LTSpice files so you can have a play with it.
Use R3, R5, and R9, R10 to scale down the sensed voltage to ensure it is within the common mode range of your op amps. Here, I've just divided it by 2, but if your op amp supply rail is e.g. 5V, you'll want to tweak those resistors to divide it further.
From what I can tell, the ratio of R2 to R8 sets the overall gain of the sensed voltage (which now has to be combined with the voltage divider's gain to calculate the overall gain). R4 should match R2.