M5Unit-ANADIG 0.4.1 git rev:a449179
Loading...
Searching...
No Matches
m5::unit::UnitMCP4725 Class Reference

Digital-to-analog signal conversion unit. More...

#include <unit_MCP4725.hpp>

Inheritance diagram for m5::unit::UnitMCP4725:

Classes

struct  config_t
 Settings for begin. More...
 

Public Member Functions

 UnitMCP4725 (const uint8_t addr=DEFAULT_ADDRESS)
 Constructor.
 
virtual bool begin () override
 Initialize the unit and apply config_t.
 
bool generalReset ()
 General reset.
 
bool readDACRegister (mcp4725::PowerDown &pd, uint16_t &raw)
 Read the DAC register.
 
bool readEEPROM (mcp4725::PowerDown &pd, uint16_t &raw)
 Read the EEPROM settings.
 
Settings for begin
config_t config ()
 Gets the configuration.
 
void config (const config_t &cfg)
 Set the configuration.
 
Properties
mcp4725::PowerDown powerDown () const
 Gets the inner power down mode.
 
uint16_t lastValue () const
 Gets the last output raw value.
 
Settings
bool writePowerDown (const mcp4725::PowerDown pd)
 Write the power down mode.
 
Output the voltage
Note
FastMode is used, so EEPROM is not affected
template<typename T , typename std::enable_if< std::is_floating_point< T >::value, std::nullptr_t >::type = nullptr>
bool writeVoltage (const T mv)
 Output the voltage.
 
bool writeVoltage (const uint16_t raw)
 Output the voltage.
 
template<typename T , typename std::enable_if<!std::is_same< uint16_t, T >::value &&std::is_unsigned< T >::value, std::nullptr_t >::type = nullptr>
bool writeVoltage (const T raw)
 Output the voltage.
 
Write to DAC register and EEPROM
Note
After a reset, the device uploads the contents of the EEPROM to the DAC register
template<typename T , typename std::enable_if< std::is_floating_point< T >::value, std::nullptr_t >::type = nullptr>
bool writeVoltageAndEEPROM (const T mv, const bool blocking=true)
 Write to DAC register and EEPROM.
 
bool writeVoltageAndEEPROM (const uint16_t raw, const bool blocking=true)
 Write to DAC register and EEPROM.
 
template<typename T , typename std::enable_if<!std::is_same< uint16_t, T >::value &&std::is_unsigned< T >::value, std::nullptr_t >::type = nullptr>
bool writeVoltageAndEEPROM (const T raw, const bool blocking=true)
 Write to DAC register and EEPROM.
 

Static Public Member Functions

static float raw_to_voltage (const uint16_t raw, const float supply_voltage)
 Raw value to voltage(mV)
 
static uint16_t voltage_to_raw (const float mv, const float supply_voltage)
 Voltage(mV) to raw value.
 

Static Public Attributes

static constexpr uint16_t RESOLUTION {0x0FFF}
 Maximum raw output value (12 bits)
 

Protected Types

enum class  Command : uint8_t { FastMode , WriteDAC , WriteDACAndEEPROM }
 

Protected Member Functions

bool write_voltage (const Command cmd, const uint16_t raw)
 
bool is_eeprom_ready ()
 
uint32_t make_buffer (uint8_t buf[3], const uint16_t raw, const Command cmd) const
 
bool read_status (uint8_t rbuf[5])
 

Detailed Description

Digital-to-analog signal conversion unit.

Constructor & Destructor Documentation

◆ UnitMCP4725()

m5::unit::UnitMCP4725::UnitMCP4725 ( const uint8_t addr = DEFAULT_ADDRESS)
inlineexplicit

Constructor.

Parameters
addrI2C address

Member Function Documentation

◆ begin()

bool m5::unit::UnitMCP4725::begin ( )
overridevirtual

Initialize the unit and apply config_t.

Returns
True if successful

◆ generalReset()

bool m5::unit::UnitMCP4725::generalReset ( )

General reset.

Reset using I2C general call

Returns
True if successful
Note
Immediately after this reset event, the device uploads the contents of the EEPROM into the DAC register
Warning
This is a reset by General command, the command is also sent to all devices with I2C connections
Not supported with m5::I2C_Class. The bus hangs because m5::I2C_Class has no timeout on bus recovery after a general call reset

◆ raw_to_voltage()

static float m5::unit::UnitMCP4725::raw_to_voltage ( const uint16_t raw,
const float supply_voltage )
inlinestatic

Raw value to voltage(mV)

Parameters
rawRaw value
supply_voltageVDD of the chip (mV)
Returns
Voltage (mV)

◆ readDACRegister()

bool m5::unit::UnitMCP4725::readDACRegister ( mcp4725::PowerDown & pd,
uint16_t & raw )

Read the DAC register.

Parameters
[out]pdPower down mode
[out]rawOutput voltage raw value
Returns
True if successful

◆ readEEPROM()

bool m5::unit::UnitMCP4725::readEEPROM ( mcp4725::PowerDown & pd,
uint16_t & raw )

Read the EEPROM settings.

Parameters
[out]pdPower down mode
[out]rawOutput voltage raw value
Returns
True if successful

◆ voltage_to_raw()

static uint16_t m5::unit::UnitMCP4725::voltage_to_raw ( const float mv,
const float supply_voltage )
inlinestatic

Voltage(mV) to raw value.

Parameters
mvVoltage (mV), clamped to 0 - supply_voltage
supply_voltageVDD of the chip (mV)
Returns
Raw value (0 - RESOLUTION)

◆ writePowerDown()

bool m5::unit::UnitMCP4725::writePowerDown ( const mcp4725::PowerDown pd)

Write the power down mode.

Parameters
pdMode
Returns
True if successful
Note
Output voltage is not changed

◆ writeVoltage() [1/3]

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, std::nullptr_t >::type = nullptr>
bool m5::unit::UnitMCP4725::writeVoltage ( const T mv)
inline

Output the voltage.

Parameters
mvOutput voltage(mV)
Returns
True if successful
Note
Negative values return false. Values exceeding the saturation voltage are clamped

◆ writeVoltage() [2/3]

template<typename T , typename std::enable_if<!std::is_same< uint16_t, T >::value &&std::is_unsigned< T >::value, std::nullptr_t >::type = nullptr>
bool m5::unit::UnitMCP4725::writeVoltage ( const T raw)
inline

Output the voltage.

Parameters
rawOutput raw value (unsigned integer other than uint16_t)
Returns
True if successful
Note
Masked with RESOLUTION (12 bits)

◆ writeVoltage() [3/3]

bool m5::unit::UnitMCP4725::writeVoltage ( const uint16_t raw)
inline

Output the voltage.

Parameters
rawOutput raw value
Returns
True if successful
Note
Masked with RESOLUTION (12 bits)

◆ writeVoltageAndEEPROM() [1/3]

template<typename T , typename std::enable_if< std::is_floating_point< T >::value, std::nullptr_t >::type = nullptr>
bool m5::unit::UnitMCP4725::writeVoltageAndEEPROM ( const T mv,
const bool blocking = true )
inline

Write to DAC register and EEPROM.

Parameters
mvOutput voltage(mV)
blockingWait until EEPROM write is complete if true
Returns
True if successful
Note
Negative values return false. Values exceeding the saturation voltage are clamped

◆ writeVoltageAndEEPROM() [2/3]

template<typename T , typename std::enable_if<!std::is_same< uint16_t, T >::value &&std::is_unsigned< T >::value, std::nullptr_t >::type = nullptr>
bool m5::unit::UnitMCP4725::writeVoltageAndEEPROM ( const T raw,
const bool blocking = true )
inline

Write to DAC register and EEPROM.

Parameters
rawOutput raw value (unsigned integer other than uint16_t)
blockingWait until EEPROM write is complete if true
Returns
True if successful
Note
Masked with RESOLUTION (12 bits)

◆ writeVoltageAndEEPROM() [3/3]

bool m5::unit::UnitMCP4725::writeVoltageAndEEPROM ( const uint16_t raw,
const bool blocking = true )

Write to DAC register and EEPROM.

Parameters
rawOutput raw value
blockingWait until EEPROM write is complete if true
Returns
True if successful
Note
Masked with RESOLUTION (12 bits)