Wiblocks --- DAC Class for TLV5620

DAC Class (TLV5620)

The DAC_TLV5620 provides an interface for ATmega168, ATmega328 and ATmega644 microcontrollers to control the Texas Instruments TLV5620 DAC. The TLV5620 is a four channel, 8-bit voltage output DAC with an SPI interface. The reference is external. On the NB1A and WB2 boards the reference is a a TLV431B shunt regulator.

The DAC_TLV5620 class requires the SPI library. Setup of the SPI library is required prior to accessing the TLV5620. The example Arduino loop sets DACD to its full-scale value and DACC to 1.2V.

// Assign Arduino pins to the DAC load and latch pins 
// and initialize the dac object

#define DAC_LOAD_PIN  10 //PB2
#define DAC_LATCH_PIN  9 //PB1

DAC_TLV5620 dac  = DAC_TLV5620(DAC_LOAD_PIN, DAC_LATCH_PIN);

void setup() {
  // initialize the SPI port
  .
  . 
}

void loop() {

  dac.set_code(D, 255);    // Set channel D to the maximum output voltage
  dac.set_voltage(C, 1.2); // Set channel C to 1.2V

}

DAC_TLV5620 Class Reference

#include <DAC.h>

Public Member Functions

 DAC_TLV5620 (unsigned char load_pin, unsigned char latch_pin)
char write_data (dac_tlv5620_chs ch, dac_tlv5620_ranges range, unsigned char code)
char set_voltage (dac_tlv5620_chs ch, double v)
void set_range (dac_tlv5620_chs ch, dac_tlv5620_ranges range)
char set_code (dac_tlv5620_chs ch, unsigned char code)

Static Public Attributes

static const double _ref = 1.24
 Reference voltage of the TLV431.
static const unsigned char _fs_code = 255
 Max value of an 8 bit unsigned char is = 2^8 - 1.
static const unsigned int _num_steps = 256
 8 bits, 256 values (0..255)

Detailed Description

DAC_TLV5620

Definition at line 23 of file DAC.h.

Constructor & Destructor Documentation

DAC_TLV5620::DAC_TLV5620 ( unsigned char  load_pin,
unsigned char  latch_pin 
)

Constructs a DAC_TLV5620 object and Assigns a pin number for the TLV5620 LOAD and LATCH pin. The pin numbers should be Arduino pin numbers (2..13). Initializes the range of each DAC channel to 2 * Vref (which is 2 * 1.24V for the NB1A).

Parameters:
[in] load_pin pin number attached to the TLV5620 LOAD pin
[in] latch_pin pin number attached to the TLV5620 LATCH pin

Definition at line 31 of file DAC.cpp.

Member Function Documentation

char DAC_TLV5620::set_code ( dac_tlv5620_chs  ch,
unsigned char  code 
)

Writes a code to a single DAC channel. The DAC channel output voltage is updated.

Parameters:
[in] ch channel to output data to -- valid channels are {A, B, C, D}
[in] code the DAC code -- valid codes are 0..255
Returns:
0 = success

Definition at line 91 of file DAC.cpp.

void DAC_TLV5620::set_range ( dac_tlv5620_chs  ch,
dac_tlv5620_ranges  range 
)

Sets the DAC range for a single DAC channel. The DAC output voltage is not changed. The range is saved in ths DAC_TLV5620 object. The next set_code or set_voltage command will use the new range.

Parameters:
[in] ch channel to output data to -- valid channels are {A, B, C, D}
[in] range the output voltage range -- valid ranges are {REF, REFX2}
Returns:
void

Definition at line 104 of file DAC.cpp.

char DAC_TLV5620::set_voltage ( dac_tlv5620_chs  ch,
double  v 
)

Sets the output voltage for a single DAC channel. The DAC output voltage is updated. If the voltage, v, is greater than FS DAC voltage than 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.

Parameters:
[in] ch channel to output data to -- valid channels are {A, B, C, D}
[in] v the value of the voltage to output -- valid voltage values are 0..Vref.
Returns:
0 = success

Definition at line 120 of file DAC.cpp.

char DAC_TLV5620::write_data ( dac_tlv5620_chs  ch,
dac_tlv5620_ranges  range,
unsigned char  code 
)

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

Parameters:
[in] ch channel to output data to -- valid channels are {A, B, C, D}
[in] range the output voltage range -- valid ranges are {REF, REFX2}
[in] code the DAC code -- valid codes are 0..255
Returns:
0 = success
Todo:
Add error codes

The data transfer for the TLV5620 consists of the following steps --

  • Set LOAD High ...... data is clocked on the falling edge of CLK
  • Pulse LOAD Low ..... transfer data from the serial-in register to the selected DAC
  • Set LATCH Low ...... output voltage is updated

Definition at line 65 of file DAC.cpp.

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