Modular Electronics  0.1
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Protected Member Functions | List of all members
DacSpi Class Reference

#include <dac.h>

Inheritance diagram for DacSpi:
AD5764 AD5791 TetraDac

Public Member Functions

 DacSpi (uint8_t sync_pin, uint8_t spi_bus_config_pin, uint8_t ldac_pin, uint8_t bit_resolution, uint8_t clock_divider=4, BitOrder bit_order=MSBFIRST, uint8_t spi_mode=SPI_MODE1)
 
uint8_t Begin (void)
 
uint8_t Initialize (void)
 
double SetVoltage (uint8_t channel, double voltage, bool update_outputs=true)
 
void UpdateAnalogOutputs (void)
 
double GetVoltage (uint8_t channel)
 

Protected Member Functions

virtual double BytesToVoltage (spi_utils::Message message)
 
virtual spi_utils::Message SetVoltageMessage (uint8_t channel, double voltage)
 
virtual spi_utils::Message InitializeMessage (void)
 

Detailed Description

Dac class

Author
Carlos Kometter
Sasha Zibrov
Version
0.1
Date
2018

Constructor & Destructor Documentation

DacSpi::DacSpi ( uint8_t  sync_pin,
uint8_t  spi_bus_config_pin,
uint8_t  ldac_pin,
uint8_t  bit_resolution,
uint8_t  clock_divider = 4,
BitOrder  bit_order = MSBFIRST,
uint8_t  spi_mode = SPI_MODE1 
)

Constructor

Parameters
[in]sync_pinThe sync or chip select of the dac chip. Different than spi_bus_config_pin
[in]spi_bus_config_pinThe pin that identifies the bus. More than one dac can share the same pin.
[in]ldac_pinThe ldac pin used to update the analog outputs.
[in]bit_resolutionThe bit resolution of the dac (eg. 20 for AD5791).
[in]clock_dividerSets the spi frequency. spi_freq = clock_freq (84 MHz for arduino due) / clock_divider (default: 4)
[in]bit_orderPossible values:
  • MSBFIRST Most significant bit first. (default)
  • LSBFIRST Least significant bit first.
[in]spi_modePossible values:
  • SPI_MODE0
  • SPI_MODE1 (default)
  • SPI_MODE2
  • SPI_MODE3

Member Function Documentation

uint8_t DacSpi::Begin ( void  )

Configures pins for SPI and initializes SPI communication. This function must be called before calling any other function.

Returns
0 if successful
virtual double DacSpi::BytesToVoltage ( spi_utils::Message  message)
inlineprotectedvirtual

Uses chip specifications (e.g. bit resolution, registers, range) to convert a set of bytes stored in a Message object to voltage. Each DAC has its own convertion function. Check the datasheet of each chip and override the function below accordingly.

Parameters
[in]messageMessage object which stores the bytes for conversion.
Returns
The current voltage setted on the dac register.

Reimplemented in AD5764, and AD5791.

double DacSpi::GetVoltage ( uint8_t  channel)

Gets the voltage setted to dac register.

Parameters
[in]channelSpecifies the channel to query the voltage.
Returns
The voltage setted to dac register.
uint8_t DacSpi::Initialize ( void  )

Initializes Dac from tristate mode to normal mode.

Returns
0 if successful.
virtual spi_utils::Message DacSpi::InitializeMessage ( void  )
inlineprotectedvirtual
Returns
Message object to intialize Dac.

Reimplemented in AD5764, and AD5791.

double DacSpi::SetVoltage ( uint8_t  channel,
double  voltage,
bool  update_outputs = true 
)

Sets a voltage to Dac register via SPI.

Parameters
[in]channelThe channel to be setted.
[in]voltageThe voltage to be setted to channel.
[in]update_outputsPossible value:
  • true The analog output is updated after setting the dac register.
  • false The analog output is not updated after setting the dac regiser.
Returns
The voltage setted.
virtual spi_utils::Message DacSpi::SetVoltageMessage ( uint8_t  channel,
double  voltage 
)
inlineprotectedvirtual
Parameters
[in]channelSpecifies the channel the Message will set the voltage to.
[in]voltageSpecifies the voltage.
Returns
Message object to write data register.

Reimplemented in AD5764, and AD5791.

void DacSpi::UpdateAnalogOutputs ( void  )

Updates the outputs of all Dac objects sharing the same ldac_pin_.


The documentation for this class was generated from the following files: