# Tahmid's blog

## Total Pageviews

I am currently a PhD student at UC Berkeley, following a 6-year journey working at Apple after my undergrad years at Cornell University. I grew up in Dhaka, Bangladesh where my interest in electronics was cultivated, resulting in the creation of this blog.

## A low-cost high-side current sense amplifier: design considering non-idealities

Current-sensing is commonly used in power electronics and embedded systems, both for system monitoring, as well as to take decisions. Examples of common use cases for the latter are:
1. Monitoring inductor current for current-mode control in power converters
2. Monitoring converter current for overcurrent protection
3. Reading battery charge current to inform the charging process
4. Reading output current to compute output power to inform how to proceed in an MPPT charge controller
Use cases 1 and 2 require high-speed current measurements since they need to operate at either the converter's control frequency or based on a desired response time. Use cases 3 and 4, however, only require measuring "DC" current and so don't require high-speed current sense. The high-speed aspect ties to notions of slew rate and bandwidth for the amplifier. Other non-idealities, which I will describe here, affect even the DC behavior of the amplifier.

## High-Side vs Low-Side Current Sensing

This article gives a good overview of the differences between high-side and low-side current sensing. Shown below are what they look like.

(a): High-side current sense
(b): Low-side current sense

### Sense Resistor Selection

In both cases, the sense element is the series resistor Rs. By monitoring the voltage drop across Rs, you can compute the corresponding current from Ohm's Law: V=IR.

Tradeoffs for resistor selection include considerations for power and minimum sense voltage.
• Power dissipation in the resistor is given by Irms2Rs. A larger resistor will correspond to larger power dissipation for the same current.
• Using a small resistor corresponds to a smaller sense voltage. When using a small sense resistor, you will use a current sense amplifier (CSA) to amplify the small sensed voltage to feed the corresponding circuit, which is often an ADC. A smaller resistor will correspond to requiring a larger gain in the amplifier or a greater ADC resolution.

### High-side vs low-side

High-side current sense refers to placing the sense resistor in the "power" side without disrupting the power return or ground, enabling  the use of a common ground overall circuit scheme. Low-side current sense refers to placing the sense resistor in the "ground" side, thereby disrupting the power return/ground. If common-ground is not desired for your application, you can use the low-side sense scheme.

In this article, we're looking at applications where you prefer high-side current sense!

## Non-idealities Considerations and Circuit Design

In this application, I'm focusing on using a standard ultra-cheap op-amp instead of a dedicated current sense amplifier (such as INA180).

The op-amp I'm picking for this is the TL082 which I have on hand. The amplifier design is based on a standard differential amplifier configuration as shown in this article. The datasheet for the TL082 can be found on the TI website [1] [2]. LCSC shows the ultra-low cost of < \$0.20 at volume!

The schematic for the current-sense amplifier (CSA) is shown below.

CSA implementation circuit (click to enlarge schematic)
VSNS+ = 12V

There are 3 parts to the output to consider:
1. VREF biases the output to 5V. Errors in the 5V reference will propagate to the output.
2. The diffamp gain is given by R3/R1 assuming R1=R2 and R3=R4. The input to the diffamp is given by the voltage across the sense resistor, which is the product of the current through it and its resistance.
3. The slope of the output voltage against current is negative due to the diffamp having negative gain. This is by design. See below.

We need to consider the amplifier non-idealities when designing the part. The ones we are considering, along with their impacts is shown below.

1. Input offset voltage
• This is a mismatch in the input voltage of the op-amp, due to the input-side design of the op-amp itself. This gets amplified and shows up as an error on the output. The TL082 is specced at 5mV typically. With our amplifier's gain of 5.6/2.2=2.54, this means that this offset shows up at the output as ~12.7mV. Given that our system's current gain magnitude is 1.27V/A, this corresponds to a 10mA error in current reading.
• Note that the offset can be positive or negative.
• Additionally, the offset varies over part tolerances and temperature, going up to as much as 20mV, which will correspond to closer to 40mA of error.
• Whether this is a problem or not depends on your application and desired current sense accuracy. You can perform an offset calibration to try to get rid of the steady-state error and only have to worry about the smaller temperature-dependent offset error. Alternately, you can use an opamp such as the TL081 which has additional pins to allow for offset nulling.
• Better opamps with lower offset can be used if the offset is an issue and cannot be solved by calibration.
2. Input bias and offset current
• A large input bias current will correspond to voltages dropped across R1 and R2, which will correspond to errors in the sensed voltage. The TL082 has bias currents in the 50pA-8nA range. Since this shows up on both inputs on this amplifier, the impact will depend on the mismatch between the input resistors. This will not be an issue in this particular application. In a low-side current-sense amplifier, the bias will show up differentially since one side will likely be grounded, so you will need to be more careful there.
• A large input offset current will correspond to mismatch in this voltage dropped across the input resistors, which will get amplified and show up as an error on the output. The TL082 has an input offset current spec between 25pA-4nA. The impact of this is the same as for the input offset voltage. Given that the input offset voltage spec is worse than this corresponding offset, this can be ignored for this application.
• The design will tend to get more sensitive to bias/offset current if you use larger input resistors, so you should be careful about that.
3. Input common-mode voltage range
• Rail-to-rail opamps allow the input voltages to go as high as the supply voltage and as low as the supply return. However, the TL082 is not a rail-to-rail opamp, so you need to be careful about making sure that the input voltage is within the desired spec. The datasheet outlines that the input voltage can go as high as the supply rail but can only go as low as 4V above supply return. That means that in our single-rail application, the input voltage cannot go below 4V.
• Note that this limit also means that you should not use the TL082 to buffer voltages below 4V!
• With the 5.6k and 2.2k resistors, as well as the 5V VREF, this is not a concern in our application! However, this is something to keep in mind!
4. Output voltage range
• You can notice that I flipped the + and - inputs on the op-amp relative to a non-inverting configuration. This gives negative gain, but why did I do this? By using VREF=5V, this then means that as current goes up, the output voltage will go down but will nominally be 5V. If I used VREF=0V and used a non-inverting configuration, that would result in the desired 0A output to be 0V. However, the TL082 cannot drive its output to within 200mV of the supply rail or return (or even worse if you have too low an output resistance!).
• This means that if the output sits at 200mV with no input, we cannot resolve currents below 158mA. However, if we sit at 5V, we don't have this issue since 5V is far out from either supply rail or GND!
• With a large enough current, the output still can't swing low enough, so the max current we can resolve is about (5V-0.2V)/1.27[V/A]=3.8A. Note that this would result in a large power in the sense resistor, so this is another constraint to consider!

• VSNS+ is bounded between 4V and 14.75V. The lower bound maintains the op-amp's input common mode voltage range. The upper bound is given by the op-amp's supply voltage (=12V here). VSNS+ can go higher than 12V as long as the input to the op-amp pins is maintained to be at most 12V. The op-amp voltage at its non-inverting input is given by the equation below. With the circuit components implemented, this sets the upper bound of VSNS+ to 14.75V.

• Errors in the reference voltage VREF (=5V here) will propagate to the output. These can be accounted for with an initial calibration step. For best performance, use a voltage ref chip such as the LM4040. This will give better accuracy for the voltage reference.
• You can set the VREF to a higher voltage and increase the gain.
• You can use a voltage divider at the output to rescale the output to a lower range.
• You should add a low-pass anti-aliasing filter between the current-sense amplifier's output and the next-stage ADC.

## Measurements

With steady state currents, the following output voltages were measured.
• 0.33A : 4.70V measured vs 4.58V expected : +2.6% error
• 0.94A : 3.73V measured vs 3.81V expected : -2.0% error

The input offset contributes output error - with no input, you can measure the output and find the offset. The component tolerances also contribute additional error.

For the purposes of this demonstrative application, this is deemed sufficient! In a wide range of applications, this could also be sufficient, especially in cases where the application is very cost-sensitive! I wanted to share some of the non-ideality considerations through this application and would love to hear if this has helped you understand them!

1. You are the best, Tahmid. Love you from Nigeria. Currently working on an inverter with esp32. Your tutorials are the best. I would appreciate if tor can help with feedback compensation.

I have read your recommendations from Marty brown. Some things are not clear.

2. hi tahmid, can you help me in doing a project about a DC-DC 300V inverter using SG3525 combined with an H bridge circuit using EGS002 to produce 220v AC 50hz output

1. What in particular? There are several posts on this blog that you will find relevant. A few are listed below.
- https://tahmidmc.blogspot.com/2023/12/sizing-ir2110-high-side-bootstrap.html
- https://tahmidmc.blogspot.com/2013/01/using-high-low-side-driver-ir2110-with.html
- https://tahmidmc.blogspot.com/2013/02/n-channel-mosfet-high-side-drive-when.html
- https://tahmidmc.blogspot.com/2013/05/debugging-bridge-tips-to-successfully.html
- https://tahmidmc.blogspot.com/2013/03/output-inductance-calculation-for-smps.html

2. I have done the circuit you made to increase the voltage to 300 vdc. For the H bridge circuit I use the EGS002 module. Do you have a project to make an inverter using the egs002 module?

3. I do not have any projects done with that. It seems like there are a lot of related resources online. If there is any particular aspect you find lacking, I may consider discussing that in a future blog post.

4. yeah. Of course. I would be very happy if you could do this project. where the intention in my project is that I have done DC to DC using SG3525. where the power that has been generated is 300vdc to supply the H-Bridge circuit. and the spwm signal uses the egs002 module to produce a sine wave and output voltage of 220 VAC 50HZ

5. Is there a particular aspect of this project that you think warrants further discussion? Because it seems to me that you'd use the EGS002 and an H-bridge with driver followed by a filter.
I think you'll find the following posts informative:
- https://tahmidmc.blogspot.com/2013/01/using-high-low-side-driver-ir2110-with.html
- https://tahmidmc.blogspot.com/2023/12/sizing-ir2110-high-side-bootstrap.html
- https://tahmidmc.blogspot.com/2013/05/using-tlp250-for-isolated-mosfet-gate.html
- https://tahmidmc.blogspot.com/2013/05/debugging-bridge-tips-to-successfully.html

3. yes. I would be very grateful if you want to make this project. I will wait for you in making the project

1. It's unlikely I will be doing this project near-term unless there's a particular aspect of it that I think would be interesting to discuss.

2. I don't understand other people's explanations about the spwm produced by the egs002 module. This seems like an interesting explanation

4. Hi Tahmid, I'm designing a 12vdc-330vdc dc-dc using sg3525. to generate DC-AC using spwm . Is there a difference between the grounds? please explain the ground difference

1. You can decide whether to connect the grounds between the 12V side and the 330V side. If you connect them together, you have a common reference point for signals such as gate drives but you have to be careful since the 12V side is no longer touch-safe. If you keep them separate, then you will need isolators for the signals crossing between the 12V side and the 330V side.

5. Please share your mail id I got some doubts in bldc motor switching.my mail id:jishnusuresh.2012@gmail.com

1. Please share your question here - others may find it useful too.