Maxim Integrated MAX5171 14-bit Force/Sense DAC

Dependents:   MAX5171BOB_Tester MAX5171BOB_14bit_Remote_Sense_SPI_DAC MAX5171BOB_Serial_Tester

Committer:
whismanoid
Date:
Fri May 15 08:23:46 2020 +0000
Revision:
7:564b438a0448
Parent:
6:f661c4a61207
Support MAX5171BOB self test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
whismanoid 1:e73245718b2a 1 // /*******************************************************************************
whismanoid 5:e8c0dfaeb53b 2 // * Copyright (C) 2020 Maxim Integrated Products, Inc., All Rights Reserved.
whismanoid 1:e73245718b2a 3 // *
whismanoid 1:e73245718b2a 4 // * Permission is hereby granted, free of charge, to any person obtaining a
whismanoid 1:e73245718b2a 5 // * copy of this software and associated documentation files (the "Software"),
whismanoid 1:e73245718b2a 6 // * to deal in the Software without restriction, including without limitation
whismanoid 1:e73245718b2a 7 // * the rights to use, copy, modify, merge, publish, distribute, sublicense,
whismanoid 1:e73245718b2a 8 // * and/or sell copies of the Software, and to permit persons to whom the
whismanoid 1:e73245718b2a 9 // * Software is furnished to do so, subject to the following conditions:
whismanoid 1:e73245718b2a 10 // *
whismanoid 1:e73245718b2a 11 // * The above copyright notice and this permission notice shall be included
whismanoid 1:e73245718b2a 12 // * in all copies or substantial portions of the Software.
whismanoid 1:e73245718b2a 13 // *
whismanoid 1:e73245718b2a 14 // * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
whismanoid 1:e73245718b2a 15 // * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
whismanoid 1:e73245718b2a 16 // * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
whismanoid 1:e73245718b2a 17 // * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
whismanoid 1:e73245718b2a 18 // * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
whismanoid 1:e73245718b2a 19 // * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
whismanoid 1:e73245718b2a 20 // * OTHER DEALINGS IN THE SOFTWARE.
whismanoid 1:e73245718b2a 21 // *
whismanoid 1:e73245718b2a 22 // * Except as contained in this notice, the name of Maxim Integrated
whismanoid 1:e73245718b2a 23 // * Products, Inc. shall not be used except as stated in the Maxim Integrated
whismanoid 1:e73245718b2a 24 // * Products, Inc. Branding Policy.
whismanoid 1:e73245718b2a 25 // *
whismanoid 1:e73245718b2a 26 // * The mere transfer of this software does not imply any licenses
whismanoid 1:e73245718b2a 27 // * of trade secrets, proprietary technology, copyrights, patents,
whismanoid 1:e73245718b2a 28 // * trademarks, maskwork rights, or any other form of intellectual
whismanoid 1:e73245718b2a 29 // * property whatsoever. Maxim Integrated Products, Inc. retains all
whismanoid 1:e73245718b2a 30 // * ownership rights.
whismanoid 1:e73245718b2a 31 // *******************************************************************************
whismanoid 1:e73245718b2a 32 // */
whismanoid 1:e73245718b2a 33 // *********************************************************************
whismanoid 1:e73245718b2a 34 // @file MAX5171.h
whismanoid 1:e73245718b2a 35 // *********************************************************************
whismanoid 1:e73245718b2a 36 // Header file
whismanoid 1:e73245718b2a 37 // DO NOT EDIT; except areas designated "CUSTOMIZE". Automatically generated file.
whismanoid 1:e73245718b2a 38 // generated by XMLSystemOfDevicesToMBED.py
whismanoid 1:e73245718b2a 39 // System Name = ExampleSystem
whismanoid 1:e73245718b2a 40 // System Description = Device driver example
whismanoid 1:e73245718b2a 41 // Device Name = MAX5171
whismanoid 1:e73245718b2a 42 // Device Description = Low-Power, Serial, 14-Bit, 1-Channel DACs with Force/Sense Voltage Output and SPI Interface
whismanoid 5:e8c0dfaeb53b 43 // Device DeviceBriefDescription = 14-bit Force/Sense DAC
whismanoid 1:e73245718b2a 44 // Device Manufacturer = Maxim Integrated
whismanoid 1:e73245718b2a 45 // Device PartNumber = MAX5171AEEE+
whismanoid 1:e73245718b2a 46 // Device RegValue_Width = DataWidth16bit_HL
whismanoid 1:e73245718b2a 47 //
whismanoid 1:e73245718b2a 48 // DAC NumChannels = 1
whismanoid 1:e73245718b2a 49 // DAC ResolutionBits = 14
whismanoid 1:e73245718b2a 50 //
whismanoid 1:e73245718b2a 51 // SPI CS = ActiveLow
whismanoid 1:e73245718b2a 52 // SPI FrameStart = CS
whismanoid 1:e73245718b2a 53 // SPI CPOL = 0
whismanoid 1:e73245718b2a 54 // SPI CPHA = 0
whismanoid 1:e73245718b2a 55 // SPI MOSI and MISO Data are both stable on Rising edge of SCLK
whismanoid 1:e73245718b2a 56 // SPI SCLK Idle Low
whismanoid 1:e73245718b2a 57 // SPI SCLKMaxMHz = 10
whismanoid 1:e73245718b2a 58 // SPI SCLKMinMHz = 0
whismanoid 1:e73245718b2a 59 //
whismanoid 1:e73245718b2a 60
whismanoid 1:e73245718b2a 61
whismanoid 1:e73245718b2a 62 // Prevent multiple declaration
whismanoid 1:e73245718b2a 63 #ifndef __MAX5171_H__
whismanoid 1:e73245718b2a 64 #define __MAX5171_H__
whismanoid 1:e73245718b2a 65
whismanoid 5:e8c0dfaeb53b 66 // standard include for target platform -- Platform_Include_Boilerplate
whismanoid 1:e73245718b2a 67 #include "mbed.h"
whismanoid 5:e8c0dfaeb53b 68 // Platforms:
whismanoid 5:e8c0dfaeb53b 69 // - MAX32625MBED
whismanoid 5:e8c0dfaeb53b 70 // - supports mbed-os-5.11, requires USBDevice library
whismanoid 5:e8c0dfaeb53b 71 // - add https://developer.mbed.org/teams/MaximIntegrated/code/USBDevice/
whismanoid 5:e8c0dfaeb53b 72 // - remove max32630fthr library (if present)
whismanoid 5:e8c0dfaeb53b 73 // - remove MAX32620FTHR library (if present)
whismanoid 5:e8c0dfaeb53b 74 // - MAX32600MBED
whismanoid 5:e8c0dfaeb53b 75 // - remove max32630fthr library (if present)
whismanoid 5:e8c0dfaeb53b 76 // - remove MAX32620FTHR library (if present)
whismanoid 5:e8c0dfaeb53b 77 // - Windows 10 note: Don't connect HDK until you are ready to load new firmware into the board.
whismanoid 5:e8c0dfaeb53b 78 // - NUCLEO_F446RE
whismanoid 5:e8c0dfaeb53b 79 // - remove USBDevice library
whismanoid 5:e8c0dfaeb53b 80 // - remove max32630fthr library (if present)
whismanoid 5:e8c0dfaeb53b 81 // - remove MAX32620FTHR library (if present)
whismanoid 5:e8c0dfaeb53b 82 // - NUCLEO_F401RE
whismanoid 5:e8c0dfaeb53b 83 // - remove USBDevice library
whismanoid 5:e8c0dfaeb53b 84 // - remove max32630fthr library (if present)
whismanoid 5:e8c0dfaeb53b 85 // - remove MAX32620FTHR library (if present)
whismanoid 5:e8c0dfaeb53b 86 // - MAX32630FTHR
whismanoid 5:e8c0dfaeb53b 87 // - #include "max32630fthr.h"
whismanoid 5:e8c0dfaeb53b 88 // - add http://os.mbed.org/teams/MaximIntegrated/code/max32630fthr/
whismanoid 5:e8c0dfaeb53b 89 // - remove MAX32620FTHR library (if present)
whismanoid 5:e8c0dfaeb53b 90 // - MAX32620FTHR
whismanoid 5:e8c0dfaeb53b 91 // - #include "MAX32620FTHR.h"
whismanoid 5:e8c0dfaeb53b 92 // - remove max32630fthr library (if present)
whismanoid 5:e8c0dfaeb53b 93 // - add https://os.mbed.com/teams/MaximIntegrated/code/MAX32620FTHR/
whismanoid 5:e8c0dfaeb53b 94 // - not tested yet
whismanoid 5:e8c0dfaeb53b 95 // - MAX32625PICO
whismanoid 5:e8c0dfaeb53b 96 // - remove max32630fthr library (if present)
whismanoid 5:e8c0dfaeb53b 97 // - remove MAX32620FTHR library (if present)
whismanoid 5:e8c0dfaeb53b 98 // - not tested yet
whismanoid 5:e8c0dfaeb53b 99 //
whismanoid 5:e8c0dfaeb53b 100 // end Platform_Include_Boilerplate
whismanoid 1:e73245718b2a 101
whismanoid 1:e73245718b2a 102 /**
whismanoid 1:e73245718b2a 103 * @brief MAX5171 Low-Power, Serial, 14-Bit, 1-Channel DACs with Force/Sense Voltage Output and SPI Interface
whismanoid 1:e73245718b2a 104 *
whismanoid 1:e73245718b2a 105 *
whismanoid 1:e73245718b2a 106 *
whismanoid 1:e73245718b2a 107 * Datasheet: https://www.maximintegrated.com/MAX5171
whismanoid 1:e73245718b2a 108 *
whismanoid 1:e73245718b2a 109 *
whismanoid 1:e73245718b2a 110 *
whismanoid 1:e73245718b2a 111 * @code
whismanoid 1:e73245718b2a 112 * // example code includes
whismanoid 5:e8c0dfaeb53b 113 * // standard include for target platform -- Platform_Include_Boilerplate
whismanoid 1:e73245718b2a 114 * #include "mbed.h"
whismanoid 5:e8c0dfaeb53b 115 * // Platforms:
whismanoid 5:e8c0dfaeb53b 116 * // - MAX32625MBED
whismanoid 4:1984eef51fe3 117 * // - supports mbed-os-5.11, requires USBDevice library
whismanoid 5:e8c0dfaeb53b 118 * // - add https://developer.mbed.org/teams/MaximIntegrated/code/USBDevice/
whismanoid 5:e8c0dfaeb53b 119 * // - remove max32630fthr library (if present)
whismanoid 5:e8c0dfaeb53b 120 * // - remove MAX32620FTHR library (if present)
whismanoid 5:e8c0dfaeb53b 121 * // - MAX32600MBED
whismanoid 5:e8c0dfaeb53b 122 * // - remove max32630fthr library (if present)
whismanoid 5:e8c0dfaeb53b 123 * // - remove MAX32620FTHR library (if present)
whismanoid 5:e8c0dfaeb53b 124 * // - Windows 10 note: Don't connect HDK until you are ready to load new firmware into the board.
whismanoid 5:e8c0dfaeb53b 125 * // - NUCLEO_F446RE
whismanoid 5:e8c0dfaeb53b 126 * // - remove USBDevice library
whismanoid 5:e8c0dfaeb53b 127 * // - remove max32630fthr library (if present)
whismanoid 5:e8c0dfaeb53b 128 * // - remove MAX32620FTHR library (if present)
whismanoid 5:e8c0dfaeb53b 129 * // - NUCLEO_F401RE
whismanoid 5:e8c0dfaeb53b 130 * // - remove USBDevice library
whismanoid 5:e8c0dfaeb53b 131 * // - remove max32630fthr library (if present)
whismanoid 5:e8c0dfaeb53b 132 * // - remove MAX32620FTHR library (if present)
whismanoid 5:e8c0dfaeb53b 133 * // - MAX32630FTHR
whismanoid 5:e8c0dfaeb53b 134 * // - #include "max32630fthr.h"
whismanoid 5:e8c0dfaeb53b 135 * // - add http://os.mbed.org/teams/MaximIntegrated/code/max32630fthr/
whismanoid 5:e8c0dfaeb53b 136 * // - remove MAX32620FTHR library (if present)
whismanoid 5:e8c0dfaeb53b 137 * // - MAX32620FTHR
whismanoid 5:e8c0dfaeb53b 138 * // - #include "MAX32620FTHR.h"
whismanoid 5:e8c0dfaeb53b 139 * // - remove max32630fthr library (if present)
whismanoid 5:e8c0dfaeb53b 140 * // - add https://os.mbed.com/teams/MaximIntegrated/code/MAX32620FTHR/
whismanoid 5:e8c0dfaeb53b 141 * // - not tested yet
whismanoid 5:e8c0dfaeb53b 142 * // - MAX32625PICO
whismanoid 5:e8c0dfaeb53b 143 * // - remove max32630fthr library (if present)
whismanoid 5:e8c0dfaeb53b 144 * // - remove MAX32620FTHR library (if present)
whismanoid 5:e8c0dfaeb53b 145 * // - not tested yet
whismanoid 5:e8c0dfaeb53b 146 * //
whismanoid 5:e8c0dfaeb53b 147 * // end Platform_Include_Boilerplate
whismanoid 1:e73245718b2a 148 * #include "MAX5171.h"
whismanoid 1:e73245718b2a 149 *
whismanoid 1:e73245718b2a 150 * // example code board support
whismanoid 1:e73245718b2a 151 * //MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
whismanoid 1:e73245718b2a 152 * //DigitalOut rLED(LED1);
whismanoid 1:e73245718b2a 153 * //DigitalOut gLED(LED2);
whismanoid 1:e73245718b2a 154 * //DigitalOut bLED(LED3);
whismanoid 1:e73245718b2a 155 * //
whismanoid 1:e73245718b2a 156 * // Arduino "shield" connector port definitions (MAX32625MBED shown)
whismanoid 1:e73245718b2a 157 * #if defined(TARGET_MAX32625MBED)
whismanoid 1:e73245718b2a 158 * #define A0 AIN_0
whismanoid 1:e73245718b2a 159 * #define A1 AIN_1
whismanoid 1:e73245718b2a 160 * #define A2 AIN_2
whismanoid 1:e73245718b2a 161 * #define A3 AIN_3
whismanoid 1:e73245718b2a 162 * #define D0 P0_0
whismanoid 1:e73245718b2a 163 * #define D1 P0_1
whismanoid 1:e73245718b2a 164 * #define D2 P0_2
whismanoid 1:e73245718b2a 165 * #define D3 P0_3
whismanoid 1:e73245718b2a 166 * #define D4 P0_4
whismanoid 1:e73245718b2a 167 * #define D5 P0_5
whismanoid 1:e73245718b2a 168 * #define D6 P0_6
whismanoid 1:e73245718b2a 169 * #define D7 P0_7
whismanoid 1:e73245718b2a 170 * #define D8 P1_4
whismanoid 1:e73245718b2a 171 * #define D9 P1_5
whismanoid 1:e73245718b2a 172 * #define D10 P1_3
whismanoid 1:e73245718b2a 173 * #define D11 P1_1
whismanoid 1:e73245718b2a 174 * #define D12 P1_2
whismanoid 1:e73245718b2a 175 * #define D13 P1_0
whismanoid 1:e73245718b2a 176 * #endif
whismanoid 1:e73245718b2a 177 *
whismanoid 6:f661c4a61207 178 * // example code declare SPI interface (GPIO controlled CS)
whismanoid 1:e73245718b2a 179 * #if defined(TARGET_MAX32625MBED)
whismanoid 1:e73245718b2a 180 * SPI spi(SPI1_MOSI, SPI1_MISO, SPI1_SCK); // mosi, miso, sclk spi1 TARGET_MAX32625MBED: P1_1 P1_2 P1_0 Arduino 10-pin header D11 D12 D13
whismanoid 1:e73245718b2a 181 * DigitalOut spi_cs(SPI1_SS); // TARGET_MAX32625MBED: P1_3 Arduino 10-pin header D10
whismanoid 1:e73245718b2a 182 * #elif defined(TARGET_MAX32600MBED)
whismanoid 1:e73245718b2a 183 * SPI spi(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13
whismanoid 1:e73245718b2a 184 * DigitalOut spi_cs(SPI2_SS); // Generic: Arduino 10-pin header D10
whismanoid 6:f661c4a61207 185 * #elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F401RE)
whismanoid 6:f661c4a61207 186 * // TODO1: avoid resource conflict between P5_0, P5_1, P5_2 SPI and DigitalInOut
whismanoid 6:f661c4a61207 187 * // void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
whismanoid 6:f661c4a61207 188 * //
whismanoid 6:f661c4a61207 189 * // TODO1: NUCLEO_F446RE SPI not working; CS and MOSI data looks OK but no SCLK clock pulses.
whismanoid 6:f661c4a61207 190 * SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); // mosi, miso, sclk spi1 TARGET_NUCLEO_F446RE: Arduino 10-pin header D11 D12 D13
whismanoid 6:f661c4a61207 191 * DigitalOut spi_cs(SPI_CS); // TARGET_NUCLEO_F446RE: PB_6 Arduino 10-pin header D10
whismanoid 6:f661c4a61207 192 * //
whismanoid 1:e73245718b2a 193 * #else
whismanoid 1:e73245718b2a 194 * SPI spi(D11, D12, D13); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13
whismanoid 1:e73245718b2a 195 * DigitalOut spi_cs(D10); // Generic: Arduino 10-pin header D10
whismanoid 1:e73245718b2a 196 * #endif
whismanoid 1:e73245718b2a 197 *
whismanoid 1:e73245718b2a 198 * // example code declare GPIO interface pins
whismanoid 1:e73245718b2a 199 * // AnalogOut FB_pin(Px_x_PortName_To_Be_Determined); // Analog Input to MAX5171 device
whismanoid 1:e73245718b2a 200 * DigitalOut RS_pin(D9); // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 201 * DigitalOut PDLb_pin(D8); // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 202 * DigitalOut CLRb_pin(D7); // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 203 * DigitalOut SHDN_pin(D6); // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 204 * // AnalogIn OUT_pin(A0); // Analog Output from MAX5171 device
whismanoid 1:e73245718b2a 205 * DigitalIn UPO_pin(D5); // Digital General-Purpose Output from MAX5171 device
whismanoid 1:e73245718b2a 206 * // example code declare device instance
whismanoid 1:e73245718b2a 207 * MAX5171 g_MAX5171_device(spi, spi_cs, RS_pin, PDLb_pin, CLRb_pin, SHDN_pin, UPO_pin, MAX5171::MAX5171_IC);
whismanoid 1:e73245718b2a 208 *
whismanoid 1:e73245718b2a 209 * // example code main function
whismanoid 1:e73245718b2a 210 * int main()
whismanoid 1:e73245718b2a 211 * {
whismanoid 5:e8c0dfaeb53b 212 * g_MAX5171_device.Init();
whismanoid 5:e8c0dfaeb53b 213 *
whismanoid 1:e73245718b2a 214 * while (1)
whismanoid 1:e73245718b2a 215 * {
whismanoid 5:e8c0dfaeb53b 216 * uint16_t code;
whismanoid 5:e8c0dfaeb53b 217 * //
whismanoid 5:e8c0dfaeb53b 218 * // example #1
whismanoid 7:564b438a0448 219 * code = 0x3fff; // 100.0% of full scale REF(2.50V) = 2.50V (FB=1-2:FORCE_BIP/SENSE_BIP: 2.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 5.00V)
whismanoid 1:e73245718b2a 220 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 6:f661c4a61207 221 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 1:e73245718b2a 222 * //
whismanoid 5:e8c0dfaeb53b 223 * // example #2
whismanoid 7:564b438a0448 224 * code = 0x3998; // 90.0% of full scale REF(2.50V) = 2.25V (FB=1-2:FORCE_BIP/SENSE_BIP: 2.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 4.50V)
whismanoid 1:e73245718b2a 225 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 6:f661c4a61207 226 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 1:e73245718b2a 227 * //
whismanoid 5:e8c0dfaeb53b 228 * // example #3
whismanoid 7:564b438a0448 229 * code = 0x3332; // 80.0% of full scale REF(2.50V) = 2.00V (FB=1-2:FORCE_BIP/SENSE_BIP: 1.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 4.00V)
whismanoid 4:1984eef51fe3 230 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 6:f661c4a61207 231 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 4:1984eef51fe3 232 * //
whismanoid 5:e8c0dfaeb53b 233 * // example #4
whismanoid 7:564b438a0448 234 * code = 0x2ccc; // 70.0% of full scale REF(2.50V) = 1.75V (FB=1-2:FORCE_BIP/SENSE_BIP: 1.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 3.50V)
whismanoid 1:e73245718b2a 235 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 6:f661c4a61207 236 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 6:f661c4a61207 237 * //
whismanoid 6:f661c4a61207 238 * // example #5
whismanoid 7:564b438a0448 239 * code = 0x2665; // 60.0% of full scale REF(2.50V) = 1.50V (FB=1-2:FORCE_BIP/SENSE_BIP: 0.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 3.00V)
whismanoid 7:564b438a0448 240 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 7:564b438a0448 241 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 7:564b438a0448 242 * //
whismanoid 7:564b438a0448 243 * // example #6
whismanoid 7:564b438a0448 244 * code = 0x1fff; // 50.0% of full scale REF(2.50V) = 1.25V (FB=1-2:FORCE_BIP/SENSE_BIP: 0.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 2.50V)
whismanoid 7:564b438a0448 245 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 7:564b438a0448 246 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 7:564b438a0448 247 * //
whismanoid 7:564b438a0448 248 * // example #7
whismanoid 7:564b438a0448 249 * code = 0x1999; // 40.0% of full scale REF(2.50V) = 1.00V (FB=1-2:FORCE_BIP/SENSE_BIP: -0.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 2.00V)
whismanoid 7:564b438a0448 250 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 7:564b438a0448 251 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 7:564b438a0448 252 * //
whismanoid 7:564b438a0448 253 * // example #8
whismanoid 7:564b438a0448 254 * code = 0x1332; // 30.0% of full scale REF(2.50V) = 0.75V (FB=1-2:FORCE_BIP/SENSE_BIP: -1.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 1.50V)
whismanoid 7:564b438a0448 255 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 7:564b438a0448 256 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 7:564b438a0448 257 * //
whismanoid 7:564b438a0448 258 * // example #9
whismanoid 7:564b438a0448 259 * code = 0x0ccc; // 20.0% of full scale REF(2.50V) = 0.50V (FB=1-2:FORCE_BIP/SENSE_BIP: -1.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 1.00V)
whismanoid 7:564b438a0448 260 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 7:564b438a0448 261 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 7:564b438a0448 262 * //
whismanoid 7:564b438a0448 263 * // example #10
whismanoid 7:564b438a0448 264 * code = 0x0666; // 10.0% of full scale REF(2.50V) = 0.25V (FB=1-2:FORCE_BIP/SENSE_BIP: -2.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 0.50V)
whismanoid 7:564b438a0448 265 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 7:564b438a0448 266 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 7:564b438a0448 267 * //
whismanoid 7:564b438a0448 268 * // example #11
whismanoid 7:564b438a0448 269 * code = 0x0000; // 0.0% of full scale REF(2.50V) = 0.00V (FB=1-2:FORCE_BIP/SENSE_BIP: -2.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 0.00V)
whismanoid 7:564b438a0448 270 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 7:564b438a0448 271 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 7:564b438a0448 272 * //
whismanoid 7:564b438a0448 273 * // example #12
whismanoid 7:564b438a0448 274 * code = 0x0000; // 0.0% of full scale REF(2.50V) = 0.00V (FB=1-2:FORCE_BIP/SENSE_BIP: -2.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 0.00V)
whismanoid 7:564b438a0448 275 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 7:564b438a0448 276 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 7:564b438a0448 277 * //
whismanoid 7:564b438a0448 278 * // example #13
whismanoid 7:564b438a0448 279 * code = 0x0666; // 10.0% of full scale REF(2.50V) = 0.25V (FB=1-2:FORCE_BIP/SENSE_BIP: -2.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 0.50V)
whismanoid 7:564b438a0448 280 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 7:564b438a0448 281 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 7:564b438a0448 282 * //
whismanoid 7:564b438a0448 283 * // example #14
whismanoid 7:564b438a0448 284 * code = 0x0ccc; // 20.0% of full scale REF(2.50V) = 0.50V (FB=1-2:FORCE_BIP/SENSE_BIP: -1.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 1.00V)
whismanoid 7:564b438a0448 285 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 7:564b438a0448 286 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 7:564b438a0448 287 * //
whismanoid 7:564b438a0448 288 * // example #15
whismanoid 7:564b438a0448 289 * code = 0x1332; // 30.0% of full scale REF(2.50V) = 0.75V (FB=1-2:FORCE_BIP/SENSE_BIP: -1.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 1.50V)
whismanoid 7:564b438a0448 290 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 7:564b438a0448 291 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 7:564b438a0448 292 * //
whismanoid 7:564b438a0448 293 * // example #16
whismanoid 7:564b438a0448 294 * code = 0x1999; // 40.0% of full scale REF(2.50V) = 1.00V (FB=1-2:FORCE_BIP/SENSE_BIP: -0.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 2.00V)
whismanoid 7:564b438a0448 295 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 7:564b438a0448 296 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 7:564b438a0448 297 * //
whismanoid 7:564b438a0448 298 * // example #17
whismanoid 7:564b438a0448 299 * code = 0x1fff; // 50.0% of full scale REF(2.50V) = 1.25V (FB=1-2:FORCE_BIP/SENSE_BIP: 0.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 2.50V)
whismanoid 7:564b438a0448 300 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 7:564b438a0448 301 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 7:564b438a0448 302 * //
whismanoid 7:564b438a0448 303 * // example #18
whismanoid 7:564b438a0448 304 * code = 0x2665; // 60.0% of full scale REF(2.50V) = 1.50V (FB=1-2:FORCE_BIP/SENSE_BIP: 0.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 3.00V)
whismanoid 7:564b438a0448 305 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 7:564b438a0448 306 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 7:564b438a0448 307 * //
whismanoid 7:564b438a0448 308 * // example #19
whismanoid 7:564b438a0448 309 * code = 0x2ccc; // 70.0% of full scale REF(2.50V) = 1.75V (FB=1-2:FORCE_BIP/SENSE_BIP: 1.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 3.50V)
whismanoid 7:564b438a0448 310 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 7:564b438a0448 311 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 7:564b438a0448 312 * //
whismanoid 7:564b438a0448 313 * // example #20
whismanoid 7:564b438a0448 314 * code = 0x3332; // 80.0% of full scale REF(2.50V) = 2.00V (FB=1-2:FORCE_BIP/SENSE_BIP: 1.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 4.00V)
whismanoid 7:564b438a0448 315 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 7:564b438a0448 316 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 7:564b438a0448 317 * //
whismanoid 7:564b438a0448 318 * // example #21
whismanoid 7:564b438a0448 319 * code = 0x3998; // 90.0% of full scale REF(2.50V) = 2.25V (FB=1-2:FORCE_BIP/SENSE_BIP: 2.00V) (FB=2-3:FORCE_UNI/SENSE_UNI: 4.50V)
whismanoid 7:564b438a0448 320 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 7:564b438a0448 321 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 7:564b438a0448 322 * //
whismanoid 7:564b438a0448 323 * // example #22
whismanoid 7:564b438a0448 324 * code = 0x3fff; // 100.0% of full scale REF(2.50V) = 2.50V (FB=1-2:FORCE_BIP/SENSE_BIP: 2.50V) (FB=2-3:FORCE_UNI/SENSE_UNI: 5.00V)
whismanoid 6:f661c4a61207 325 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 6:f661c4a61207 326 * wait_ms(3000); // wait_ms(unsigned long interval_msec)
whismanoid 1:e73245718b2a 327 *
whismanoid 5:e8c0dfaeb53b 328 * // wait(3.0);
whismanoid 1:e73245718b2a 329 * }
whismanoid 1:e73245718b2a 330 * }
whismanoid 1:e73245718b2a 331 * @endcode
whismanoid 1:e73245718b2a 332 */
whismanoid 2:d1340b334b0d 333 class MAX5171 {
whismanoid 1:e73245718b2a 334 public:
whismanoid 1:e73245718b2a 335 //----------------------------------------
whismanoid 1:e73245718b2a 336 /// Command Codes (first byte)
whismanoid 1:e73245718b2a 337 ///
whismanoid 1:e73245718b2a 338 /// Naming convention is CMD_bitstream_FUNCTION_NAME
whismanoid 1:e73245718b2a 339 /// - dd_dddd_dddd_dddd = data field
whismanoid 1:e73245718b2a 340 /// - xxxx = don't care
whismanoid 1:e73245718b2a 341 typedef enum MAX5171_CMD_enum_t {
whismanoid 6:f661c4a61207 342 CMD_00dd_dddd_dddd_dddd_CODE = 0x0000, //!< 0b0000000000000000
whismanoid 6:f661c4a61207 343 CMD_01dd_dddd_dddd_dddd_CODE_LOAD = 0x4000, //!< 0b0100000000000000
whismanoid 6:f661c4a61207 344 CMD_10xx_xxxx_xxxx_xxxx_LOAD = 0x8000, //!< 0b1000000000000000
whismanoid 6:f661c4a61207 345 CMD_1100_xxxx_xxxx_xxxx_NOP = 0xc000, //!< 0b1100000000000000
whismanoid 6:f661c4a61207 346 CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN = 0xd000, //!< 0b1101000000000000
whismanoid 6:f661c4a61207 347 CMD_1110_0xxx_xxxx_xxxx_UPO_LOW = 0xe000, //!< 0b1110000000000000
whismanoid 6:f661c4a61207 348 CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH = 0xe800, //!< 0b1110100000000000
whismanoid 6:f661c4a61207 349 CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE = 0xf000, //!< 0b1111000000000000
whismanoid 6:f661c4a61207 350 CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE = 0xf800, //!< 0b1111100000000000
whismanoid 1:e73245718b2a 351 } MAX5171_CMD_enum_t;
whismanoid 1:e73245718b2a 352
whismanoid 1:e73245718b2a 353 /**
whismanoid 1:e73245718b2a 354 * @brief IC's supported with this driver
whismanoid 1:e73245718b2a 355 * @details MAX5171
whismanoid 1:e73245718b2a 356 */
whismanoid 2:d1340b334b0d 357 typedef enum
whismanoid 2:d1340b334b0d 358 {
whismanoid 1:e73245718b2a 359 MAX5171_IC = 0,
whismanoid 1:e73245718b2a 360 //MAX5171_IC = 1
whismanoid 1:e73245718b2a 361 } MAX5171_ic_t;
whismanoid 0:80a9add62408 362
whismanoid 1:e73245718b2a 363 /**********************************************************//**
whismanoid 1:e73245718b2a 364 * @brief Constructor for MAX5171 Class.
whismanoid 1:e73245718b2a 365 *
whismanoid 1:e73245718b2a 366 * @details Requires an existing SPI object as well as a DigitalOut object.
whismanoid 1:e73245718b2a 367 * The DigitalOut object is used for a chip enable signal
whismanoid 1:e73245718b2a 368 *
whismanoid 1:e73245718b2a 369 * On Entry:
whismanoid 1:e73245718b2a 370 * @param[in] spi - pointer to existing SPI object
whismanoid 1:e73245718b2a 371 * @param[in] cs_pin - pointer to a DigitalOut pin object
whismanoid 1:e73245718b2a 372 * @param[in] RS_pin - pointer to a DigitalOut pin object
whismanoid 1:e73245718b2a 373 * @param[in] PDLb_pin - pointer to a DigitalOut pin object
whismanoid 1:e73245718b2a 374 * @param[in] CLRb_pin - pointer to a DigitalOut pin object
whismanoid 1:e73245718b2a 375 * @param[in] SHDN_pin - pointer to a DigitalOut pin object
whismanoid 1:e73245718b2a 376 * @param[in] UPO_pin - pointer to a DigitalIn pin object
whismanoid 1:e73245718b2a 377 * @param[in] ic_variant - which type of MAX5171 is used
whismanoid 1:e73245718b2a 378 *
whismanoid 1:e73245718b2a 379 * On Exit:
whismanoid 1:e73245718b2a 380 *
whismanoid 1:e73245718b2a 381 * @return None
whismanoid 1:e73245718b2a 382 **************************************************************/
whismanoid 1:e73245718b2a 383 MAX5171(SPI &spi, DigitalOut &cs_pin, // SPI interface
whismanoid 1:e73245718b2a 384 // AnalogOut &FB_pin, // Analog Input to MAX5171 device
whismanoid 1:e73245718b2a 385 DigitalOut &RS_pin, // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 386 DigitalOut &PDLb_pin, // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 387 DigitalOut &CLRb_pin, // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 388 DigitalOut &SHDN_pin, // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 389 // AnalogIn &OUT_pin, // Analog Output from MAX5171 device
whismanoid 1:e73245718b2a 390 DigitalIn &UPO_pin, // Digital General-Purpose Output from MAX5171 device
whismanoid 1:e73245718b2a 391 MAX5171_ic_t ic_variant);
whismanoid 1:e73245718b2a 392
whismanoid 1:e73245718b2a 393 /************************************************************
whismanoid 1:e73245718b2a 394 * @brief Default destructor for MAX5171 Class.
whismanoid 1:e73245718b2a 395 *
whismanoid 1:e73245718b2a 396 * @details Destroys SPI object if owner
whismanoid 1:e73245718b2a 397 *
whismanoid 1:e73245718b2a 398 * On Entry:
whismanoid 1:e73245718b2a 399 *
whismanoid 1:e73245718b2a 400 * On Exit:
whismanoid 1:e73245718b2a 401 *
whismanoid 1:e73245718b2a 402 * @return None
whismanoid 1:e73245718b2a 403 **************************************************************/
whismanoid 1:e73245718b2a 404 ~MAX5171();
whismanoid 1:e73245718b2a 405
whismanoid 5:e8c0dfaeb53b 406 /// Function pointer void f(size_t byteCount, uint8_t mosiData[], uint8_t misoData[])
whismanoid 5:e8c0dfaeb53b 407 Callback<void(size_t, uint8_t*, uint8_t*)> onSPIprint; //!< optional @ref onSPIprint SPI diagnostic function
whismanoid 5:e8c0dfaeb53b 408
whismanoid 5:e8c0dfaeb53b 409 /// set SPI SCLK frequency
whismanoid 1:e73245718b2a 410 void spi_frequency(int spi_sclk_Hz);
whismanoid 1:e73245718b2a 411
whismanoid 5:e8c0dfaeb53b 412 /// get SPI SCLK frequency
whismanoid 5:e8c0dfaeb53b 413 int get_spi_frequency() const { return m_SPI_SCLK_Hz; }
whismanoid 5:e8c0dfaeb53b 414
whismanoid 5:e8c0dfaeb53b 415 /// get SPI mode
whismanoid 5:e8c0dfaeb53b 416 int get_spi_dataMode() const { return m_SPI_dataMode; }
whismanoid 5:e8c0dfaeb53b 417
whismanoid 1:e73245718b2a 418 //----------------------------------------
whismanoid 1:e73245718b2a 419 public:
whismanoid 1:e73245718b2a 420
whismanoid 1:e73245718b2a 421 /// reference voltage, in Volts
whismanoid 1:e73245718b2a 422 double VRef;
whismanoid 1:e73245718b2a 423
whismanoid 5:e8c0dfaeb53b 424 /// shadow of dacCodeLsbs; write-only dacCodeLsbs field CMD_00dd_dddd_dddd_dddd_CODE or CMD_01dd_dddd_dddd_dddd_CODE_LOAD
whismanoid 1:e73245718b2a 425 int16_t DACCode;
whismanoid 1:e73245718b2a 426
whismanoid 1:e73245718b2a 427
whismanoid 1:e73245718b2a 428 //----------------------------------------
whismanoid 1:e73245718b2a 429 // Assert SPI Chip Select
whismanoid 1:e73245718b2a 430 // SPI chip-select for MAX5171
whismanoid 1:e73245718b2a 431 //
whismanoid 1:e73245718b2a 432 void SPIoutputCS(int isLogicHigh);
whismanoid 1:e73245718b2a 433
whismanoid 1:e73245718b2a 434 //----------------------------------------
whismanoid 1:e73245718b2a 435 // SPI write 16 bits
whismanoid 1:e73245718b2a 436 // SPI interface to MAX5171 shift 16 bits mosiData into MAX5171 DIN
whismanoid 1:e73245718b2a 437 //
whismanoid 1:e73245718b2a 438 void SPIwrite16bits(int16_t mosiData16);
whismanoid 1:e73245718b2a 439
whismanoid 1:e73245718b2a 440 private:
whismanoid 1:e73245718b2a 441 // SPI object
whismanoid 1:e73245718b2a 442 SPI &m_spi;
whismanoid 1:e73245718b2a 443 int m_SPI_SCLK_Hz;
whismanoid 1:e73245718b2a 444 int m_SPI_dataMode;
whismanoid 1:e73245718b2a 445 int m_SPI_cs_state;
whismanoid 1:e73245718b2a 446
whismanoid 1:e73245718b2a 447 // Selector pin object
whismanoid 1:e73245718b2a 448 DigitalOut &m_cs_pin;
whismanoid 1:e73245718b2a 449
whismanoid 1:e73245718b2a 450 // InputPin Name = FB
whismanoid 1:e73245718b2a 451 // InputPin Description = Feedback Input
whismanoid 1:e73245718b2a 452 // InputPin Function = Analog
whismanoid 1:e73245718b2a 453 //
whismanoid 1:e73245718b2a 454 // InputPin Name = RS
whismanoid 1:e73245718b2a 455 // InputPin Description = Reset Mode Select (digital input). Connect to VDD to select midscale reset output value. Connect to DGND
whismanoid 1:e73245718b2a 456 // to select 0 reset output value.
whismanoid 1:e73245718b2a 457 // InputPin Function = Configuration
whismanoid 1:e73245718b2a 458 DigitalOut &m_RS_pin;
whismanoid 1:e73245718b2a 459 //
whismanoid 1:e73245718b2a 460 // InputPin Name = PDL#
whismanoid 1:e73245718b2a 461 // InputPin Description = Power-Down Lockout (digital input). Connect to VDD to allow shutdown. Connect to DGND to disable shutdown.
whismanoid 1:e73245718b2a 462 // InputPin Function = Configuration
whismanoid 1:e73245718b2a 463 DigitalOut &m_PDLb_pin;
whismanoid 1:e73245718b2a 464 //
whismanoid 1:e73245718b2a 465 // InputPin Name = CLR#
whismanoid 1:e73245718b2a 466 // InputPin Description = Clear DAC (digital input). Clears the DAC to its predetermined output state as set by RS.
whismanoid 1:e73245718b2a 467 // InputPin Function = Configuration
whismanoid 1:e73245718b2a 468 DigitalOut &m_CLRb_pin;
whismanoid 1:e73245718b2a 469 //
whismanoid 1:e73245718b2a 470 // InputPin Name = SHDN
whismanoid 1:e73245718b2a 471 // InputPin Description = Shutdown (digital input). Pulling SHDN high when PDL = VDD places the chip in shutdown mode with a
whismanoid 1:e73245718b2a 472 // maximum shutdown current 0f 10uA.
whismanoid 1:e73245718b2a 473 // InputPin Function = Configuration
whismanoid 1:e73245718b2a 474 DigitalOut &m_SHDN_pin;
whismanoid 1:e73245718b2a 475 //
whismanoid 1:e73245718b2a 476 // OutputPin Name = OUT
whismanoid 1:e73245718b2a 477 // OutputPin Description = Analog Voltage Output. High impedance in shutdown. Output voltage is limited to VDD.
whismanoid 1:e73245718b2a 478 // OutputPin Function = Analog
whismanoid 1:e73245718b2a 479 // AnalogIn &m_OUT_pin;
whismanoid 1:e73245718b2a 480 //
whismanoid 1:e73245718b2a 481 // OutputPin Name = UPO
whismanoid 1:e73245718b2a 482 // OutputPin Description = User-Programmable Output. State is set by serial input.
whismanoid 1:e73245718b2a 483 // OutputPin Function = General-Purpose
whismanoid 1:e73245718b2a 484 DigitalIn &m_UPO_pin;
whismanoid 1:e73245718b2a 485 //
whismanoid 1:e73245718b2a 486
whismanoid 1:e73245718b2a 487 // Identifies which IC variant is being used
whismanoid 1:e73245718b2a 488 MAX5171_ic_t m_ic_variant;
whismanoid 1:e73245718b2a 489
whismanoid 1:e73245718b2a 490 public:
whismanoid 1:e73245718b2a 491
whismanoid 1:e73245718b2a 492 //----------------------------------------
whismanoid 5:e8c0dfaeb53b 493 /// Menu item '!'
whismanoid 1:e73245718b2a 494 /// Initialize device
whismanoid 6:f661c4a61207 495 ///
whismanoid 6:f661c4a61207 496 /// TODO1: #170 MAX5171 Self Test for Test Fixture Firmware
whismanoid 6:f661c4a61207 497 /// @future test group ____ // Verify function ____ (enabled by default)
whismanoid 6:f661c4a61207 498 /// @future test
whismanoid 6:f661c4a61207 499 /// tinyTester.settle_time_msec = 250;
whismanoid 6:f661c4a61207 500 ///
whismanoid 6:f661c4a61207 501 /// @test group DACCodeOfVoltage // Verify function DACCodeOfVoltage (enabled by default)
whismanoid 6:f661c4a61207 502 /// @test group DACCodeOfVoltage tinyTester.blink_time_msec = 20 // quickly speed through the software verification
whismanoid 6:f661c4a61207 503 /// @test group DACCodeOfVoltage tinyTester.print("VRef = 2.500 MAX5171 14-bit LSB = 0.00015V")
whismanoid 6:f661c4a61207 504 /// @test group DACCodeOfVoltage VRef = 2.500
whismanoid 6:f661c4a61207 505 /// @test group DACCodeOfVoltage tinyTester.err_threshold = 0.00015259720441921504 // 14-bit LSB (2.500/16383)
whismanoid 6:f661c4a61207 506 /// //
whismanoid 6:f661c4a61207 507 /// @test group DACCodeOfVoltage DACCodeOfVoltage(2.499847412109375) expect 0x3FFF
whismanoid 6:f661c4a61207 508 /// @test group DACCodeOfVoltage DACCodeOfVoltage(2.49969482421875) expect 0x3FFE
whismanoid 6:f661c4a61207 509 /// @test group DACCodeOfVoltage DACCodeOfVoltage(2.499542236328125) expect 0x3FFD
whismanoid 6:f661c4a61207 510 /// @test group DACCodeOfVoltage DACCodeOfVoltage(2.4993896484375) expect 0x3FFC
whismanoid 6:f661c4a61207 511 /// @test group DACCodeOfVoltage DACCodeOfVoltage(1.250152587890625) expect 0x2001
whismanoid 6:f661c4a61207 512 /// @test group DACCodeOfVoltage DACCodeOfVoltage(1.25) expect 0x2000
whismanoid 6:f661c4a61207 513 /// @test group DACCodeOfVoltage DACCodeOfVoltage(1.249847412109375) expect 0x1FFF
whismanoid 6:f661c4a61207 514 /// @test group DACCodeOfVoltage DACCodeOfVoltage(1.24969482421875) expect 0x1FFE
whismanoid 6:f661c4a61207 515 /// @test group DACCodeOfVoltage DACCodeOfVoltage(0.000457763671875) expect 0x0003
whismanoid 6:f661c4a61207 516 /// @test group DACCodeOfVoltage DACCodeOfVoltage(0.00030517578125) expect 0x0002
whismanoid 6:f661c4a61207 517 /// @test group DACCodeOfVoltage DACCodeOfVoltage(0.000152587890625) expect 0x0001
whismanoid 6:f661c4a61207 518 /// @test group DACCodeOfVoltage DACCodeOfVoltage(0.00000) expect 0x0000
whismanoid 6:f661c4a61207 519 /// @test group DACCodeOfVoltage tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
whismanoid 6:f661c4a61207 520 /// //
whismanoid 6:f661c4a61207 521 /// @test group VoltageOfCode // Verify function VoltageOfCode (enabled by default)
whismanoid 6:f661c4a61207 522 /// @test group VoltageOfCode tinyTester.blink_time_msec = 20 // quickly speed through the software verification
whismanoid 6:f661c4a61207 523 /// @test group VoltageOfCode tinyTester.print("VRef = 2.500 MAX5171 14-bit LSB = 0.00015V")
whismanoid 6:f661c4a61207 524 /// @test group VoltageOfCode VRef = 2.500
whismanoid 6:f661c4a61207 525 /// @test group VoltageOfCode tinyTester.err_threshold = 0.00015259720441921504 // 14-bit LSB (2.500/16383)
whismanoid 6:f661c4a61207 526 /// @test group VoltageOfCode VoltageOfCode(0x3FFF) expect 2.499847412109375
whismanoid 6:f661c4a61207 527 /// @test group VoltageOfCode VoltageOfCode(0x3FFE) expect 2.49969482421875
whismanoid 6:f661c4a61207 528 /// @test group VoltageOfCode VoltageOfCode(0x3FFD) expect 2.499542236328125
whismanoid 6:f661c4a61207 529 /// @test group VoltageOfCode VoltageOfCode(0x3FFC) expect 2.4993896484375
whismanoid 6:f661c4a61207 530 /// @test group VoltageOfCode VoltageOfCode(0x2001) expect 1.250152587890625
whismanoid 6:f661c4a61207 531 /// @test group VoltageOfCode VoltageOfCode(0x2000) expect 1.25
whismanoid 6:f661c4a61207 532 /// @test group VoltageOfCode VoltageOfCode(0x1FFF) expect 1.249847412109375
whismanoid 6:f661c4a61207 533 /// @test group VoltageOfCode VoltageOfCode(0x1FFE) expect 1.24969482421875
whismanoid 6:f661c4a61207 534 /// @test group VoltageOfCode VoltageOfCode(0x0003) expect 0.000457763671875
whismanoid 6:f661c4a61207 535 /// @test group VoltageOfCode VoltageOfCode(0x0002) expect 0.00030517578125
whismanoid 6:f661c4a61207 536 /// @test group VoltageOfCode VoltageOfCode(0x0001) expect 0.000152587890625
whismanoid 6:f661c4a61207 537 /// @test group VoltageOfCode VoltageOfCode(0x0000) expect 0.00000
whismanoid 6:f661c4a61207 538 /// @test group VoltageOfCode tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
whismanoid 6:f661c4a61207 539 /// //
whismanoid 6:f661c4a61207 540 /// // Device Testing: DAC commands, verify using on-board ADC inputs
whismanoid 6:f661c4a61207 541 /// //
whismanoid 6:f661c4a61207 542 /// @test group CODE_LOAD // Verify function CODE_LOAD (enabled by default)
whismanoid 6:f661c4a61207 543 /// @test group CODE_LOAD tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
whismanoid 6:f661c4a61207 544 /// @test group CODE_LOAD tinyTester.settle_time_msec = 500
whismanoid 6:f661c4a61207 545 /// tinyTester.blink_time_msec = 75;
whismanoid 6:f661c4a61207 546 /// cmdLine.serial().printf("
whismanoid 6:f661c4a61207 547 /// MAX5171.Init()");
whismanoid 6:f661c4a61207 548 /// g_MAX5171_device.Init();
whismanoid 6:f661c4a61207 549 /// @test Init()
whismanoid 6:f661c4a61207 550 /// @test VRef expect 2.500 // Nominal Full-Scale Voltage Reference
whismanoid 6:f661c4a61207 551 /// //
whismanoid 6:f661c4a61207 552 /// tinyTester.err_threshold = 0.030; // 30mV
whismanoid 6:f661c4a61207 553 /// @test group CODE_LOAD tinyTester.err_threshold = 0.050
whismanoid 6:f661c4a61207 554 /// uint16_t code = 0x3FFF;
whismanoid 6:f661c4a61207 555 /// //~ double voltageV = 0.5;
whismanoid 6:f661c4a61207 556 /// //
whismanoid 6:f661c4a61207 557 /// cmdLine.serial().printf("
whismanoid 6:f661c4a61207 558 /// MAX5171.CODE_LOAD code=%d", code);
whismanoid 6:f661c4a61207 559 /// g_MAX5171_device.CODE_LOAD(code);
whismanoid 6:f661c4a61207 560 /// @test group CODE_LOAD tinyTester.print("100.0% of full scale REF(2.50V) = 2.50V Jumper FB=1-2")
whismanoid 6:f661c4a61207 561 /// @test group CODE_LOAD CODE_LOAD(0x3FFF) // 100.0% of full scale REF(2.50V) = 2.50V
whismanoid 6:f661c4a61207 562 /// // tinyTester.Wait_Output_Settling replaces wait_ms
whismanoid 6:f661c4a61207 563 /// tinyTester.Wait_Output_Settling();
whismanoid 6:f661c4a61207 564 /// @test group CODE_LOAD tinyTester.Wait_Output_Settling()
whismanoid 6:f661c4a61207 565 /// // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
whismanoid 6:f661c4a61207 566 /// tinyTester.AnalogIn0_Read_Expect_voltageV(2.500);
whismanoid 6:f661c4a61207 567 /// @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(2.500)
whismanoid 6:f661c4a61207 568 /// //
whismanoid 6:f661c4a61207 569 /// code = 0x0000;
whismanoid 6:f661c4a61207 570 /// cmdLine.serial().printf("
whismanoid 6:f661c4a61207 571 /// MAX5171.CODE_LOAD code=%d", code);
whismanoid 6:f661c4a61207 572 /// g_MAX5171_device.CODE_LOAD(code);
whismanoid 6:f661c4a61207 573 /// @test group CODE_LOAD tinyTester.print("0.0% of full scale REF(2.50V) = 0.000V")
whismanoid 6:f661c4a61207 574 /// @test group CODE_LOAD CODE_LOAD(0x0000) // 0.0% of full scale REF(2.50V) = 0.000V
whismanoid 6:f661c4a61207 575 /// // tinyTester.Wait_Output_Settling replaces wait_ms
whismanoid 6:f661c4a61207 576 /// tinyTester.Wait_Output_Settling();
whismanoid 6:f661c4a61207 577 /// @test group CODE_LOAD tinyTester.Wait_Output_Settling()
whismanoid 6:f661c4a61207 578 /// // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
whismanoid 6:f661c4a61207 579 /// tinyTester.AnalogIn0_Read_Expect_voltageV(0.0000);
whismanoid 6:f661c4a61207 580 /// @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(0.0000)
whismanoid 6:f661c4a61207 581 /// //
whismanoid 6:f661c4a61207 582 /// code = 0x1FFF;
whismanoid 6:f661c4a61207 583 /// cmdLine.serial().printf("
whismanoid 6:f661c4a61207 584 /// MAX5171.CODE_LOAD code=%d", code);
whismanoid 6:f661c4a61207 585 /// g_MAX5171_device.CODE_LOAD(code);
whismanoid 6:f661c4a61207 586 /// @test group CODE_LOAD tinyTester.print("50.0% of full scale REF(2.50V) = 1.25V")
whismanoid 6:f661c4a61207 587 /// @test group CODE_LOAD CODE_LOAD(0x1FFF) // 50.0% of full scale REF(2.50V) = 1.25V
whismanoid 6:f661c4a61207 588 /// // tinyTester.Wait_Output_Settling replaces wait_ms
whismanoid 6:f661c4a61207 589 /// tinyTester.Wait_Output_Settling();
whismanoid 6:f661c4a61207 590 /// @test group CODE_LOAD tinyTester.Wait_Output_Settling()
whismanoid 6:f661c4a61207 591 /// // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
whismanoid 6:f661c4a61207 592 /// tinyTester.AnalogIn0_Read_Expect_voltageV(1.2500);
whismanoid 6:f661c4a61207 593 /// @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(1.2500)
whismanoid 6:f661c4a61207 594 /// //
whismanoid 6:f661c4a61207 595 /// // test UPO User Programmable Output, verify using digital input D2
whismanoid 6:f661c4a61207 596 /// //
whismanoid 6:f661c4a61207 597 /// @test group UPO // Verify User Programmable Output functions UPO_HIGH and UPO_LOW (enabled by default)
whismanoid 6:f661c4a61207 598 /// @test group UPO tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
whismanoid 6:f661c4a61207 599 /// @test group UPO tinyTester.settle_time_msec = 500 // default 250
whismanoid 6:f661c4a61207 600 /// cmdLine.serial().printf("
whismanoid 6:f661c4a61207 601 /// MAX5171.UPO_HIGH");
whismanoid 6:f661c4a61207 602 /// g_MAX5171_device.UPO_HIGH();
whismanoid 6:f661c4a61207 603 /// @test group UPO UPO_HIGH()
whismanoid 6:f661c4a61207 604 /// tinyTester.Wait_Output_Settling();
whismanoid 6:f661c4a61207 605 /// @test group UPO tinyTester.Wait_Output_Settling()
whismanoid 6:f661c4a61207 606 /// // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
whismanoid 6:f661c4a61207 607 /// tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command");
whismanoid 6:f661c4a61207 608 /// @test group CODE_LOAD tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command")
whismanoid 6:f661c4a61207 609 /// //
whismanoid 6:f661c4a61207 610 /// cmdLine.serial().printf("
whismanoid 6:f661c4a61207 611 /// MAX5171.UPO_LOW");
whismanoid 6:f661c4a61207 612 /// g_MAX5171_device.UPO_LOW();
whismanoid 6:f661c4a61207 613 /// @test group UPO UPO_LOW()
whismanoid 6:f661c4a61207 614 /// tinyTester.Wait_Output_Settling();
whismanoid 6:f661c4a61207 615 /// @test group UPO tinyTester.Wait_Output_Settling()
whismanoid 6:f661c4a61207 616 /// // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
whismanoid 6:f661c4a61207 617 /// tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 0, "UPO_pin is low after MAX5171 UPO_LOW command");
whismanoid 6:f661c4a61207 618 /// @test group CODE_LOAD tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 0, "UPO_pin is low after MAX5171 UPO_LOW command")
whismanoid 6:f661c4a61207 619 /// //
whismanoid 6:f661c4a61207 620 /// cmdLine.serial().printf("
whismanoid 6:f661c4a61207 621 /// MAX5171.UPO_HIGH");
whismanoid 6:f661c4a61207 622 /// g_MAX5171_device.UPO_HIGH();
whismanoid 6:f661c4a61207 623 /// @test group UPO UPO_HIGH()
whismanoid 6:f661c4a61207 624 /// tinyTester.Wait_Output_Settling();
whismanoid 6:f661c4a61207 625 /// @test group UPO tinyTester.Wait_Output_Settling()
whismanoid 6:f661c4a61207 626 /// // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
whismanoid 6:f661c4a61207 627 /// tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command");
whismanoid 6:f661c4a61207 628 /// @test group CODE_LOAD tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command")
whismanoid 6:f661c4a61207 629 /// //
whismanoid 6:f661c4a61207 630 ///
whismanoid 6:f661c4a61207 631 ///
whismanoid 6:f661c4a61207 632 void Init(void);
whismanoid 1:e73245718b2a 633
whismanoid 1:e73245718b2a 634 //----------------------------------------
whismanoid 1:e73245718b2a 635 /// Return the DAC register value corresponding to physical voltage.
whismanoid 1:e73245718b2a 636 /// Does not perform any offset or gain correction.
whismanoid 1:e73245718b2a 637 ///
whismanoid 1:e73245718b2a 638 /// @pre g_MAX5171_device.VRef = Voltage of REF input, in Volts
whismanoid 1:e73245718b2a 639 /// @param[in] voltage = physical voltage in Volts
whismanoid 1:e73245718b2a 640 /// @return raw 14-bit MAX5171 code (right justified).
whismanoid 1:e73245718b2a 641 uint16_t DACCodeOfVoltage(double voltageV);
whismanoid 1:e73245718b2a 642
whismanoid 1:e73245718b2a 643 //----------------------------------------
whismanoid 1:e73245718b2a 644 /// Return the physical voltage corresponding to DAC register.
whismanoid 1:e73245718b2a 645 /// Does not perform any offset or gain correction.
whismanoid 1:e73245718b2a 646 ///
whismanoid 1:e73245718b2a 647 /// @pre g_MAX5171_device.VRef = Voltage of REF input, in Volts
whismanoid 1:e73245718b2a 648 /// @param[in] value_u14: raw 14-bit MAX5171 code (right justified).
whismanoid 1:e73245718b2a 649 /// @return physical voltage corresponding to MAX5171 code.
whismanoid 1:e73245718b2a 650 double VoltageOfCode(uint16_t value_u14);
whismanoid 1:e73245718b2a 651
whismanoid 1:e73245718b2a 652 //----------------------------------------
whismanoid 1:e73245718b2a 653 /// CMD_00dd_dddd_dddd_dddd_CODE
whismanoid 1:e73245718b2a 654 ///
whismanoid 1:e73245718b2a 655 /// Load input register; DAC registers are unchanged.
whismanoid 1:e73245718b2a 656 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 657 uint8_t CODE(uint16_t dacCodeLsbs);
whismanoid 1:e73245718b2a 658
whismanoid 1:e73245718b2a 659 //----------------------------------------
whismanoid 1:e73245718b2a 660 /// CMD_01dd_dddd_dddd_dddd_CODE_LOAD
whismanoid 1:e73245718b2a 661 ///
whismanoid 1:e73245718b2a 662 /// Load input register; DAC registers are updated (start up DAC with new data).
whismanoid 1:e73245718b2a 663 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 664 uint8_t CODE_LOAD(uint16_t dacCodeLsbs);
whismanoid 1:e73245718b2a 665
whismanoid 1:e73245718b2a 666 //----------------------------------------
whismanoid 1:e73245718b2a 667 /// CMD_10xx_xxxx_xxxx_xxxx_LOAD
whismanoid 1:e73245718b2a 668 ///
whismanoid 1:e73245718b2a 669 /// Update DAC register from input register (start up DAC with data previously
whismanoid 1:e73245718b2a 670 /// stored in the input registers).
whismanoid 1:e73245718b2a 671 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 672 uint8_t LOAD(void);
whismanoid 1:e73245718b2a 673
whismanoid 1:e73245718b2a 674 //----------------------------------------
whismanoid 1:e73245718b2a 675 /// CMD_1100_xxxx_xxxx_xxxx_NOP
whismanoid 1:e73245718b2a 676 ///
whismanoid 1:e73245718b2a 677 /// No operation (NOP).
whismanoid 1:e73245718b2a 678 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 679 uint8_t NOP(void);
whismanoid 1:e73245718b2a 680
whismanoid 1:e73245718b2a 681 //----------------------------------------
whismanoid 1:e73245718b2a 682 /// CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN
whismanoid 1:e73245718b2a 683 ///
whismanoid 1:e73245718b2a 684 /// Shut down DAC (provided PDL# = 1).
whismanoid 1:e73245718b2a 685 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 686 uint8_t SHUTDOWN(void);
whismanoid 1:e73245718b2a 687
whismanoid 1:e73245718b2a 688 //----------------------------------------
whismanoid 1:e73245718b2a 689 /// CMD_1110_0xxx_xxxx_xxxx_UPO_LOW
whismanoid 1:e73245718b2a 690 ///
whismanoid 1:e73245718b2a 691 /// UPO goes low (default).
whismanoid 1:e73245718b2a 692 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 693 uint8_t UPO_LOW(void);
whismanoid 1:e73245718b2a 694
whismanoid 1:e73245718b2a 695 //----------------------------------------
whismanoid 1:e73245718b2a 696 /// CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH
whismanoid 1:e73245718b2a 697 ///
whismanoid 1:e73245718b2a 698 /// UPO goes high.
whismanoid 1:e73245718b2a 699 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 700 uint8_t UPO_HIGH(void);
whismanoid 1:e73245718b2a 701
whismanoid 1:e73245718b2a 702 //----------------------------------------
whismanoid 1:e73245718b2a 703 /// CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE
whismanoid 1:e73245718b2a 704 ///
whismanoid 5:e8c0dfaeb53b 705 /// Mode 1, DOUT clocked out on SCLK's rising edge.
whismanoid 1:e73245718b2a 706 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 707 uint8_t MODE1_DOUT_SCLK_RISING_EDGE(void);
whismanoid 1:e73245718b2a 708
whismanoid 1:e73245718b2a 709 //----------------------------------------
whismanoid 1:e73245718b2a 710 /// CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE
whismanoid 1:e73245718b2a 711 ///
whismanoid 5:e8c0dfaeb53b 712 /// Mode 0, DOUT clocked out on SCLK's falling edge (default).
whismanoid 1:e73245718b2a 713 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 714 uint8_t MODE0_DOUT_SCLK_FALLING_EDGE(void);
whismanoid 1:e73245718b2a 715
whismanoid 1:e73245718b2a 716 }; // end of class MAX5171
whismanoid 1:e73245718b2a 717
whismanoid 1:e73245718b2a 718 #endif // __MAX5171_H__
whismanoid 1:e73245718b2a 719
whismanoid 1:e73245718b2a 720 // End of file