Skip to main content

Analog Out

DAC​

A digital-to-analog converter (DAC) turns a numeric sample into a voltage between 0 V and the chip's reference voltage (3.3 V on Endpoint, 12-bit resolution). The output is a weak signal and is not meant to drive a load directly. Add an op-amp or similar buffer to drive something like a speaker.

WriteValue accepts either a raw 12-bit integer (0 to 4095) or a double in the range 0.0 to 1.0.

using GHIElectronics.Endpoint.Core;
using GHIElectronics.Endpoint.Devices.Dac;

var dac = DacController.FromName(EPDomino24.Dac.Id);
using var output = dac.OpenChannel(EPDomino24.Dac.PA5);

double level = 0, step = 0.1;
int direction = 1;

while (true) {
output.WriteValue(level);
if (level >= 0.9) direction = -1;
if (level <= 0.1) direction = 1;
level += step * direction;
Thread.Sleep(1000);
}
tip

Do not use analog outputs to control the power of an LED or a motor. Use PWM for that.

PWM​

PWM can also simulate an analog voltage when filtered or driving a duty-cycle-responsive load (motor, LED). See PWM for details.