M5Unit-ANADIG 0.1.0 git rev:3fbd370
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)
 
virtual bool begin () override
 
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 configration.
 
void config (const config_t &cfg)
 Set the configration.
 
Properties
mcp4725::PowerDown powerDown () const
 Gets the iner 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=5000.f)
 Raw value to voltage(mV)
 
static uint16_t voltage_to_raw (const float mv, const float supply_voltage=5000.f)
 Voltage(mV) to raw value.
 

Static Public Attributes

static constexpr uint16_t RESOLUTION {0x0FFF}
 
static constexpr float MAXIMUM_VOLTAGE {3300.f}
 

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)
 
bool read_status (uint8_t rbuf[5])
 

Detailed Description

Digital-to-analog signal conversion unit.

Member Function Documentation

◆ generalReset()

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

General reset.

Reset using I2C general call

Returns
True if successful
Note
Immediately after this reset event, the deviceuploads the contents of the EEPROM into the DACregister
Warning
This is a reset by General command, the command is also sent to all devices with I2C connections

◆ 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

◆ 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/2]

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 If exceeding the range, it will be kept within the range

◆ writeVoltage() [2/2]

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

Output the voltage.

Parameters
rawOutput raw value
Returns
True if successful @Note If exceeding the range, it will be kept within the range

◆ writeVoltageAndEEPROM() [1/2]

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 If exceeding the range, it will be kept within the range

◆ writeVoltageAndEEPROM() [2/2]

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