ADC input conditioning

Updates coming soon. In the meantime here are the kicad-project files for:

Kicad project files



The output of the CCD – without any circuitry – is app. 0.6V-2.5V. When placed in the drive circuit from in datasheet the output voltages are app. 1.2V-3V.

Neither of them is good match for the range of the ADC in the STM32F401RE – and then there’s the annoying thing with the inverse relationship between exposure and output-voltage.

The answer is to use an inverting op-amp as a differential amplifier before the ADC. The ADC-manufacturers have recommendations for op-amps depending on the application. I picked the AD8021 because David Allmon also used it.

Regardless of the choice, the op-amp should be used in inverting mode to fix the signal polarity, the gain should scale the input to match the ADC’s input range, and finally the signal needs to be level-shifted (so no light corresponds to 0V).

The simplest op-amp circuit I could find that does all the above, is this:


The gain is:

G = - R2 / R1

we have an input range of 1.9V, but want 3.2V (actually 3.3V but I don’t want to saturate the ADC-input), so G should be -1.68.

The level shift is:

S = R4/(R3+R4)·(1+R2/R1)·Vref

The output voltage then becomes:

Vout = G·Vin + S = -R2/R1·Vin + R4/(R3+R4)·(1+R2/R1)·Vref

There’s probably a point to the resistor values in the typical drive circuit (noise?), so R1 is chosen to be 150Ω. The gain then dictates that R2 should be 252Ω. Setting Vref to 5V (it is in the complete circuit) R3 and R4 can be found by solving:

Vout = 3.2V    when Vin = 0.6V        and
Vout = 0V      when Vin = 2.5V

One solution is (almost) R4 = 150Ω and R3 = 330Ω. You may have to experiment.


The circuit in its entirety looks like this:


It isn’t quite identical to the PCB shown below, where R4 originally connects to -5V instead of GND. Instead I cut the trace going from -5V on the AD8021 to the voltage divider and connected it to GND:


Eagle files (with the corrected circuit) can be found in the downloads section.

Suggested reading:

National’s Op Amp circuit collection
Analog’s data conversion handbook. Chapter 6
Bryant, Jung and Kester, Op Amp Applications, Chap. 3

Original posts at
First steps towards a new PCB
Suddenly you’ll like bipolarity
Broken promises