Skip to content
If this is your first visit, please click here to learn about shipping and delivery.
If this is your first visit, please touch here to learn about shipping and delivery.
Eight-pin DIP package product image for the MCP4921 DAC

Building an Adjustable Analogue Setpoint with an MCP4921 DAC

A microcontroller is good at storing a number, but another circuit may need a voltage: a test fixture setpoint, an adjustable threshold or a simulated sensor signal. A digital-to-analogue converter, or DAC, provides the bridge. The useful design question is not simply how many bits it has, but how accurately and reliably the complete circuit produces the voltage you need.

The digital-to-analogue IC collection includes the Microchip MCP4921-E/P 12-bit SPI DAC. It is a suitable example for learning setpoint generation with an external reference. This guide develops a measurement-led approach rather than treating a successful SPI transfer as proof of analogue accuracy.

Define the signal before selecting the circuit

Start by writing a short requirement: “Produce an adjustable voltage from 0.5 V to 3.5 V for a high-impedance test input.” Then add the acceptable error, adjustment speed and behaviour during reset. A slowly adjusted classroom experiment and a waveform generator place very different demands on the same DAC.

Also identify the receiving circuit’s input impedance and permitted voltage range. If its documentation is incomplete, resolve that before connecting equipment. Your output may need buffering, protection or a different voltage range; the DAC alone does not make those decisions.

Questions that shape an analogue setpoint design
Requirement Why it matters
Voltage range Determines reference and output-stage choices
Allowable error Sets reference, calibration and measurement requirements
Load Determines whether a buffer is needed
Update behaviour Defines settling, overshoot and start-up tests
Failure response Determines the required default or disabled output

Understand what the MCP4921 provides

Microchip’s MCP4921 product information describes a single-channel, 12-bit voltage-output DAC with an SPI interface and external voltage reference. Its supply operating range is 2.7–5.5 V, and its output amplifier offers selectable unity or two-times gain. Those features do not guarantee every combination of supply, reference, gain and output voltage is usable.

Consult the MCP4901/4911/4921 data sheet for the exact package, reference-input conditions, output swing, load limits and serial timing. Check the digital input thresholds against your controller’s guaranteed output levels; a 3.3 V controller should not be assumed compatible with every 5 V peripheral.

Calculate the code and the ideal step size

For the MCP4921, the ideal relationship is:

Vout = gain × Vref × code / 4096

The 12-bit code ranges from 0 to 4095. Consider an illustrative circuit using a suitable 4.096 V reference, unity gain and a 5 V DAC supply, with the reference mode and output load checked against the data sheet. One ideal code step is then 1 mV.

Ideal outputs for this example, before errors and output-stage limitations
Code Ideal voltage
500 0.500 V
2048 2.048 V
3500 3.500 V
4095 4.095 V

Notice that the highest code is one step below 4.096 V. When converting a requested voltage into a code, round deliberately and enforce the application’s permitted range before sending it. A request outside that range should produce a defined error or clamp behaviour, rather than wrapping into an unexpected code.

Resolution is not the same as accuracy

A 1 mV ideal step does not promise that each output voltage is correct to 1 mV. Reference error, DAC offset, gain error, nonlinearity, temperature and measurement uncertainty all affect the result. The external reference deserves the same attention as the converter itself.

Analog Devices’ guide to reference selection for voltage-output DACs explains how reference performance enters the error budget. A noisy supply rail used as a convenient reference can become a noisy output. Whether that is acceptable depends on the application, not the number of bits printed in the catalogue.

Bring up the digital and analogue sides separately

  1. Inspect the unpowered circuit. Verify the package orientation, supply polarity, ground connection and decoupling. Keep the reference path short and away from high-current switching loops.
  2. Measure the supplies. Confirm the DAC supply and reference at their actual pins before relying on software calculations.
  3. Send one known code. Begin with a mid-range output, using the data-sheet command format and correct SPI timing. Configure gain, reference buffering and output enable deliberately.
  4. Measure the unloaded result. Use a suitable high-impedance instrument and a clear ground reference.
  5. Connect the intended load. Repeat the measurement and investigate any change.

Keep the first firmware test small. A serial command that selects three fixed voltages is easier to diagnose than a menu system, display update task and waveform generator running together. Once those points work, expand the software while retaining a simple diagnostic mode.

Calibrate only after establishing stable behaviour

Make a worksheet containing requested voltage, transmitted code, measured reference and measured output. Test several points across the intended working range, then repeat them after the circuit has warmed up. Record the instrument and range used so the measurements remain interpretable.

A straight-line correction may compensate for a stable offset and scale error. It cannot remove random noise, fix an overloaded output or make a nonlinear response perfectly linear. Reserve additional test points to assess the correction rather than checking only the points used to calculate it.

For the example 0.5–3.5 V application, you might calibrate near each end and check intermediate values independently. Avoid claiming a precise accuracy from a meter display alone: the instrument’s specifications and connection errors belong in the result.

Test transitions and resets as well as steady voltages

Command a change from the minimum allowed setpoint to the maximum and back. Observe whether the receiving circuit responds as expected. Where transient behaviour matters, use an oscilloscope and appropriate probing instead of relying on a slowly updating multimeter.

Then reset the controller, interrupt communication and cycle the supplies in realistic sequences. Decide what the connected system should do before firmware sends its first valid value. For a test fixture, a separate enable or output disconnect may be more useful than trusting an unspecified power-up condition.

Common mistakes worth catching early

  • Wrong voltage everywhere: inspect the reference value, selected gain and command format.
  • Correct unloaded, wrong when connected: check load current, grounding and the need for a buffer.
  • Small code changes appear invisible: check meter resolution, noise and the actual step size.
  • Good numbers but unpredictable start-up: specify and test the whole system’s reset behaviour.

A useful DAC design is one whose voltage, error and failure behaviour you can explain and reproduce. The code calculation starts that process; careful reference selection and measured verification finish it.

Previous article Battery Power for Arduino Projects: Voltage Range, Runtime and Regulator Heat