#include <dac.h>
|
| 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) |
|
Dac class
- Author
- Carlos Kometter
-
Sasha Zibrov
- Version
- 0.1
- Date
- 2018
- Copyright
- GNU Public License.
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_pin | The sync or chip select of the dac chip. Different than spi_bus_config_pin |
[in] | spi_bus_config_pin | The pin that identifies the bus. More than one dac can share the same pin. |
[in] | ldac_pin | The ldac pin used to update the analog outputs. |
[in] | bit_resolution | The bit resolution of the dac (eg. 20 for AD5791). |
[in] | clock_divider | Sets the spi frequency. spi_freq = clock_freq (84 MHz for arduino due) / clock_divider (default: 4) |
[in] | bit_order | Possible values:
- MSBFIRST Most significant bit first. (default)
- LSBFIRST Least significant bit first.
|
[in] | spi_mode | Possible values:
- SPI_MODE0
- SPI_MODE1 (default)
- SPI_MODE2
- SPI_MODE3
|
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
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] | message | Message 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] | channel | Specifies 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.
- 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] | channel | The channel to be setted. |
[in] | voltage | The voltage to be setted to channel. |
[in] | update_outputs | Possible 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.
- Parameters
-
[in] | channel | Specifies the channel the Message will set the voltage to. |
[in] | voltage | Specifies 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:
- include/dac.h
- src/dac.cpp