Skip to main content

Analog Out

A Digital-to-Analog Converter (DAC) converts a digital number to an analog output voltage. The output usually swings from close to 0V up to nearly the microcontroller's supply voltage (3.3V on SITCore).

The DAC output is a weak signal — it's not meant to drive a load directly. Add an op-amp or similar buffer circuit if you need to drive a speaker, motor, or other load.

WriteValue() accepts a value from 0.0 to 1.0, representing a ratio of the supply voltage (so 0.5 → ~1.65V on a 3.3V system). Both SC20xxx and SC13xxx DACs are 12-bit resolution.

NuGet packages: GHIElectronics.TinyCLR.Devices.Dac for the API, and GHIElectronics.TinyCLR.Pins for pin name constants.

Writing a value

using System.Threading;
using GHIElectronics.TinyCLR.Devices.Dac;
using GHIElectronics.TinyCLR.Pins;

var dac = DacController.GetDefault();
var analogPad4 = dac.OpenChannel(FEZBit.Dac.PA4);

double d = 0.5;
double dd = 0.01;

while (true){
analogPad4.WriteValue(d);
d += dd;
if (d <= 0 || d >= 1)
dd *= -1; // Invert direction
Thread.Sleep(10);
}
tip

The DAC produces a clean, precise analog signal — ideal as input to an audio amplifier, a voltage reference for sensor calibration, or any circuit that takes a low-current voltage input (op-amps, VCOs, ADC inputs on other chips). For controlling load power (LEDs, motors), use PWM instead — it's designed to switch current efficiently.

Other ways to output analog signals

  • PWM — generates an analog voltage by switching a digital pin rapidly. Better for power control (LED dimming, motor speed) than the DAC.
  • Audio playback — WAV file playback using an analog output pin.

API reference

NamespaceDescription
GHIElectronics.TinyCLR.Devices.DacDAC controller and channel classes