Atmega328 internal comparator using 100mV or so reference.

I wasn't exactly sure where this question should go.. I need to use the internal comparator to compare a low voltage of around 100mV to an input. When the input is greater than 100mV I'm going to enable an interrupt. My code is already working, but I'm working with 3.3 volt as a reference and 5v as the input to test.

My idea is to use a precision voltage reference with a voltage divider, but even with tight tolerance resistors and proper voltage reference it could still be off enough to make a difference. Anyone have a solution to use 100mV or so as a reference for a comparator?

Could you make a schematic of your circuit ? You can make a drawing on paper and make a photo of it.
Could you show us your sketch ?

You have a 3.3V reference connected to AREF ? Which voltage reference ?
The analog comparator inside the ATmega328P is pure analog. I think it should detect 1mV difference, so 100mV should not be a problem.

I would use the 1.1V internal voltage reference of the ATmega328P chip. That measures an input with 1mV resolution. At least that is something that works.

Hi, I'm using the 3.3v version of the lm4040. I was testing with the sparkfun 45a INA169 shunt monitor. It outputs 3.3v @44.7a, so it would work out like that. I'm swiching to the IN226 though, which communicates over i2c. In that situation, I could ditch the voltage reference, but it doesn't output an analog signal. The real benefit of using the INA226 is that it can detect bus voltage as well as current. That's all I need, so I wouldn't need the ADC at all.

The whole idea is for over current protection. I'm using 4x 2W 4mOhm shunt resistors in parallel. When the voltage drop across them goes over 100mV I'd like to enable the interrupt. I don't actually have the INA226 yet, but I can post everything up when I get it.

I was thinking the input had to be higher than the reference to enable to interrupt. The internal reference would be awesome, but how would that work when the input would only be up to 100mV or so?

EDIT:The INA226 has an alert pin with functions like shunt voltage over limit, which could work, but I'm hoping it's fast enough. I'm going to try that as well. I was just hoping the interrupt could be enabled as quick as possible. Looks like 140µs conversion time. Add that to the interrupt input-output time and I think it's around 263µs.

Any thoughts?

http://www.ti.com/lit/ds/symlink/ina226.pdf

As far as I know there is no 3.3V LM4040 ::) Do you need such extreme accurate current measurements ?

These are the Sparkfun breakout modules: https://www.sparkfun.com/products/12040 https://www.sparkfun.com/products/10643 Which one do you have ?

In the compare mode, there are two analog input pins. One pin is like a threshold (I [u]don't[/u] want to call it a "reference"). If the other pin is higher than the threshold, it generates an interrupt. You can do the same thing with a normal external comparator.

The reference voltage used by the ATmega chip is something else. That has to do with the AREF pin and the analogRead() and analogReference() function. This has nothing to do with the analog comparator.

When the internal analog comparator is used. One pin can be the output of the INA169. Is the output voltage zero when the measured current is zero ? I think it does. For the threshold, you need 100mV. Do you have a stable 5V or 3.3V. Then you can use that with a voltage divider (two resistors) to create 100mV.

I'm using this one: https://www.sparkfun.com/products/10643 I'm switching it up to the INA226 for sure, though.

This is the lm4040 I've used with this project so far. There's a package that has much lower tolerance, though. It's 3.3v. This one is sc70.

http://www.digikey.com/product-detail/en/LM4040DEX3-3.3%2BT/LM4040DEX3-3.3%2BT-ND/1303580

Sorry about the terminology. Using a voltage divider for the threshold goes back to my original question. It needs to be very close to 100mV. 80mV would be even better. So, would you just use the lowest tolerance voltage reference and resistors you can find?

Why do you need an accurate voltage reference ?

Is it important if you can select a trigger voltage of 100mV or 101mV ? Suppose the 5V is 5% inaccurate, and you use two normal resistors to make 80mV. Then the total inaacuracy will be 5% plus the inaccuracy of the resistors. If 80mV is needed, and it turns out to be 81mV, then just add an resistor to tune the voltage.

I don't understand it very well. Suppose you need 100.000mV, but 80mV would be better.

Let's assume that you need to trigger every time at the precise same current. Then I would use the LM4040, and use a voltage divider for the threshold voltage to an analog input of the Arduino. You would have to calculate the current for the LM4040, and choose the optimal resistor values. The internal voltage reference of the ATmega chip of 1.1V depends a little on the temperature. If that is no problem, perhaps the AREF can be used with a voltage divider instead of the LM4040. But I don't know if the AREF can supply current for a voltage divider. I have never used it that way.

The ATmega chip can use the ADC to distinguish 0mV from 1mV. I assume that the internal comparator can work at such low voltages as well. I didn't read in the datasheet that it is different for the comparator.

Ahh, I didn’t think of that. Even 5% at 80mV is nothing like you said. :slight_smile: My original use for the voltage reference was for as accurate as possible adc reads to read current and bus voltage, but since I’m switching to an i2c component I won’t be using that anymore. The project is basically an RMS voltage regulator that runs from 4-10v RMS @122hz. When I tested what my display said against my scope, the results were within 50mV RMS of the target. I was pretty impressed with it.

I’ll be powering the MCU with an LDO with better than 5% tolerance, so I could just use a low tolerance voltage divider from the output. Sound good?

I really appreciate it. You hit it spot on.

Yes, sounds good. If the LDO is 1%, then I would choose 1% or 0.5% resistors. The INA226 seems to have it all, but I can't read in the datasheet if it has an internal reference. Or is the 3.3V or 5V power supply used as reference.

I looked at the datasheet and didn't come up with an answer to the analog reference either. Thanks again for your input. I'm very excited to try it. I designed a little breakout board for the INA226. Hoping it gets here pretty soon and also hoping it works. :)

EDIT:Is there any 5v regulators that know of off the top of your head that you recommend? I've been doing some research. Need to do a bit more.

EDIT2:I'm looking at this one:

http://www.mouser.com/ds/2/308/NCP1117-D-81326.pdf