ADC resolution and reference voltage help convert real-world signals into numbers a microcontroller can understand.
ADC resolution and reference voltage in Embedded C
digital_value = (analog_voltage / reference_voltage) * ((1 << resolution) - 1);
resolution is the number of bits the ADC uses (e.g., 10 bits means values from 0 to 1023).
reference_voltage is the maximum voltage the ADC can measure (e.g., 5V or 3.3V).
resolution = 10; reference_voltage = 5.0; analog_voltage = 2.5; digital_value = (analog_voltage / reference_voltage) * ((1 << resolution) - 1);
resolution = 12; reference_voltage = 3.3; analog_voltage = 1.65; digital_value = (analog_voltage / reference_voltage) * ((1 << resolution) - 1);
This program calculates the digital output of a 10-bit ADC with 5V reference for an input voltage of 2.5V.
#include <stdio.h> int main() { int resolution = 10; // 10-bit ADC float reference_voltage = 5.0; // 5V reference float analog_voltage = 2.5; // example input voltage int max_digital = (1 << resolution) - 1; // 1023 for 10-bit int digital_value = (int)((analog_voltage / reference_voltage) * max_digital); printf("Analog voltage: %.2f V\n", analog_voltage); printf("Digital value (ADC output): %d\n", digital_value); return 0; }
Higher resolution means more precise measurements but may take longer to convert.
Reference voltage sets the maximum voltage the ADC can read; using a stable reference improves accuracy.
Always scale your input voltage to be within 0 and reference voltage to avoid incorrect readings.
ADC resolution defines how many steps the analog input is divided into.
Reference voltage is the maximum voltage the ADC can measure.
Digital value = (input voltage / reference voltage) x (2^resolution - 1).