DAC_TLV5618provides an interface for ATmega168, ATmega328 and ATmega644 microcontrollers to control the Texas Instruments TLV5618 DAC. The TLV5618 is a two channel, 12-bit voltage output DAC with an SPI interface. The reference is external.
DAC_TLV5618class requires the SPI library. Setup of the SPI library is required prior to accessing the TLV5618.
#define DAC_CS_PIN 4 // Sanguino Pin (ATmega644P PB4) #define SPI_TIMEOUT 10 // mS // Constants for the SPI pins used on the NB1A and NB2A are in SPI.h // The timeout value was defined above. // Initialize the timeout and assign the SPI pins. SPI spi = SPI(SPI_TIMEOUT, NB2A_MOSI_PIN, NB2A_MISO_PIN, NB2A_SCK_PIN); // Assign the DAC chip select pin using the value defined above. DAC_TLV5618 dac = DAC_TLV5618(DAC_CS_PIN);
Public Member Functions
|DAC_TLV5618 (unsigned char cs_pin, dac_tlv5618_pwrs pwr=DAC_NORMAL, dac_tlv5618_spds spd=DAC_SLOW)|
|char||write_data (dac_tlv5618_rs rs, unsigned int code)|
|char||set_voltage (dac_tlv5618_rs rs, double v)|
|char||set_code (dac_tlv5618_rs rs, unsigned int code)|
|void||set_speed (dac_tlv5618_spds spd)|
|void||set_power_control (dac_tlv5618_pwrs pwr)|
Static Public Attributes
|static const double||_ref = 1.225|
|Reference voltage of the LM4041AIZ-1.2. |
|static const unsigned int||_fs_code = 4095|
|Max value of a 12 bit unsigned char is = 2^12 - 1. |
|static const unsigned int||_num_steps = 4096|
|12 bits, 256 values (0..4095) |
Definition at line 58 of file DAC.h.
|dac_tlv5618_pwrs|| pwr =
|dac_tlv5618_spds|| spd = |
Constructs a DAC_TLV5618 object and assigns a pin number for the TLV5618 CHIP SELECT pin. The pin numbers should be an Arduino (2-13) or Sanguino pin number (2-24).
|[in]||cs_pin||pin number attached to the TLV5618 chip select pin|
|[in]||pwr||power mode for the DAC -- NORMAL or POWER_DOWN. The default is NORMAL.|
|[in]||spd||speed of the DAC -- SLOW or FAST|
Writes the code corresponding to the voltage value,
v, to the DAC.
If the register bits,
rs, are set to WRITE_B_AND_BUFFER then the code is written to DACB and to the buffer. If
rs is set to WRITE_BUFFER then the code is only written to the buffer and there is no change to either DAC output. If
rs is set to WRITE_A_UPDATE_B then the code is written to DACA and the value stored in the buffer is written to DACB.
If the voltage, v, is greater than FS DAC voltage then the DAC voltage is set to the FS value. If the voltage, v, is less than 0 then the DAC voltage is set to 0. The TLV5618 has a voltage doubler on each DAC channel. The FS voltage is 2 * VREF * 4095 / 4096.
To perform simultaneous updates of both channels --
Updating DACA always updates DACB with the data that is stored in the buffer. On startup initialize the buffer using either WRITE_BUFFER or WRITE_B_AND_BUFFER.
|[in]||rs||register select bits. The valid values for |
|[in]||v||the value of the voltage to output -- valid voltage values are 0..Vref.|