156 Serial.begin(115200);
171 uint8_t spi_error_code = 0;
172 static int16_t selected_dac = 0;
177 if (Serial.available())
182 Serial.println(user_command);
184 switch (user_command)
212 spi_error_code |= i2c_ack;
217 spi_error_code |= i2c_ack;
221 Serial.println(
"Incorrect Option");
225 if (i2c_ack != 0) Serial.println(F(
"Error: No Acknowledge. Check I2C Address."));
226 if (spi_error_code != 0) Serial.println(F(
"Error: SPI communication error."));
229 Serial.println(F(
"*************************"));
242 Serial.print(F(
"Type 1 to enter voltage, 2 to enter code:"));
245 Serial.println(user_input);
260 Serial.print(F(
"Enter Desired DAC output voltage: "));
262 Serial.print(dac_voltage);
263 Serial.println(F(
" V"));
274 Serial.println(F(
"Enter Desired DAC Code"));
275 Serial.print(F(
"(Format 32768, 0x8000, 0100000, or B1000000000000000): "));
277 Serial.print(F(
"0x"));
278 Serial.println(returncode, HEX);
286 Serial.println(F(
"*****************************************************************"));
287 Serial.println(F(
"* DC934A Demonstration Program *"));
288 Serial.println(F(
"* *"));
289 Serial.println(F(
"* This program demonstrates communication with the LTC2607 *"));
290 Serial.println(F(
"* 16-Bit Dual Rail-to-Rail DAC with I2C Interface. This board *"));
291 Serial.println(F(
"* also features an LTC2422 2-Channel 20-Bit uPower No Latency *"));
292 Serial.println(F(
"* Delta Sigma ADC for readback. *"));
293 Serial.println(F(
"* *"));
294 Serial.println(F(
"* Set the baud rate to 115200 select the newline terminator. *"));
295 Serial.println(F(
"*****************************************************************"));
301 Serial.println(F(
"\nCommand Summary:"));
303 Serial.println(F(
" 1-Select DAC"));
304 Serial.println(F(
" 2-Write to input register (no update)"));
305 Serial.println(F(
" 3-Write and update DAC"));
306 Serial.println(F(
" 4-Update/Power up DAC"));
307 Serial.println(F(
" 5-Power Down DAC"));
308 Serial.println(F(
" 6-Read ADC"));
309 Serial.println(F(
" 7-Sweep"));
310 Serial.println(F(
" 8-Calibrate ALL"));
312 Serial.print(F(
" Selected DAC: "));
313 if (selected_dac != 2)
314 Serial.println((
char) (selected_dac + 0x41));
316 Serial.println(F(
"All"));
318 Serial.print(F(
"Enter a command:"));
327 Serial.print(F(
"Select DAC to be updated (0=A, 1=B, 2=All)"));
329 if (*selected_dac > 2) *selected_dac=2;
330 if (*selected_dac == 2)
331 Serial.println(F(
"All"));
333 Serial.println(*selected_dac);
403 uint32_t adc_code_array[2];
414 adc_code_array[adc_channel] =
adc_code;
419 adc_code_array[adc_channel] =
adc_code;
423 Serial.print(F(
" ADC A : Code: 0x"));
424 Serial.println(adc_code_array[1], HEX);
425 Serial.print(F(
" Voltage: "));
427 Serial.println(adc_voltage, 6);
431 Serial.print(F(
" ADC B : Code: 0x"));
432 Serial.println(adc_code_array[0], HEX);
433 Serial.print(F(
" Voltage: "));
435 Serial.println(adc_voltage, 6);
444 Serial.print(F(
"Enter the desired number of sample points: "));
451 Serial.println(sample);
456 uint16_t sample_code;
457 sample_code = 65535/
sample;
467 if (adc_channel == 1)
476 Serial.println(F(
"Code, DAC A,DAC B"));
482 for (i = 0; i <=
sample; i++)
485 dac_code = (sample_code*
i);
486 if (dac_code > 65535)
499 Serial.print(dac_code);
500 Serial.print(F(
","));
502 Serial.print(adc_voltage, 6);
503 Serial.print(F(
","));
510 Serial.println(adc_voltage, 6);
514 if (adc_channel == 1)
516 Serial.println(F(
"Out of sync!!"));
525 Serial.println(F(
"Copy and save data points to a .csv file"));
526 Serial.println(F(
"and open in Excel to plot points."));
537 const uint16_t CAL_LOW_DAC_CODE = 0x00FF;
538 const uint16_t CAL_HIGH_DAC_CODE = 0xFF00;
541 Serial.println(F(
"Measure and Enter Reference "));
542 Serial.print(F(
"Voltage for The ADC: "));
546 Serial.println(ref_voltage, 6);
554 Serial.print(F(
"Calibrating DACs ... "));
569 if (adc_channel == 0)
571 if (adc_channel == 1)
576 if (adc_channel == 0)
578 if (adc_channel == 1)
597 if (adc_channel == 0)
599 if (adc_channel == 1)
604 if (adc_channel == 0)
606 if (adc_channel == 1)
614 Serial.println(F(
"Calibration Complete"));
616 Serial.print(F(
"lsb DAC A: "));
618 Serial.print(F(
" V offset: "));
621 Serial.print(F(
"lsb DAC B: "));
623 Serial.print(F(
" V offset: "));
626 Serial.print(F(
"All DACs: "));
628 Serial.print(F(
" V offset: "));
static int32_t LTC2607_offset[3]
The LTC2422 offset variable.
LTC2422: 1-/2-Channel 20-Bit uPower No Latency Delta-Sigma ADC in MSOP-10.
#define LTC2607_WRITE_COMMAND
Command to write to internal register of LTC2607, but not update output voltage yet.
unsigned char user_command
static void loop()
Repeats Linduino loop.
const uint16_t MISO_TIMEOUT
The MISO timout in ms.
float LTC2422_code_to_voltage(int32_t adc_code, float LTC2422_lsb)
Calculates the voltage given the ADC code and lsb weight.
uint16_t LTC2607_voltage_to_code(float dac_voltage, float LTC2607_lsb, int32_t LTC2607_offset)
Calculates an LTC2607 DAC code for the desired output voltage.
const float LTC2422_TYPICAL_lsb
The LTC2422 typical least significant bit value with 5V full-scale.
void LTC2607_calibrate(uint16_t dac_code1, uint16_t dac_code2, float voltage1, float voltage2, float *LTC2607_lsb, int32_t *LTC2607_offset)
Calculates the LTC2607 offset and lsb voltage given two measured voltages and their corresponding DAC...
#define output_high(pin)
Set "pin" high.
const float LTC2607_TYPICAL_OFFSET
The LTC2607 typical offset voltage.
static float LTC2607_lsb[3]
The LTC2607 least significant bit value with 5V full-scale.
static void setup()
Initialize Linduino.
Header File for Linduino Libraries and Demo Code.
static int8_t demo_board_connected
Set to 1 if the board is connected.
const uint16_t LTC2422_TIMEOUT
Configures the maximum timeout (ms) allowed for an LTC2607 read.
const float LTC2607_TYPICAL_lsb
The LTC2607 typical least significant bit value with 5V full-scale.
#define LTC2607_ALL_DACS
Command (and DAC code) will modify both DAC A and DAC B.
static uint8_t menu_3_write_and_update_dac(int16_t selected_dac)
Menu 3: Write to input register and update output voltage.
static void print_title()
Prints the title block.
static uint8_t menu_2_write_to_input_register(int16_t selected_dac)
Menu 2: Write to input register only.
void LTC2422_adc_read(uint8_t cs, uint8_t *adc_channel, int32_t *code)
Read ADC code from the LTC2422.
#define LTC2607_WRITE_UPDATE_COMMAND
Command to write and update (and power up) the LTC2607.
static uint16_t get_code()
static uint8_t menu_7_sweep()
Menu 7: Voltage Sweep.
LT_I2C: Routines to communicate with ATmega328P's hardware I2C port.
static uint8_t menu_8_calibrate_all()
Menu 8: Calibrate All.
static uint8_t menu_5_power_down_dac(int16_t selected_dac)
Menu 5: Power Down DAC.
#define LTC2607_UPDATE_COMMAND
Command to update (and power up) LTC2607.
void quikeval_SPI_init(void)
Configure the SPI port for 4Mhz SCK.
int8_t discover_demo_board(char *demo_name)
Read the ID string from the EEPROM and determine if the correct board is connected.
static void print_prompt(int16_t selected_dac)
Prints the main menu, and prompts the user for an input command.
const uint8_t address_map[3]
Look-up table for DAC_A, DAC_B, or both command byte option.
LT_SPI: Routines to communicate with ATmega328P's hardware SPI port.
static int16_t prompt_voltage_or_code()
Prompts user to find out if they want to enter DAC code as a "voltage" or a "code".
#define LTC2607_POWER_DOWN_COMMAND
Command to power down the LTC2607.
LT_I2C: Routines to communicate with ATmega328P's hardware I2C port.
#define LTC2607_DAC_B
Command (and DAC code) will modify DAC B.
static uint8_t menu_6_read_adc()
Menu 6: Read voltage from the ADC.
void LTC2422_calculate_lsb(float LTC2422_reference_voltage, float *LTC2422_lsb)
Calculates the lsb weight from the given reference voltage.
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 LTC2607_I2C_GLOBAL_ADDRESS
LTC2607 Global I2C Address.
prompt
Used to keep track to print voltage or print code.
#define LTC2422_CS
Define the SPI CS pin.
static uint8_t menu_1_select_dac(int16_t *selected_dac)
Menu 1: Select DAC to update.
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
void quikeval_I2C_connect(void)
Switch MUX to connect I2C pins to QuikEval connector.
LTC2607: 16-Bit, Dual Rail-to-Rail DACs with I2C Interface.
int8_t LTC2607_write(uint8_t i2c_address, uint8_t dac_command, uint8_t dac_address, uint16_t dac_code)
Writes command, DAC address, and DAC code to the LTC2607.
#define LTC2607_DAC_A
Command (and DAC code) will modify DAC A.
static float LTC2422_lsb
The LTC2422 least significant bit value with 5V full-scale.
uint8_t LTC2422_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
Checks for EOC with a specified timeout.
static uint16_t get_voltage(float LTC2607_lsb, int32_t LTC2607_offset)
Read desired DAC output voltage from user input.
static uint8_t menu_4_update_power_up_dac(int16_t selected_dac)
Menu 4: Update/Power Up DAC.