How can I measure -15V using the ADC of an AVR microcontroller?
I would like to scale my signal so that -15V signal voltage equals 0V at the input to the ADC and 0V signal voltage equals 5V at the input to the ADC. Vref and Vcc are 5V.
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It only takes a minute to sign up.Sign up to join this community
You'll need a non-inverting summing amplifier:
Start with the -15 V at the Vin input. Then the non-inverting input should be at 0 V, so the ratio R1/R2 should be 3/1, like R1 = 30 kΩ and R2 = 10 kΩ.
If the input voltage is 0 V then with these values the non-inverting input will be at 3.75 V, and we'll choose R3 and R4 to bring that to 5 V. Since the amplification is (R4 + R3)/R3 we can use the same resistor values: R3 = 30 kΩ and R4 = 10 kΩ.
Make sure you have an RRIO (Rail-to-Rail I/O) opamp.
This looks to me like a classic example of overspecification. Inverting a full-range signal in software is trivially easy: just 1's complement the number. (seriously) And most microcontrollers have an instruction that does exactly that.
(Just be sure to invert only the relevant bits and leave the rest '0'. This adds an extra AND instruction for bit-widths that are not multiples of the CPU size.)
Given this information, it no longer matters whether the front-end amp is inverting or not, as long as the software knows which it is. This adds some freedom to the hardware side.
Given that freedom, I would recommend an inverting amp for this application because it can be configured easily to read an input that is outside its own power supply, like this:
R1/R2 provide a reference that is just enough off the rail that the amp can control to it. Read the datasheet and adjust accordingly.
Ri/Rf are the standard feedback network, configured for a gain of roughly -1/3. It's a little bit less than that to account for the reference not being exactly zero. If it clips, make it a bit lower still.