This circuit is designed to measure a wide variety of digital or analog sources.

Two types of inputs may be connected - resistive or voltage.

Resistive sensors are connected between 1-3V3REF and 2-INPUT on the INPUT terminal.

For resistive sensors Q3 is activated to provide a sensing current to the sensor.
This creates a voltage divider between the sensor and R3 with a sensing current of 330ľA or less to prevent self heating of the sensor.

The voltage at the input becomes 3.3-(3.3*R/(R+10000)) where R is the sensor resistance.

MCP4716 (U4) is a 10 bit DAC and LTC6915 (U3) is an instrumentation amplifier with digitally programmable gain.

Together, these circuits allow the microcontroller to "zoom" in on an arbitrary range of the input voltage which ideally takes the form Vgain*(Vinput-Vbias), where Vinput is the input voltage, Vgain the gain selected for U3 and Vbias the bias produced by U3.

The input voltage is buffered by U2B to provide a low impedance signal for the U3 sampling circuitry.

The actual accuracy depends on a variety of factors and while the uncalibrated circuit should be able to give fairly accurate readouts careful calibration will be required if (very) high accuracy is required.

Factors include: IC1 voltage, trace resistance, R1-R3 resistance, Q1-Q3 resistances, U2 quiescent current & offset voltage, U3 offset voltage & common mode rejection as well as temperature drift for all parameters.

To measure AC or DC voltages, the maximum range is selected by Q1 and Q2 which form a voltage divider between R4 and their respective resistors R1 and R2:

Q2 Q1 RANGE
0  0  0-3.3V
0  1  0-36.3V (24VAC mode/33V p-p)
1  0  0-18.3V (12VAC mode/17V p-p)
1  1  0-51.3V (not supported)

When full ranging of the U3/U4 circuitry is needed the maximum voltage after this stage should remain within 0-3.3V.

To prevent overvoltage, D1 clamps this voltage to the range of 0-5V.

When treating an input as digital the voltage produced by the U4 DAC is instead used as the logic level threshold using U2A to produce a stable 0/5V signal to the microcontroller.

Since D1 does not clamp at 3.3V, but 5V it is possible to read digital signals with a HIGH voltage that exceeds the analog range as described by the table above, as long as a relative logic threshold of no more than 3.3V is acceptable, for example a 5V TTL signal will work fine with both Q1 and Q2 turned off.

Both the DAC and the ADC uses a 3.3V reference from the 2% voltage regulator (IC1) to provide some immunity to noise and drops on the 5V line.

MCP6402 (U2) has a gain bandwidth product of 1MHz, which limits the maximum frequency of digital input.

When measuring analog signals, the frequency is limited by U3, which samples the input signal at 1.5kHz.
Since the circuit does not include a sample and hold circuit, only low frequency signals should be measured, or aliasing errors will occur.
As a rule of thumb, the signal should be limited to 1500/(2*GAIN) Hz.

Since only the positive half wave of AC signals can be measured, a filter is implemented in software to stabilize digital AC signals.

The maximum input voltage would be limited by the breakdown voltage of Q3, which is 60V - however, the 0601 resistors in the input section are rated at 0.1W, effectively limiting the voltage to just above 30VDC/VAC RMS in case resistive mode is erronously activated when a voltage is applied to the input.