119 #define EEPROM_CAL_KEY_INT 0x5678 120 #define EEPROM_CAL_KEY_EXT 0x9ABC
125 #define REF_INTERNAL LTC2654_CMD_INTERNAL_REFERENCE 126 #define REF_EXTERNAL LTC2654_CMD_EXTERNAL_REFERENCE
129 #define STORED_REF_STATE_BASE EEPROM_CAL_STATUS_ADDRESS 130 #define INT_CAL_VALID_BASE STORED_REF_STATE_BASE + 2
131 #define INT_CAL_PARAMS_BASE INT_CAL_VALID_BASE + 2
132 #define EXT_CAL_VALID_BASE INT_CAL_PARAMS_BASE + 32
133 #define EXT_CAL_PARAMS_BASE EXT_CAL_VALID_BASE + 2
134 #define EXT_REF_V_BASE EXT_CAL_PARAMS_BASE + 32
186 Serial.begin(115200);
200 static int16_t selected_dac = 0;
204 if (Serial.available())
207 Serial.println(user_command);
209 switch (user_command)
239 Serial.println(
"Incorrect Option");
242 Serial.println(
"\n*****************************************************************");
254 Serial.print(
"Select DAC to operate on (0=A, 1=B, 2=C, 3=D, 4=All)");
256 if (*selected_dac == 4)
257 Serial.println(
"All");
259 Serial.println(*selected_dac);
306 Serial.println(
"Select reference mode - 0 for Internal, 1 for External");
311 Serial.println(
"External reference mode; enter external reference voltage");
320 Serial.println(
"Internal reference mode selected");
322 Serial.println(
"Writing reference mode to EEPROM\n\n");
331 for (i = 0; i < 4; i++)
343 Serial.println(F(
"\n\nSelect option - 0: Enable Internal, 1: Disable Internal, 2: Enable External, 3: Disable External"));
348 Serial.println(F(
"Enabling Internal Cal Params"));
352 Serial.println(F(
"Disabling Internal Cal Params"));
356 Serial.println(F(
"Enabling External Cal Params"));
360 Serial.println(F(
"Disabling External Cal Params"));
371 int16_t intvalid, extvalid;
375 Serial.println(F(
"\n\nReading Calibration parameters from EEPROM..."));
387 Serial.println(F(
"Restored external ref. Voltage:"));
393 Serial.println(
"Internal reference mode set");
431 for (i = 0; i <= 4; i++)
443 Serial.println(F(
"Found internal calibration, restoring...)"));
448 Serial.println(F(
"Found external calibration, restoring...)"));
450 else Serial.println(F(
"Calibration not found for this\nreference mode, using ideal calibration"));
464 Serial.println(
"Calibration Restored");
468 Serial.print(
"DAC ");
469 Serial.print((
char) (
'A' + i));
470 Serial.print(
" offset: ");
472 Serial.print(
" , lsb: ");
474 Serial.println(
" mv");
476 Serial.println(
"(DAC E applies to ALL DACs selections)");
477 if (eeaddr != 0)
return (1);
505 Serial.println(F(
"Calibration Stored to EEPROM"));
513 Serial.print(F(
"Type 1 to enter voltage, 2 to enter code:"));
516 Serial.println(user_input);
530 Serial.print(F(
"Enter Desired DAC output voltage: "));
532 Serial.print(dac_voltage);
533 Serial.println(
" V");
543 Serial.println(
"Enter Desired DAC Code");
544 Serial.print(
"(Format 32768, 0x8000, 0100000, or B1000000000000000): ");
547 Serial.println(returncode, HEX);
556 Serial.println(F(
"*****************************************************************"));
557 Serial.println(F(
"* DC1678 Demonstration Program *"));
558 Serial.println(F(
"* *"));
559 Serial.println(F(
"* This program demonstrates how to send data to the LTC2654 *"));
560 Serial.println(F(
"* quad 16/12-bit DAC found on the DC1678 demo board. *"));
561 Serial.println(F(
"* *"));
562 Serial.println(F(
"* Set the baud rate to 115200 and select the newline terminator.*"));
563 Serial.println(F(
"* *"));
564 Serial.println(F(
"*****************************************************************"));
570 Serial.println(F(
"\nCommand Summary:"));
571 Serial.println(F(
" 1-Select DAC"));
572 Serial.println(F(
" 2-Write to input register (no update)"));
573 Serial.println(F(
" 3-Write and update DAC"));
574 Serial.println(F(
" 4-Update / power up DAC"));
575 Serial.println(F(
" 5-Power down DAC"));
576 Serial.println(F(
" 6-Set reference mode"));
577 Serial.println(F(
" 7-Calibrate DAC"));
578 Serial.println(F(
" 8-Enable / Disable calibration"));
580 Serial.println(
"\nPresent Values:");
581 Serial.print(
" Selected DAC: ");
582 if (selected_dac != 4)
583 Serial.println((
char) (selected_dac + 0x41));
585 Serial.println(
"All");
586 Serial.print(
" DAC Reference: ");
588 Serial.println(
"Internal");
591 Serial.print(F(
"External "));
593 Serial.println(F(
"V reference, please verify"));
594 Serial.print(F(
"Enter a command:"));
604 uint16_t code1 = 0x0200;
605 uint16_t code2 = 0xFFFF;
609 Serial.print(
"Calibrating DAC ");
610 Serial.println((
char) (0x41 + index));
613 Serial.print(
"DAC code set to 0x");
614 Serial.println(code1, HEX);
615 Serial.print(
"Enter measured DAC voltage:");
617 Serial.print(voltage1, 6);
618 Serial.println(
" V");
621 Serial.print(
"DAC code set to 0x");
622 Serial.println(code2, HEX);
623 Serial.print(
"Enter measured DAC voltage:");
625 Serial.print(voltage2, 6);
626 Serial.println(
" V");
struct demo_board_type demo_board
Instantiate demo board structure.
char option
Demo Circuit option (A)
#define EXT_REF_V_BASE
Base address of the stored external reference voltage.
static uint8_t shift_count
The data align shift count.
static int8_t restore_calibration()
Read stored calibration parameters from nonvolatile EEPROM on demo board.
uint8_t eeprom_read_int16(uint8_t i2c_address, int16_t *read_data, uint16_t address)
Read the two byte integer data from the EEPROM starting at address.
const uint8_t address_map[5]
Lookup table for DAC address.
unsigned char user_command
static void loop()
Repeats Linduino loop.
#define EEPROM_I2C_ADDRESS
uint8_t eeprom_write_byte(uint8_t i2c_address, char data, uint16_t address)
Write the data byte to the EEPROM with i2c_address starting at EEPROM address.
#define EXT_CAL_VALID_BASE
Base address of the "external ref calibration valid" flag.
#define INT_CAL_VALID_BASE
Base address of the "internal ref calibration valid" flag.
static uint8_t reference_mode
Tells whether to set internal or external reference.
static void menu_1_select_dac(int16_t *selected_dac)
Select which DAC to operate on.
static float reference_voltage
Reference voltage, either internal or external.
Header File for Linduino Libraries and Demo Code.
static int16_t prompt_voltage_or_code()
Prompt user to enter a voltage or digital code to send to DAC.
#define LTC2654_CMD_POWER_DOWN
Power down n.
uint8_t eeprom_read_float(uint8_t i2c_address, float *read_data, uint16_t address)
Read the four byte float data from the EEPROM starting at address.
static void menu_4_update_power_up_dac(int16_t selected_dac)
Update DAC with data that is stored in input register, power up if sleeping.
#define LTC2654_CMD_WRITE
Write to input register n.
#define LTC2654_CMD_WRITE_UPDATE
Write to input register n, update (power up) all.
static int16_t LTC2654_offset[5]
DAC offset - index 4 for "all DACs".
static void menu_7_calibrate_dacs()
Calibrate all DACs by measuring two known outputs.
#define LTC2654_CMD_UPDATE
Update (power up) DAC register n.
static void menu_3_write_and_update_dac(int16_t selected_dac)
Write data to DAC register (which updates output immediately)
static void print_title()
Prints the title block when program first starts.
#define REF_INTERNAL
Stored reference state is Internal.
static uint16_t get_voltage(float LTC2654_lsb, int16_t LTC2654_offset)
Get voltage from user input, calculate DAC code based on lsb, offset.
uint8_t eeprom_write_float(uint8_t i2c_address, float write_data, uint16_t address)
Write the 4 byte float data to the EEPROM starting at address.
static void store_calibration()
Store measured calibration parameters to nonvolatile EEPROM on demo board.
uint8_t eeprom_write_int16(uint8_t i2c_address, int16_t write_data, uint16_t address)
Write the 2 byte integer data to the EEPROM starting at address.
static void menu_2_write_to_input_register(int16_t selected_dac)
Write data to input register, but do not update DAC output.
#define INT_CAL_PARAMS_BASE
Base address of the internal ref calibration parameters.
static void menu_6_set_reference_mode()
Set reference mode and store to EEPROM.
uint8_t eeprom_read_byte(uint8_t i2c_address, char *data, uint16_t address)
Read a data byte at address from the EEPROM with i2c_address.
static void menu_8_enable_calibration()
Enable / Disable calibration.
static void calibrate_dac(uint8_t index)
Calibrate the selected DAC using a voltmeter.
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
void LTC2654_calibrate(uint16_t dac_code1, uint16_t dac_code2, float voltage1, float voltage2, float *LTC2654_lsb, int16_t *LTC2654_offset)
Calculate the LTC2654 offset and LSB voltage given two measured voltages and their corresponding code...
int8_t discover_demo_board(char *demo_name)
Read the ID string from the EEPROM and determine if the correct board is connected.
LT_SPI: Routines to communicate with ATmega328P's hardware SPI port.
LT_I2C: Routines to communicate with ATmega328P's hardware I2C port.
static void menu_5_power_down_dac(int16_t selected_dac)
Power down DAC.
char demo_name[]
Demo Board Name stored in QuikEval EEPROM.
void quikeval_SPI_connect()
Connect SPI pins to QuikEval connector through the Linduino MUX. This will disconnect I2C...
#define STORED_REF_STATE_BASE
Base address of the stored reference state.
static void setup()
Initialize Linduino.
#define EXT_CAL_PARAMS_BASE
Base address of the external ref calibration parameters.
#define LTC2654_CS
Define the SPI CS pin.
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
#define REF_EXTERNAL
Stored reference state is External.
static uint8_t demo_board_connected
Set to 1 if the board is connected.
static uint16_t get_code()
Get code to send to DAC directly, in decimal, hex, or binary.
static void print_prompt(int16_t selected_dac)
Prints main menu.
static float LTC2654_lsb[5]
The LTC2654 lsb - index 4 for "all DACs".
uint16_t LTC2654_voltage_to_code(float dac_voltage, float LTC2654_lsb, int16_t LTC2654_offset)
Calculate a LTC2654 DAC code given the desired output voltage and DAC address (0-3) ...
void LTC2654_write(uint8_t cs, uint8_t dac_command, uint8_t dac_address, uint16_t dac_code)
Write the 16-bit dac_code to the LTC2654.
LTC2654: Quad SPI 16-/12-Bit Rail-to-Rail DACs with 10ppm/C Max Reference.