# Scaling analog sensor output (0.4V to 2.7V) to full dynamic of ADC (Vref 3.3V)

I have a question regarding the scaling of analog sensor output signal.

The goal is to connect a Sharp GP2Y0A02YK0F distance sensor to a Raspberry Pi 3 B. The sensor can be run off the 5V rail of the Raspi. The output voltage differential is specified as:

And this example for a distance measuring is given:

Accordingly I expect my output from the sensor to be DC voltages between ~0.4V and ~2.75V. Each value being held for at least the duration of one measurement and for as long as the measured distance doesn't change at maximum.

As a ADC I plan to use a MCP3204 (12-Bit, 4 Ch., SPI), with the 3.3V rail of the Raspi as Vref and as single sided power supply.

To make use of the full dynamic of the ADC I would like to scale the output of the sensor and remove the offset before feeding it into the ADC.

For the scaling itself I think a non-inverting op-amp circuit should suffice. When leaving a little headroom I would go for Va=3.2/2.75=1.16.

What I don't know how to tackle is the 0.4V offset. If my signal was AC I would go for a simple high pass before the op-amp, but with the signal possibly being DC for longer periods of time, I am not sure what to do.

Your signal range is, as a percentage of the range of the ADC, 71.2%. In equivalent LSbs that is 2917 LSBs. That's equivalent to a hypothetical ADC that has 11.5 bits resolution.

So my first observation is why bother: -

Given that any ADC has a real range that can never be relied upon to be exactly 0 volts to Vref, I don't really see much of an advantage to what you propose.

But, say you used an op-amp that modified your signal to the range you believe you want, what errors are incurred in doing so? Are you going to use 0.1% resistors (10 bit accuracy) or maybe 0.01% resistors (a bit over 13 bit accuracy). Are you willing to pay for that accuracy?

Each resistor will incur an error and those errors can be assumed to accumulate. Plus, there is the error from the op-amp and it's inability to get within 10 mV to 50 mV of the supply range means you can never get the full 12 bits you desire.

So, do you stick with an 11.5 bit system or, do you design an op-amp (with significant cost for the resistors) that might give you 11.8 bits?