Atmega32u4 differential input mode.

I've been looking for a small library for differential mode on the atmega32u4. I'm looking at the datasheet, and see it's totally doable. Up until now, I've only wrote any code from libraries without poking registers and all that. Great time to learn. :slight_smile:

This routine should read ADC1(-)/ADC0(+) differential with no gain:

int16_t read_differential() {
  uint8_t low, high;
  ADCSRB = (ADCSRB & ~(1 << MUX5));
  ADMUX = 0x10;
  sbi(ADCSRA, ADSC);
  while (bit_is_set(ADCSRA, ADSC));
  low = ADCL;
  high = ADCH;
  return (high << 8) | low;
}

Hi, thanks! I'll try it. You're awesome! The only other problem is the range of the voltage being read around the <10mV-30mV. If we adjust the gain, that'll just multiply the adc noise as well, correct? Should I add an opamp to amplify the voltage before the analog pins?

I have a high precision 2.5v voltage reference diode. I wouldn't mind finding a 1.1v if I had to. Needs to be as accurate as possible.

If we adjust the gain, that'll just multiply the adc noise as well, correct?

The same as you would with an external opamp. There is the option to use the internal 200x gain but if the signal really reaches 30mV you might ruin the hardware. You also have gain factors of 10 and 40 available but it's difficult to suggest something if you don't tell us what you plan to do.

Sorry for the lag... I've literally been working from 7:30am until 9:30pm...

I'm working on a simple ohmmeter with oled display. All extra parts I have in the garage. I have an lt3092 constant current source configured at 10ma since it's going to be on battery power. I need to check the actual mV range, but it's pretty low from reading it with a meter. Would like it to read from 0.01Ω-3Ω or so.

I see what you mean about the opamp VS the gain adjustment. Either way it would amplify the noise. I was thinking maybe the noise was coming from the ADC itself. Say the amplified voltage was 2v going into the adc. If there was 20mv(just an example) noise, it wouldn't be so bad. If it needed to read 20mV with 20mV noise, it's no good. I'm just new to all of this. Thanks for the confirmation on that. :slight_smile:

I wish I had more time to read about all this, but if the internal gain does the same thing, I'll test it out. If you have any other ideas for me, I'm all ears. I've googled quite a bit and read up, but this 4 wire measurement isn't something I've seen many people do with this MCU.

I really appreciate the code as well. Hopefully this weekend I'll get to make some progress.

I'm just new to all of this. Thanks for the confirmation on that.

I'm not a specialist with these things but as far as I understood it, the noise is built by your circuit. If you design your circuit carefully and shield it as much as possible your should be able to keep the noise low. The ADC doesn't introduce noise but it might have a small measurement error.

Would like it to read from 0.01Ω-3Ω or so.

How do you take care that the voltage is within the range you design the amplifier gain?

Could you explain me.. what this code is doing?

@randybonnette: Your question has absolutely no relation to this thread. Please open your own thread and don't hijack a thread several years old. In your thread provide the needed information, so please read the sticky post "How to use this forum - please read" at the top of the board.