Example host software for the Maxim Integrated DS4424/DS4422 I2C Sink/Source Current DAC. Hosted on the MAX32630FTHR.

Dependencies:   max32630fthr DS4424_SINK_SOURCE_CURRENT_DAC_INPUT_OUTPUT_DAC USBDevice

Committer:
phonemacro
Date:
Sun Jan 27 00:33:06 2019 +0000
Revision:
9:36e3c385f119
Parent:
8:5bbefd9bce9f
revert the last commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phonemacro 0:a3f9ce6b99f5 1 /*******************************************************************************
phonemacro 9:36e3c385f119 2 * Copyright (C) 2018-2019 Maxim Integrated Products, Inc., All Rights Reserved.
phonemacro 0:a3f9ce6b99f5 3 *
phonemacro 0:a3f9ce6b99f5 4 * Permission is hereby granted, free of charge, to any person obtaining a
phonemacro 0:a3f9ce6b99f5 5 * copy of this software and associated documentation files (the "Software"),
phonemacro 0:a3f9ce6b99f5 6 * to deal in the Software without restriction, including without limitation
phonemacro 0:a3f9ce6b99f5 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
phonemacro 0:a3f9ce6b99f5 8 * and/or sell copies of the Software, and to permit persons to whom the
phonemacro 0:a3f9ce6b99f5 9 * Software is furnished to do so, subject to the following conditions:
phonemacro 0:a3f9ce6b99f5 10 *
phonemacro 0:a3f9ce6b99f5 11 * The above copyright notice and this permission notice shall be included
phonemacro 0:a3f9ce6b99f5 12 * in all copies or substantial portions of the Software.
phonemacro 0:a3f9ce6b99f5 13 *
phonemacro 0:a3f9ce6b99f5 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
phonemacro 0:a3f9ce6b99f5 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
phonemacro 0:a3f9ce6b99f5 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
phonemacro 0:a3f9ce6b99f5 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
phonemacro 0:a3f9ce6b99f5 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
phonemacro 0:a3f9ce6b99f5 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
phonemacro 0:a3f9ce6b99f5 20 * OTHER DEALINGS IN THE SOFTWARE.
phonemacro 0:a3f9ce6b99f5 21 *
phonemacro 0:a3f9ce6b99f5 22 * Except as contained in this notice, the name of Maxim Integrated
phonemacro 0:a3f9ce6b99f5 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
phonemacro 0:a3f9ce6b99f5 24 * Products, Inc. Branding Policy.
phonemacro 0:a3f9ce6b99f5 25 *
phonemacro 0:a3f9ce6b99f5 26 * The mere transfer of this software does not imply any licenses
phonemacro 0:a3f9ce6b99f5 27 * of trade secrets, proprietary technology, copyrights, patents,
phonemacro 0:a3f9ce6b99f5 28 * trademarks, maskwork rights, or any other form of intellectual
phonemacro 0:a3f9ce6b99f5 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
phonemacro 0:a3f9ce6b99f5 30 * ownership rights.
phonemacro 0:a3f9ce6b99f5 31 *******************************************************************************
phonemacro 0:a3f9ce6b99f5 32 */
phonemacro 0:a3f9ce6b99f5 33 #include "mbed.h"
phonemacro 0:a3f9ce6b99f5 34 #include "max32630fthr.h"
phonemacro 9:36e3c385f119 35 #include "DS4424.h"
phonemacro 9:36e3c385f119 36
phonemacro 0:a3f9ce6b99f5 37 #include "USBSerial.h"
phonemacro 0:a3f9ce6b99f5 38
phonemacro 0:a3f9ce6b99f5 39 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
phonemacro 0:a3f9ce6b99f5 40
phonemacro 0:a3f9ce6b99f5 41 DigitalOut rLED(LED1);
phonemacro 0:a3f9ce6b99f5 42 DigitalOut gLED(LED2);
phonemacro 0:a3f9ce6b99f5 43 DigitalOut bLED(LED3);
phonemacro 1:a7990c969d1a 44
phonemacro 9:36e3c385f119 45 I2C i2cBus(P3_4, P3_5);
phonemacro 1:a7990c969d1a 46
phonemacro 9:36e3c385f119 47 DS4424 ds4424_dac(i2cBus, DS4424::DS4424_I2C_SLAVE_ADRS0, DS4424::DS4424_IC);
phonemacro 9:36e3c385f119 48
phonemacro 4:51c1a4c4f762 49 /** main() runs in its own thread in the OS */
phonemacro 4:51c1a4c4f762 50 /** (note the calls to Thread::wait below for delays) */
phonemacro 2:07fde4ba8e91 51 /**
phonemacro 9:36e3c385f119 52 * @brief Sample main program for Maxim Integrated DS4424, DS4422
phonemacro 9:36e3c385f119 53 * @version 1.0000.301
phonemacro 4:51c1a4c4f762 54 *
phonemacro 9:36e3c385f119 55 * @details Sample main program for DS4424, DS4422
phonemacro 4:51c1a4c4f762 56 * The prints are sent to the terminal window (9600, 8n1).
phonemacro 9:36e3c385f119 57 * The program sets the output DAC registers to various values.
phonemacro 9:36e3c385f119 58 * These registers are then read back and printed out.
phonemacro 9:36e3c385f119 59 * The program then blinks the blue-green LED.
phonemacro 4:51c1a4c4f762 60 * To run the program, drag and drop the .bin file into the
phonemacro 4:51c1a4c4f762 61 * DAPLINK folder. After it finishes flashing, cycle the power or
phonemacro 4:51c1a4c4f762 62 * reset the Pegasus (MAX32630FTHR) after flashing by pressing the button on
phonemacro 4:51c1a4c4f762 63 * the Pegasus next to the battery connector or the button
phonemacro 4:51c1a4c4f762 64 * on the MAXREFDES100HDK.
phonemacro 4:51c1a4c4f762 65 */
phonemacro 0:a3f9ce6b99f5 66 int main()
phonemacro 0:a3f9ce6b99f5 67 {
phonemacro 9:36e3c385f119 68 int32_t in_pAmps[4] = {-193675000, -1525000, 6100000, -16012500};
phonemacro 9:36e3c385f119 69 uint8_t in_raw[4];
phonemacro 9:36e3c385f119 70 int32_t value[4] = {0, 0, 0, 0};
phonemacro 0:a3f9ce6b99f5 71 int ret, i;
phonemacro 9:36e3c385f119 72 int32_t out_pAmps[4] = {0, 0, 0, 0};
phonemacro 9:36e3c385f119 73 uint32_t rfs_board[4] = {40000, 80000, 100000, 160000};
phonemacro 9:36e3c385f119 74
phonemacro 0:a3f9ce6b99f5 75 DigitalOut rLED(LED1, LED_OFF);
phonemacro 0:a3f9ce6b99f5 76 DigitalOut gLED(LED2, LED_OFF);
phonemacro 0:a3f9ce6b99f5 77 DigitalOut bLED(LED3, LED_OFF);
phonemacro 0:a3f9ce6b99f5 78
phonemacro 9:36e3c385f119 79 bLED = LED_ON;
phonemacro 0:a3f9ce6b99f5 80 gLED = LED_ON;
phonemacro 0:a3f9ce6b99f5 81
phonemacro 9:36e3c385f119 82 i2cBus.frequency(400000);
phonemacro 9:36e3c385f119 83 printf("\r\n");
phonemacro 9:36e3c385f119 84
phonemacro 9:36e3c385f119 85 /* write to each channel using picoAmps */
phonemacro 9:36e3c385f119 86 for (i = 0; i < 4; i++) {
phonemacro 9:36e3c385f119 87 ret = ds4424_dac.convert_picoAmps_to_hw_raw(&in_raw[i], in_pAmps[i], rfs_board[i]);
phonemacro 9:36e3c385f119 88 printf("Set picoAmps Out %d picoAmps, hw raw = %d, rfs = %d Ohms\r\n", in_pAmps[i], in_raw[i], rfs_board[i]);
phonemacro 9:36e3c385f119 89 }
phonemacro 9:36e3c385f119 90 printf("\r\n");
phonemacro 9:36e3c385f119 91 ret = ds4424_dac.write_hw_raw(in_raw[0], DS4424::REG_OUT0);
phonemacro 9:36e3c385f119 92 ret = ds4424_dac.write_hw_raw(in_raw[1], DS4424::REG_OUT1);
phonemacro 9:36e3c385f119 93 ret = ds4424_dac.write_hw_raw(in_raw[2], DS4424::REG_OUT2);
phonemacro 9:36e3c385f119 94 ret = ds4424_dac.write_hw_raw(in_raw[3], DS4424::REG_OUT3);
phonemacro 0:a3f9ce6b99f5 95
phonemacro 9:36e3c385f119 96 /* write to each channel using two's complement */
phonemacro 9:36e3c385f119 97 /*
phonemacro 9:36e3c385f119 98 ret = ds4424_dac.write_raw(-127, DS4424::REG_OUT0);
phonemacro 9:36e3c385f119 99 ret = ds4424_dac.write_raw(-2, DS4424::REG_OUT1);
phonemacro 9:36e3c385f119 100 ret = ds4424_dac.write_raw(10, DS4424::REG_OUT2);
phonemacro 9:36e3c385f119 101 ret = ds4424_dac.write_raw(-42, DS4424::REG_OUT3);
phonemacro 9:36e3c385f119 102 */
phonemacro 9:36e3c385f119 103 ret = ds4424_dac.read_hw_raw(in_raw[0], DS4424::REG_OUT0);
phonemacro 9:36e3c385f119 104 ret = ds4424_dac.read_hw_raw(in_raw[1], DS4424::REG_OUT1);
phonemacro 9:36e3c385f119 105 ret = ds4424_dac.read_hw_raw(in_raw[2], DS4424::REG_OUT2);
phonemacro 9:36e3c385f119 106 ret = ds4424_dac.read_hw_raw(in_raw[3], DS4424::REG_OUT3);
phonemacro 9:36e3c385f119 107 for (i = 0; i < 4; i++) {
phonemacro 9:36e3c385f119 108 printf("Read hw raw Out %d = %d\r\n", i, in_raw[i]);
phonemacro 9:36e3c385f119 109 }
phonemacro 7:bf8c91e28a3b 110 printf("\r\n");
phonemacro 9:36e3c385f119 111
phonemacro 9:36e3c385f119 112 ret = ds4424_dac.read_raw(value[0], DS4424::REG_OUT0);
phonemacro 9:36e3c385f119 113 ret = ds4424_dac.read_raw(value[1], DS4424::REG_OUT1);
phonemacro 9:36e3c385f119 114 ret = ds4424_dac.read_raw(value[2], DS4424::REG_OUT2);
phonemacro 9:36e3c385f119 115 ret = ds4424_dac.read_raw(value[3], DS4424::REG_OUT3);
phonemacro 9:36e3c385f119 116 for (i = 0; i < 4; i++) {
phonemacro 9:36e3c385f119 117 printf("Read raw two's complement Out %d = %d\r\n", i, value[i]);
phonemacro 9:36e3c385f119 118 }
phonemacro 9:36e3c385f119 119 printf("\r\n");
phonemacro 9:36e3c385f119 120
phonemacro 9:36e3c385f119 121 /* Convert two's complement values to picoAmps */
phonemacro 9:36e3c385f119 122 for (i = 0; i < 4; i++) {
phonemacro 9:36e3c385f119 123 ret = ds4424_dac.convert_raw_to_picoAmps(&out_pAmps[i], value[i], rfs_board[i]);
phonemacro 9:36e3c385f119 124 printf("Read Out %d = %d picoAmps, rfs = %d Ohms\r\n", i, out_pAmps[i], rfs_board[i]);
phonemacro 9:36e3c385f119 125 }
phonemacro 9:36e3c385f119 126 printf("\r\n");
phonemacro 9:36e3c385f119 127
phonemacro 9:36e3c385f119 128 while (true) { // Blink the blue-green LED
phonemacro 9:36e3c385f119 129 bLED = !bLED;
phonemacro 0:a3f9ce6b99f5 130 gLED = !gLED;
phonemacro 0:a3f9ce6b99f5 131 wait(1.0);
phonemacro 0:a3f9ce6b99f5 132 }
phonemacro 0:a3f9ce6b99f5 133 }