Wiblocks --- DAC Class for TLV5618

DAC Class (TLV5618)

The DAC_TLV5618 provides 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.

The DAC_TLV5618 class 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);



DAC_TLV5618 Class Reference

#include <DAC.h>

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)

Detailed Description

DAC_TLV5618

Definition at line 58 of file DAC.h.

Constructor & Destructor Documentation

DAC_TLV5618::DAC_TLV5618 ( unsigned char  cs_pin,
dac_tlv5618_pwrs  pwr = DAC_NORMAL,
dac_tlv5618_spds  spd = DAC_SLOW 
)

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).

Parameters:
[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

Definition at line 142 of file DAC.cpp.

Member Function Documentation

char DAC_TLV5618::set_code ( dac_tlv5618_rs  rs,
unsigned int  code 
)

Writes a code to the DAC.

Parameters:
[in] rs register to output data to
[in] code the DAC code -- valid codes are 0..4095
Returns:
0 = success

Definition at line 229 of file DAC.cpp.

void DAC_TLV5618::set_power_control ( dac_tlv5618_pwrs  pwr  ) 

Changes the power control bit

The update occurs on the next write to the DAC.

Parameters:
[in] pwr -- values are NORMAL or POWER_DOWN

Definition at line 253 of file DAC.cpp.

void DAC_TLV5618::set_speed ( dac_tlv5618_spds  spd  ) 

Changes the speed control bit.

The update occurs on the next write to the DAC.

Parameters:
[in] spd -- values are SLOW or FAST

Definition at line 241 of file DAC.cpp.

char DAC_TLV5618::set_voltage ( dac_tlv5618_rs  rs,
double  v 
)

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 --

  1. Use WRITE_BUFFER to write the data for DACB to the buffer
  2. Use WRITE_A_UPDATE_B which will write data to DACA and update DACB with the data in the buffer

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.

Parameters:
[in] rs register select bits. The valid values for rs are:

WRITE_B_AND_BUFFER   Write data to DACB and BUFFER
WRITE_BUFFER    Write data to BUFFER
WRITE_A_UPDATE_B    Write data to DACA and update DACB with BUFFER


[in] v the value of the voltage to output -- valid voltage values are 0..Vref.
Returns:
0 = success

Definition at line 216 of file DAC.cpp.

char DAC_TLV5618::write_data ( dac_tlv5618_rs  rs,
unsigned int  code 
)

write_data is used to output data, using the SPI port, to the TLV5618. It is called by set_voltage and set_code.

Parameters:
[in] rs register select bits
[in] code the DAC code -- valid codes are 0..4095
Returns:
0 = success
Todo:
Add error codes

Definition at line 164 of file DAC.cpp.

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