Digital Analog Converter (DAC)#

Hardware Interface#

Defined in namespace hal

#include <libhal/dac.hpp>

class dac#

Digital to Analog Converter (DAC) hardware abstraction interface.

Use this interface for devices and peripherals that can create arbitrary analog voltages between a defined Vss (negative reference) and Vcc (positive reference) voltage.

Subclassed by hal::inert_dac, hal::lpc40::dac, hal::mock::dac, hal::soft::inert_dac

Public Functions

inline void write(float p_percentage)#

Set the output voltage of the DAC.

The input value p_percentage is a 32-bit floating point value from 0.0f to +1.0f.

The floating point value is linearly proportional to the output voltage relative to the Vss and Vcc such that if Vss is 0V (gnd) and Vcc is 5V then 0.0 is 0V, 0.25 is 1.25V, 0.445 is 2.225V and 1.0 is 5V.

This function clamps the input value between 0.0f and 1.0f and thus values passed to driver implementations are guaranteed to be within this range. Callers of this function do not need to clamp their values before passing them into this function as it would be redundant. The rationale for doing this at the interface layer is that it allows callers and driver implementors to omit redundant clamping code, reducing code bloat.

Parameters:

p_percentage – - value from 0.0f to +1.0f representing the proportion of the output voltage from the Vss to Vcc.