Take it on /learn as ADCs, DACs and sampling.
The lessons
- Aliasing: an Uno samples a function generator's sine at a rate you pick and counts the cycles it sees. Right below half the sample rate, wrong above it: 70 Hz sampled at 100 Hz looks like 30 Hz.
- Resolution and LSB: a bench supply on A0. Codes and volts, a 4.88 mV step, fewer bits, the 1.1 V reference and clipping.
- R-2R DAC: four slide switches drive a 10k and 20k ladder. Binary weights, full scale one LSB short, and why a ladder needs a buffer.
- PWM as a DAC: pin 9 through a 10k and 10 uF low-pass. Level, ripple and the 19.6 mV step.
- ADS1115 and MCP3008: sixteen bits and a gain amplifier against ten bits and speed, on the same input.
- MCP4725: the gallery's DAC sine, read back on A0 and compared with PWM.
- Boss: a 16-bit voltmeter: wire a bussed resistor network as an 8:1 divider, enter the ratio, run a self-test against the DAC and pick a range.
The sketches
convlab (lessons 1, 2 and 4) reads A0 and drives pin 9. Serial commands:
read, bits 8 (1 to 10), ref 1.1 or ref 5, alias, rate 100
(1 to 2000 samples a second) and duty 128 (0 to 255).
voltmeter16 (lesson 5 and the boss) has an ADS1115 (0x48) and an MCP4725
(0x60) on I2C and an MCP3008 on SPI with CS on pin 10. Commands:
range 4.096 (6.144, 4.096, 2.048, 1.024, 0.512 or 0.256), avg 16,
divider 8, dac 1.000 and test.
What the simulator leaves out
The converters here are noiseless and their references exact, so averaging changes nothing and every reading repeats. Real converters have noise, offset, gain error and a reference that drifts with temperature, which is why a real meter is calibrated against a known source, as the self-test does.