Maxim Integrated MAX5719 20-bit, 0.05nV-sec DAC

Dependents:   MAX5719BOB_20bit_DAC MAX5719BOB_FunctionGen MAX5719BOB_Serial_Tester

Committer:
whismanoid
Date:
Sat Jun 12 01:34:21 2021 -0700
Revision:
3:fd0441f1a4ce
Parent:
2:6ffccf9a34d0
SelfTest . runall= runfail= loopall= loopfail=

Who changed what in which revision?

UserRevisionLine numberNew contents of line
whismanoid 0:49c7e35bd044 1 // /*******************************************************************************
whismanoid 0:49c7e35bd044 2 // * Copyright (C) 2021 Maxim Integrated Products, Inc., All Rights Reserved.
whismanoid 0:49c7e35bd044 3 // *
whismanoid 0:49c7e35bd044 4 // * Permission is hereby granted, free of charge, to any person obtaining a
whismanoid 0:49c7e35bd044 5 // * copy of this software and associated documentation files (the "Software"),
whismanoid 0:49c7e35bd044 6 // * to deal in the Software without restriction, including without limitation
whismanoid 0:49c7e35bd044 7 // * the rights to use, copy, modify, merge, publish, distribute, sublicense,
whismanoid 0:49c7e35bd044 8 // * and/or sell copies of the Software, and to permit persons to whom the
whismanoid 0:49c7e35bd044 9 // * Software is furnished to do so, subject to the following conditions:
whismanoid 0:49c7e35bd044 10 // *
whismanoid 0:49c7e35bd044 11 // * The above copyright notice and this permission notice shall be included
whismanoid 0:49c7e35bd044 12 // * in all copies or substantial portions of the Software.
whismanoid 0:49c7e35bd044 13 // *
whismanoid 0:49c7e35bd044 14 // * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
whismanoid 0:49c7e35bd044 15 // * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
whismanoid 0:49c7e35bd044 16 // * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
whismanoid 0:49c7e35bd044 17 // * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
whismanoid 0:49c7e35bd044 18 // * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
whismanoid 0:49c7e35bd044 19 // * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
whismanoid 0:49c7e35bd044 20 // * OTHER DEALINGS IN THE SOFTWARE.
whismanoid 0:49c7e35bd044 21 // *
whismanoid 0:49c7e35bd044 22 // * Except as contained in this notice, the name of Maxim Integrated
whismanoid 0:49c7e35bd044 23 // * Products, Inc. shall not be used except as stated in the Maxim Integrated
whismanoid 0:49c7e35bd044 24 // * Products, Inc. Branding Policy.
whismanoid 0:49c7e35bd044 25 // *
whismanoid 0:49c7e35bd044 26 // * The mere transfer of this software does not imply any licenses
whismanoid 0:49c7e35bd044 27 // * of trade secrets, proprietary technology, copyrights, patents,
whismanoid 0:49c7e35bd044 28 // * trademarks, maskwork rights, or any other form of intellectual
whismanoid 0:49c7e35bd044 29 // * property whatsoever. Maxim Integrated Products, Inc. retains all
whismanoid 0:49c7e35bd044 30 // * ownership rights.
whismanoid 0:49c7e35bd044 31 // *******************************************************************************
whismanoid 0:49c7e35bd044 32 // */
whismanoid 0:49c7e35bd044 33 // *********************************************************************
whismanoid 0:49c7e35bd044 34 // @file MAX5719.cpp
whismanoid 0:49c7e35bd044 35 // *********************************************************************
whismanoid 0:49c7e35bd044 36 // Device Driver file
whismanoid 0:49c7e35bd044 37 // DO NOT EDIT; except areas designated "CUSTOMIZE". Automatically generated file.
whismanoid 0:49c7e35bd044 38 // generated by XMLSystemOfDevicesToMBED.py
whismanoid 0:49c7e35bd044 39 // System Name = ExampleSystem
whismanoid 0:49c7e35bd044 40 // System Description = Device driver example
whismanoid 0:49c7e35bd044 41
whismanoid 0:49c7e35bd044 42 #include "MAX5719.h"
whismanoid 0:49c7e35bd044 43
whismanoid 0:49c7e35bd044 44 // Device Name = MAX5719
whismanoid 2:6ffccf9a34d0 45 // Device Description = 20-Bit, low glitch energy 0.05nV-sec, Voltage-Output DAC with SPI Interface
whismanoid 2:6ffccf9a34d0 46 // Device DeviceBriefDescription = 20-bit 0.05nV-sec DAC
whismanoid 0:49c7e35bd044 47 // Device Manufacturer = Maxim Integrated
whismanoid 0:49c7e35bd044 48 // Device PartNumber = MAX5719AGSD+
whismanoid 0:49c7e35bd044 49 // Device RegValue_Width = DataWidth16bit_HL
whismanoid 0:49c7e35bd044 50 //
whismanoid 0:49c7e35bd044 51 // DAC NumChannels = 1
whismanoid 0:49c7e35bd044 52 // DAC ResolutionBits = 20
whismanoid 0:49c7e35bd044 53 //
whismanoid 0:49c7e35bd044 54 // SPI CS = ActiveLow
whismanoid 0:49c7e35bd044 55 // SPI FrameStart = CS
whismanoid 0:49c7e35bd044 56 // SPI CPOL = 0
whismanoid 0:49c7e35bd044 57 // SPI CPHA = 0
whismanoid 0:49c7e35bd044 58 // SPI MOSI and MISO Data are both stable on Rising edge of SCLK
whismanoid 0:49c7e35bd044 59 // SPI SCLK Idle Low
whismanoid 0:49c7e35bd044 60 // SPI SCLKMaxMHz = 50
whismanoid 0:49c7e35bd044 61 // SPI SCLKMinMHz = 0
whismanoid 0:49c7e35bd044 62 //
whismanoid 0:49c7e35bd044 63 // InputPin Name = RFB
whismanoid 0:49c7e35bd044 64 // InputPin Description = Feedback Resistor. Connect to external op amp's output in bipolar mode.
whismanoid 0:49c7e35bd044 65 // InputPin Function = Analog
whismanoid 0:49c7e35bd044 66 //
whismanoid 0:49c7e35bd044 67 // InputPin Name = INV
whismanoid 0:49c7e35bd044 68 // InputPin Description = Junction of Internal Resistors. Connect to the inverting input of the external op amp in bipolar mode.
whismanoid 0:49c7e35bd044 69 // InputPin Function = Analog
whismanoid 0:49c7e35bd044 70 //
whismanoid 0:49c7e35bd044 71 // InputPin Name = LDAC#
whismanoid 0:49c7e35bd044 72 // InputPin Description = LDAC Input. A falling edge updates the internal DAC latch.
whismanoid 0:49c7e35bd044 73 // InputPin Function = Trigger
whismanoid 0:49c7e35bd044 74 //
whismanoid 0:49c7e35bd044 75 // OutputPin Name = OUT
whismanoid 0:49c7e35bd044 76 // OutputPin Description = Analog Voltage Output. High impedance in shutdown. Output voltage is limited to VDD.
whismanoid 0:49c7e35bd044 77 // OutputPin Function = Analog
whismanoid 0:49c7e35bd044 78 //
whismanoid 0:49c7e35bd044 79 // SupplyPin Name = VDD
whismanoid 0:49c7e35bd044 80 // SupplyPin Description = Positive Supply. Bypass to AGND with a 4.7uF capacitor in parallel with a 0.1uF capacitor.
whismanoid 0:49c7e35bd044 81 // SupplyPin VinMax = 4.50
whismanoid 0:49c7e35bd044 82 // SupplyPin VinMin = 5.50
whismanoid 0:49c7e35bd044 83 // SupplyPin Function = Analog
whismanoid 0:49c7e35bd044 84 //
whismanoid 0:49c7e35bd044 85 // SupplyPin Name = REFF
whismanoid 0:49c7e35bd044 86 // SupplyPin Description = Reference Input (force). Connect an external +4.096V reference.
whismanoid 0:49c7e35bd044 87 // SupplyPin VinMax = VDD
whismanoid 0:49c7e35bd044 88 // SupplyPin VinMin = 4
whismanoid 0:49c7e35bd044 89 // SupplyPin Function = Analog
whismanoid 0:49c7e35bd044 90 //
whismanoid 0:49c7e35bd044 91 // SupplyPin Name = REFS
whismanoid 0:49c7e35bd044 92 // SupplyPin Description = Reference Input (sense). Connect an external +4.096V reference.
whismanoid 0:49c7e35bd044 93 // SupplyPin VinMax = VDD
whismanoid 0:49c7e35bd044 94 // SupplyPin VinMin = 4
whismanoid 0:49c7e35bd044 95 // SupplyPin Function = Analog
whismanoid 0:49c7e35bd044 96 //
whismanoid 0:49c7e35bd044 97 // SupplyPin Name = DGND
whismanoid 0:49c7e35bd044 98 // SupplyPin Description = Digital Ground.
whismanoid 0:49c7e35bd044 99 // SupplyPin VinMax = 0
whismanoid 0:49c7e35bd044 100 // SupplyPin VinMin = 0
whismanoid 0:49c7e35bd044 101 // SupplyPin Function = Analog
whismanoid 0:49c7e35bd044 102 //
whismanoid 0:49c7e35bd044 103 // SupplyPin Name = AGNDF
whismanoid 0:49c7e35bd044 104 // SupplyPin Description = Analog Ground (force).
whismanoid 0:49c7e35bd044 105 // SupplyPin VinMax = 0
whismanoid 0:49c7e35bd044 106 // SupplyPin VinMin = 0
whismanoid 0:49c7e35bd044 107 // SupplyPin Function = Analog
whismanoid 0:49c7e35bd044 108 //
whismanoid 0:49c7e35bd044 109 // SupplyPin Name = AGNDS
whismanoid 0:49c7e35bd044 110 // SupplyPin Description = Analog Ground (sense).
whismanoid 0:49c7e35bd044 111 // SupplyPin VinMax = 0
whismanoid 0:49c7e35bd044 112 // SupplyPin VinMin = 0
whismanoid 0:49c7e35bd044 113 // SupplyPin Function = Analog
whismanoid 0:49c7e35bd044 114 //
whismanoid 0:49c7e35bd044 115
whismanoid 0:49c7e35bd044 116 MAX5719::MAX5719(SPI &spi, DigitalOut &cs_pin, // SPI interface
whismanoid 0:49c7e35bd044 117 // AnalogOut &RFB_pin, // Analog Input to MAX5719 device
whismanoid 0:49c7e35bd044 118 // AnalogOut &INV_pin, // Analog Input to MAX5719 device
whismanoid 0:49c7e35bd044 119 DigitalOut &LDACb_pin, // Digital Trigger Input to MAX5719 device
whismanoid 0:49c7e35bd044 120 // AnalogIn &OUT_pin, // Analog Output from MAX5719 device
whismanoid 0:49c7e35bd044 121 MAX5719_ic_t ic_variant)
whismanoid 0:49c7e35bd044 122 : m_spi(spi), m_cs_pin(cs_pin), // SPI interface
whismanoid 0:49c7e35bd044 123 // m_RFB_pin(RFB_pin), // Analog Input to MAX5719 device
whismanoid 0:49c7e35bd044 124 // m_INV_pin(INV_pin), // Analog Input to MAX5719 device
whismanoid 0:49c7e35bd044 125 m_LDACb_pin(LDACb_pin), // Digital Trigger Input to MAX5719 device
whismanoid 0:49c7e35bd044 126 // m_OUT_pin(OUT_pin), // Analog Output from MAX5719 device
whismanoid 0:49c7e35bd044 127 m_ic_variant(ic_variant)
whismanoid 0:49c7e35bd044 128 {
whismanoid 0:49c7e35bd044 129 // SPI CS = ActiveLow
whismanoid 0:49c7e35bd044 130 // SPI FrameStart = CS
whismanoid 0:49c7e35bd044 131 m_SPI_cs_state = 1;
whismanoid 0:49c7e35bd044 132 if (m_cs_pin.is_connected()) { // avoid mbed runtime error if pin is NC not connected
whismanoid 0:49c7e35bd044 133 m_cs_pin = m_SPI_cs_state;
whismanoid 0:49c7e35bd044 134 }
whismanoid 0:49c7e35bd044 135
whismanoid 0:49c7e35bd044 136 // SPI CPOL = 0
whismanoid 0:49c7e35bd044 137 // SPI CPHA = 0
whismanoid 0:49c7e35bd044 138 // SPI MOSI and MISO Data are both stable on Rising edge of SCLK
whismanoid 0:49c7e35bd044 139 // SPI SCLK Idle Low
whismanoid 0:49c7e35bd044 140 m_SPI_dataMode = 0; //SPI_MODE0; // CPOL=0,CPHA=0: Rising Edge stable; SCLK idle Low
whismanoid 0:49c7e35bd044 141 m_spi.format(8,m_SPI_dataMode); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0
whismanoid 0:49c7e35bd044 142
whismanoid 0:49c7e35bd044 143 // SPI SCLKMaxMHz = 50
whismanoid 0:49c7e35bd044 144 // SPI SCLKMinMHz = 0
whismanoid 0:49c7e35bd044 145 //#define SPI_SCLK_Hz 48000000 // 48MHz
whismanoid 0:49c7e35bd044 146 //#define SPI_SCLK_Hz 24000000 // 24MHz
whismanoid 0:49c7e35bd044 147 //#define SPI_SCLK_Hz 12000000 // 12MHz
whismanoid 0:49c7e35bd044 148 //#define SPI_SCLK_Hz 6000000 // 6MHz
whismanoid 0:49c7e35bd044 149 //#define SPI_SCLK_Hz 4000000 // 4MHz
whismanoid 0:49c7e35bd044 150 //#define SPI_SCLK_Hz 2000000 // 2MHz
whismanoid 0:49c7e35bd044 151 //#define SPI_SCLK_Hz 1000000 // 1MHz
whismanoid 0:49c7e35bd044 152 m_SPI_SCLK_Hz = 12000000; // platform limit 12MHz; MAX5719 limit is 50MHz
whismanoid 0:49c7e35bd044 153 m_spi.frequency(m_SPI_SCLK_Hz);
whismanoid 0:49c7e35bd044 154
whismanoid 0:49c7e35bd044 155 //
whismanoid 0:49c7e35bd044 156 // RFB Analog Input to MAX5719 device
whismanoid 0:49c7e35bd044 157 //
whismanoid 0:49c7e35bd044 158 // INV Analog Input to MAX5719 device
whismanoid 0:49c7e35bd044 159 //
whismanoid 0:49c7e35bd044 160 // LDACb Trigger Input to MAX5719 device
whismanoid 0:49c7e35bd044 161 m_LDACb_pin = 1; // output logic high -- initial value in constructor
whismanoid 0:49c7e35bd044 162 //
whismanoid 0:49c7e35bd044 163 // OUT Analog Output from device
whismanoid 0:49c7e35bd044 164 }
whismanoid 0:49c7e35bd044 165
whismanoid 0:49c7e35bd044 166 MAX5719::~MAX5719()
whismanoid 0:49c7e35bd044 167 {
whismanoid 0:49c7e35bd044 168 // do nothing
whismanoid 0:49c7e35bd044 169 }
whismanoid 0:49c7e35bd044 170
whismanoid 0:49c7e35bd044 171 /// set SPI SCLK frequency
whismanoid 0:49c7e35bd044 172 void MAX5719::spi_frequency(int spi_sclk_Hz)
whismanoid 0:49c7e35bd044 173 {
whismanoid 0:49c7e35bd044 174 m_SPI_SCLK_Hz = spi_sclk_Hz;
whismanoid 0:49c7e35bd044 175 m_spi.frequency(m_SPI_SCLK_Hz);
whismanoid 0:49c7e35bd044 176 }
whismanoid 0:49c7e35bd044 177
whismanoid 0:49c7e35bd044 178 // Assert SPI Chip Select
whismanoid 0:49c7e35bd044 179 // SPI chip-select for MAX5719
whismanoid 0:49c7e35bd044 180 //
whismanoid 0:49c7e35bd044 181 inline void MAX5719::SPIoutputCS(int isLogicHigh)
whismanoid 0:49c7e35bd044 182 {
whismanoid 0:49c7e35bd044 183 m_SPI_cs_state = isLogicHigh;
whismanoid 0:49c7e35bd044 184 if (m_cs_pin.is_connected()) { // avoid mbed runtime error if pin is NC not connected
whismanoid 0:49c7e35bd044 185 m_cs_pin = m_SPI_cs_state;
whismanoid 0:49c7e35bd044 186 }
whismanoid 0:49c7e35bd044 187 }
whismanoid 0:49c7e35bd044 188
whismanoid 0:49c7e35bd044 189 // SPI write 24 bits
whismanoid 0:49c7e35bd044 190 // SPI interface to MAX5719 shift 24 bits mosiData into MAX5719 DIN
whismanoid 0:49c7e35bd044 191 //
whismanoid 0:49c7e35bd044 192 void MAX5719::SPIwrite24bits(int8_t mosiData8_FF0000, int16_t mosiData16_00FFFF)
whismanoid 0:49c7e35bd044 193 {
whismanoid 0:49c7e35bd044 194 size_t byteCount = 3;
whismanoid 0:49c7e35bd044 195 static char mosiData[3];
whismanoid 0:49c7e35bd044 196 static char misoData[3];
whismanoid 0:49c7e35bd044 197 mosiData[0] = mosiData8_FF0000;
whismanoid 0:49c7e35bd044 198 mosiData[1] = (char)((mosiData16_00FFFF >> 8) & 0xFF); // MSByte
whismanoid 0:49c7e35bd044 199 mosiData[2] = (char)((mosiData16_00FFFF >> 0) & 0xFF); // LSByte
whismanoid 0:49c7e35bd044 200 //
whismanoid 0:49c7e35bd044 201 // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts()
whismanoid 0:49c7e35bd044 202 //~ noInterrupts();
whismanoid 0:49c7e35bd044 203 //
whismanoid 0:49c7e35bd044 204 //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin
whismanoid 0:49c7e35bd044 205 //
whismanoid 0:49c7e35bd044 206 unsigned int numBytesTransferred = m_spi.write(mosiData, byteCount, misoData, byteCount);
whismanoid 0:49c7e35bd044 207 //~ SPI.transfer(mosiData8_FF0000);
whismanoid 0:49c7e35bd044 208 //~ SPI.transfer(mosiData16_00FF00);
whismanoid 0:49c7e35bd044 209 //~ SPI.transfer(mosiData16_0000FF);
whismanoid 0:49c7e35bd044 210 //
whismanoid 0:49c7e35bd044 211 //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin
whismanoid 0:49c7e35bd044 212 //
whismanoid 0:49c7e35bd044 213 // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts()
whismanoid 0:49c7e35bd044 214 //~ interrupts();
whismanoid 0:49c7e35bd044 215 // Optional Diagnostic function to print SPI transactions
whismanoid 0:49c7e35bd044 216 if (onSPIprint)
whismanoid 0:49c7e35bd044 217 {
whismanoid 0:49c7e35bd044 218 onSPIprint(byteCount, (uint8_t*)mosiData, (uint8_t*)misoData);
whismanoid 0:49c7e35bd044 219 }
whismanoid 0:49c7e35bd044 220 //
whismanoid 0:49c7e35bd044 221 // VERIFY: SPIwrite24bits print diagnostic information
whismanoid 0:49c7e35bd044 222 //cmdLine.serial().printf(" MOSI->"));
whismanoid 0:49c7e35bd044 223 //cmdLine.serial().printf(" 0x"));
whismanoid 0:49c7e35bd044 224 //Serial.print( (mosiData8_FF0000 & 0xFF), HEX);
whismanoid 0:49c7e35bd044 225 //cmdLine.serial().printf(" 0x"));
whismanoid 0:49c7e35bd044 226 //Serial.print( (mosiData16_00FF00 & 0xFF), HEX);
whismanoid 0:49c7e35bd044 227 //cmdLine.serial().printf(" 0x"));
whismanoid 0:49c7e35bd044 228 //Serial.print( (mosiData16_0000FF & 0xFF), HEX);
whismanoid 0:49c7e35bd044 229 // hex dump mosiData[0..byteCount-1]
whismanoid 0:49c7e35bd044 230 #if HAS_MICROUSBSERIAL
whismanoid 0:49c7e35bd044 231 cmdLine_microUSBserial.serial().printf("\r\nSPI");
whismanoid 0:49c7e35bd044 232 if (byteCount > 7) {
whismanoid 0:49c7e35bd044 233 cmdLine_microUSBserial.serial().printf(" byteCount:%d", byteCount);
whismanoid 0:49c7e35bd044 234 }
whismanoid 0:49c7e35bd044 235 cmdLine_microUSBserial.serial().printf(" MOSI->");
whismanoid 0:49c7e35bd044 236 for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++)
whismanoid 0:49c7e35bd044 237 {
whismanoid 0:49c7e35bd044 238 cmdLine_microUSBserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]);
whismanoid 0:49c7e35bd044 239 }
whismanoid 0:49c7e35bd044 240 // hex dump misoData[0..byteCount-1]
whismanoid 0:49c7e35bd044 241 cmdLine_microUSBserial.serial().printf(" MISO<-");
whismanoid 0:49c7e35bd044 242 for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++)
whismanoid 0:49c7e35bd044 243 {
whismanoid 0:49c7e35bd044 244 cmdLine_microUSBserial.serial().printf(" 0x%2.2X", misoData[byteIndex]);
whismanoid 0:49c7e35bd044 245 }
whismanoid 0:49c7e35bd044 246 cmdLine_microUSBserial.serial().printf(" ");
whismanoid 0:49c7e35bd044 247 #endif
whismanoid 0:49c7e35bd044 248 #if HAS_DAPLINK_SERIAL
whismanoid 0:49c7e35bd044 249 cmdLine_DAPLINKserial.serial().printf("\r\nSPI");
whismanoid 0:49c7e35bd044 250 if (byteCount > 7) {
whismanoid 0:49c7e35bd044 251 cmdLine_DAPLINKserial.serial().printf(" byteCount:%d", byteCount);
whismanoid 0:49c7e35bd044 252 }
whismanoid 0:49c7e35bd044 253 cmdLine_DAPLINKserial.serial().printf(" MOSI->");
whismanoid 0:49c7e35bd044 254 for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++)
whismanoid 0:49c7e35bd044 255 {
whismanoid 0:49c7e35bd044 256 cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]);
whismanoid 0:49c7e35bd044 257 }
whismanoid 0:49c7e35bd044 258 // hex dump misoData[0..byteCount-1]
whismanoid 0:49c7e35bd044 259 cmdLine_DAPLINKserial.serial().printf(" MISO<-");
whismanoid 0:49c7e35bd044 260 for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++)
whismanoid 0:49c7e35bd044 261 {
whismanoid 0:49c7e35bd044 262 cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", misoData[byteIndex]);
whismanoid 0:49c7e35bd044 263 }
whismanoid 0:49c7e35bd044 264 cmdLine_DAPLINKserial.serial().printf(" ");
whismanoid 0:49c7e35bd044 265 #endif
whismanoid 0:49c7e35bd044 266 // VERIFY: DIAGNOSTIC: print MAX5715 device register write
whismanoid 0:49c7e35bd044 267 // TODO: MAX5715_print_register_verbose(mosiData8_FF0000, mosiData16_00FFFF);
whismanoid 0:49c7e35bd044 268 //
whismanoid 0:49c7e35bd044 269 // int misoData16 = (misoData16_FF00 << 8) | misoData16_00FF;
whismanoid 0:49c7e35bd044 270 // return misoData16;
whismanoid 0:49c7e35bd044 271 }
whismanoid 0:49c7e35bd044 272
whismanoid 0:49c7e35bd044 273 // Assert MAX5719 LDAC pin : High = inactive, Low = load DAC.
whismanoid 0:49c7e35bd044 274 //
whismanoid 0:49c7e35bd044 275 void MAX5719::LDACboutputValue(int isLogicHigh)
whismanoid 0:49c7e35bd044 276 {
whismanoid 0:49c7e35bd044 277 // m_LDACb_pin.output(); // only applicable to DigitalInOut
whismanoid 0:49c7e35bd044 278 m_LDACb_pin = isLogicHigh;
whismanoid 0:49c7e35bd044 279 }
whismanoid 0:49c7e35bd044 280
whismanoid 0:49c7e35bd044 281 //----------------------------------------
whismanoid 0:49c7e35bd044 282 // Menu item '!'
whismanoid 0:49c7e35bd044 283 // Initialize device
whismanoid 0:49c7e35bd044 284 //
whismanoid 0:49c7e35bd044 285 // //
whismanoid 0:49c7e35bd044 286 // // Device Testing: DAC commands, verify using on-board ADC inputs
whismanoid 0:49c7e35bd044 287 // //
whismanoid 0:49c7e35bd044 288 // @test group CODE_LOAD // Verify function CODE_LOAD vs platform AIN0 analog input (enabled by default)
whismanoid 0:49c7e35bd044 289 // @test group CODE_LOAD tinyTester.print("VRef = 4.096 MAX5719 20-bit LSB = 0.000004V = 3.90625uV")
whismanoid 0:49c7e35bd044 290 // @test group CODE_LOAD tinyTester.print("Wire MAX5719 OUT to platform AIN0 for analog loopback tests...")
whismanoid 0:49c7e35bd044 291 // @test group CODE_LOAD VRef = 4.096
whismanoid 0:49c7e35bd044 292 // @test group CODE_LOAD tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
whismanoid 0:49c7e35bd044 293 // @test group CODE_LOAD tinyTester.settle_time_msec = 500
whismanoid 0:49c7e35bd044 294 // @test Init()
whismanoid 0:49c7e35bd044 295 // @test VRef expect 4.096 // Nominal Full-Scale Voltage Reference
whismanoid 0:49c7e35bd044 296 // //
whismanoid 0:49c7e35bd044 297 // @test group CODE_LOAD tinyTester.err_threshold = 0.050
whismanoid 0:49c7e35bd044 298 // //
whismanoid 0:49c7e35bd044 299 // @test group CODE_LOAD tinyTester.print("0x000000 = 0.000V")
whismanoid 0:49c7e35bd044 300 // @test group CODE_LOAD CODE_LOAD(0x000000) // 0.000V
whismanoid 0:49c7e35bd044 301 // @test group CODE_LOAD tinyTester.Wait_Output_Settling()
whismanoid 0:49c7e35bd044 302 // @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(0.000000)
whismanoid 2:6ffccf9a34d0 303 // @test group CODE_LOAD tinyTester.AnalogIn1_Read_Report_voltageV(); // remove unwanted loading on AIN0
whismanoid 0:49c7e35bd044 304 // //
whismanoid 0:49c7e35bd044 305 // @test group CODE_LOAD tinyTester.print("0x01f400 = 0.500V")
whismanoid 0:49c7e35bd044 306 // @test group CODE_LOAD CODE_LOAD(0x01f400) // 0.500V
whismanoid 0:49c7e35bd044 307 // @test group CODE_LOAD tinyTester.Wait_Output_Settling()
whismanoid 0:49c7e35bd044 308 // @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(0.500000)
whismanoid 2:6ffccf9a34d0 309 // @test group CODE_LOAD tinyTester.AnalogIn1_Read_Report_voltageV(); // remove unwanted loading on AIN0
whismanoid 0:49c7e35bd044 310 // //
whismanoid 0:49c7e35bd044 311 // @test group CODE_LOAD tinyTester.print("0x03e800 = 1.000V")
whismanoid 0:49c7e35bd044 312 // @test group CODE_LOAD CODE_LOAD(0x03e800) // 1.000V
whismanoid 0:49c7e35bd044 313 // @test group CODE_LOAD tinyTester.Wait_Output_Settling()
whismanoid 0:49c7e35bd044 314 // @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(1.000000)
whismanoid 2:6ffccf9a34d0 315 // @test group CODE_LOAD tinyTester.AnalogIn1_Read_Report_voltageV(); // remove unwanted loading on AIN0
whismanoid 0:49c7e35bd044 316 // //
whismanoid 1:f7dd5b495201 317 // @test group CODE_LOAD tinyTester.err_threshold = 0.075
whismanoid 1:f7dd5b495201 318 // //
whismanoid 0:49c7e35bd044 319 // @test group CODE_LOAD tinyTester.print("0x05dc00 = 1.500V")
whismanoid 0:49c7e35bd044 320 // @test group CODE_LOAD CODE_LOAD(0x05dc00) // 1.500V
whismanoid 0:49c7e35bd044 321 // @test group CODE_LOAD tinyTester.Wait_Output_Settling()
whismanoid 0:49c7e35bd044 322 // @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(1.500000)
whismanoid 2:6ffccf9a34d0 323 // @test group CODE_LOAD tinyTester.AnalogIn1_Read_Report_voltageV(); // remove unwanted loading on AIN0
whismanoid 0:49c7e35bd044 324 // //
whismanoid 1:f7dd5b495201 325 // @test group CODE_LOAD tinyTester.err_threshold = 0.100
whismanoid 1:f7dd5b495201 326 // //
whismanoid 0:49c7e35bd044 327 // @test group CODE_LOAD tinyTester.print("0x07d000 = 2.000V")
whismanoid 0:49c7e35bd044 328 // @test group CODE_LOAD CODE_LOAD(0x07d000) // 2.000V
whismanoid 0:49c7e35bd044 329 // @test group CODE_LOAD tinyTester.Wait_Output_Settling()
whismanoid 0:49c7e35bd044 330 // @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(2.000000)
whismanoid 2:6ffccf9a34d0 331 // @test group CODE_LOAD tinyTester.AnalogIn1_Read_Report_voltageV(); // remove unwanted loading on AIN0
whismanoid 0:49c7e35bd044 332 // //
whismanoid 1:f7dd5b495201 333 // @test group CODE_LOAD tinyTester.err_threshold = 0.150
whismanoid 1:f7dd5b495201 334 // //
whismanoid 0:49c7e35bd044 335 // @test group CODE_LOAD tinyTester.print("0x09c400 = 2.500V")
whismanoid 0:49c7e35bd044 336 // @test group CODE_LOAD CODE_LOAD(0x09c400) // 2.500V
whismanoid 0:49c7e35bd044 337 // @test group CODE_LOAD tinyTester.Wait_Output_Settling()
whismanoid 0:49c7e35bd044 338 // @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(2.500000)
whismanoid 2:6ffccf9a34d0 339 // @test group CODE_LOAD tinyTester.AnalogIn1_Read_Report_voltageV(); // remove unwanted loading on AIN0
whismanoid 0:49c7e35bd044 340 // //
whismanoid 1:f7dd5b495201 341 // @test group CODE_LOAD tinyTester.err_threshold = 0.200
whismanoid 1:f7dd5b495201 342 // //
whismanoid 0:49c7e35bd044 343 // @test group CODE_LOAD tinyTester.print("0x0bb800 = 3.000V")
whismanoid 0:49c7e35bd044 344 // @test group CODE_LOAD CODE_LOAD(0x0bb800) // 3.000V
whismanoid 0:49c7e35bd044 345 // @test group CODE_LOAD tinyTester.Wait_Output_Settling()
whismanoid 0:49c7e35bd044 346 // @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(3.000000)
whismanoid 2:6ffccf9a34d0 347 // @test group CODE_LOAD tinyTester.AnalogIn1_Read_Report_voltageV(); // remove unwanted loading on AIN0
whismanoid 0:49c7e35bd044 348 // //
whismanoid 1:f7dd5b495201 349 // @test group CODE_LOAD tinyTester.err_threshold = 0.250
whismanoid 1:f7dd5b495201 350 // //
whismanoid 0:49c7e35bd044 351 // @test group CODE_LOAD tinyTester.print("0x0dac00 = 3.500V")
whismanoid 0:49c7e35bd044 352 // @test group CODE_LOAD CODE_LOAD(0x0dac00) // 3.500V
whismanoid 0:49c7e35bd044 353 // @test group CODE_LOAD tinyTester.Wait_Output_Settling()
whismanoid 0:49c7e35bd044 354 // @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(3.500000)
whismanoid 2:6ffccf9a34d0 355 // @test group CODE_LOAD tinyTester.AnalogIn1_Read_Report_voltageV(); // remove unwanted loading on AIN0
whismanoid 0:49c7e35bd044 356 // //
whismanoid 1:f7dd5b495201 357 // @test group CODE_LOAD tinyTester.err_threshold = 0.500
whismanoid 1:f7dd5b495201 358 // //
whismanoid 0:49c7e35bd044 359 // @test group CODE_LOAD tinyTester.print("0x0fa000 = 4.000V")
whismanoid 0:49c7e35bd044 360 // @test group CODE_LOAD CODE_LOAD(0x0fa000) // 4.000V
whismanoid 0:49c7e35bd044 361 // @test group CODE_LOAD tinyTester.Wait_Output_Settling()
whismanoid 0:49c7e35bd044 362 // @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(4.000000)
whismanoid 2:6ffccf9a34d0 363 // @test group CODE_LOAD tinyTester.AnalogIn1_Read_Report_voltageV(); // remove unwanted loading on AIN0
whismanoid 0:49c7e35bd044 364 // //
whismanoid 1:f7dd5b495201 365 // @test group CODE_LOAD tinyTester.err_threshold = 0.750
whismanoid 1:f7dd5b495201 366 // //
whismanoid 0:49c7e35bd044 367 // @test group CODE_LOAD tinyTester.print("0x0fffff = 4.095V")
whismanoid 0:49c7e35bd044 368 // @test group CODE_LOAD CODE_LOAD(0x0fffff) // 4.095V
whismanoid 0:49c7e35bd044 369 // @test group CODE_LOAD tinyTester.Wait_Output_Settling()
whismanoid 0:49c7e35bd044 370 // @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(4.095000)
whismanoid 2:6ffccf9a34d0 371 // @test group CODE_LOAD tinyTester.AnalogIn1_Read_Report_voltageV(); // remove unwanted loading on AIN0
whismanoid 0:49c7e35bd044 372 // //
whismanoid 1:f7dd5b495201 373 // @test group CODE_LOAD tinyTester.err_threshold = 0.200
whismanoid 1:f7dd5b495201 374 // //
whismanoid 0:49c7e35bd044 375 // @test group CODE_LOAD tinyTester.print("0x080000 // 2.048V")
whismanoid 0:49c7e35bd044 376 // @test group CODE_LOAD CODE_LOAD(0x080000) // 2.048V
whismanoid 0:49c7e35bd044 377 // @test group CODE_LOAD tinyTester.Wait_Output_Settling()
whismanoid 0:49c7e35bd044 378 // @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(2.048000)
whismanoid 2:6ffccf9a34d0 379 // @test group CODE_LOAD tinyTester.AnalogIn1_Read_Report_voltageV(); // remove unwanted loading on AIN0
whismanoid 0:49c7e35bd044 380 // //
whismanoid 3:fd0441f1a4ce 381 // //
whismanoid 3:fd0441f1a4ce 382 // @test group CODE_LOAD_2V5 // Verify function CODE_LOAD vs platform AIN0 analog input (enabled by default) (no run on button)
whismanoid 3:fd0441f1a4ce 383 // @test group CODE_LOAD_2V5 tinyTester.err_threshold = 0.150
whismanoid 3:fd0441f1a4ce 384 // @test group CODE_LOAD_2V5 tinyTester.print("0x09c400 = 2.500V")
whismanoid 3:fd0441f1a4ce 385 // @test group CODE_LOAD_2V5 CODE_LOAD(0x09c400) // 2.500V
whismanoid 3:fd0441f1a4ce 386 // @test group CODE_LOAD_2V5 tinyTester.Wait_Output_Settling()
whismanoid 3:fd0441f1a4ce 387 // @test group CODE_LOAD_2V5 tinyTester.AnalogIn0_Read_Expect_voltageV(2.500000)
whismanoid 3:fd0441f1a4ce 388 // @test group CODE_LOAD_2V5 tinyTester.AnalogIn1_Read_Report_voltageV(); // remove unwanted loading on AIN0
whismanoid 3:fd0441f1a4ce 389 // //
whismanoid 3:fd0441f1a4ce 390 // //
whismanoid 3:fd0441f1a4ce 391 // @test group CODE_LOAD_3V0 // Verify function CODE_LOAD vs platform AIN0 analog input (enabled by default) (no run on button)
whismanoid 3:fd0441f1a4ce 392 // @test group CODE_LOAD_3V0 tinyTester.err_threshold = 0.200
whismanoid 3:fd0441f1a4ce 393 // @test group CODE_LOAD_3V0 tinyTester.print("0x0bb800 = 3.000V")
whismanoid 3:fd0441f1a4ce 394 // @test group CODE_LOAD_3V0 CODE_LOAD(0x0bb800) // 3.000V
whismanoid 3:fd0441f1a4ce 395 // @test group CODE_LOAD_3V0 tinyTester.Wait_Output_Settling()
whismanoid 3:fd0441f1a4ce 396 // @test group CODE_LOAD_3V0 tinyTester.AnalogIn0_Read_Expect_voltageV(3.000000)
whismanoid 3:fd0441f1a4ce 397 // @test group CODE_LOAD_3V0 tinyTester.AnalogIn1_Read_Report_voltageV(); // remove unwanted loading on AIN0
whismanoid 3:fd0441f1a4ce 398 // //
whismanoid 3:fd0441f1a4ce 399 // //
whismanoid 3:fd0441f1a4ce 400 // @test group CODE_LOAD_4V1 // Verify function CODE_LOAD vs platform AIN0 analog input (enabled by default) (no run on button)
whismanoid 3:fd0441f1a4ce 401 // @test group CODE_LOAD_4V1 tinyTester.err_threshold = 0.750
whismanoid 3:fd0441f1a4ce 402 // @test group CODE_LOAD_4V1 tinyTester.print("0x0fffff = 4.095V")
whismanoid 3:fd0441f1a4ce 403 // @test group CODE_LOAD_4V1 CODE_LOAD(0x0fffff) // 4.095V
whismanoid 3:fd0441f1a4ce 404 // @test group CODE_LOAD_4V1 tinyTester.Wait_Output_Settling()
whismanoid 3:fd0441f1a4ce 405 // @test group CODE_LOAD_4V1 tinyTester.AnalogIn0_Read_Expect_voltageV(4.095000)
whismanoid 3:fd0441f1a4ce 406 // @test group CODE_LOAD_4V1 tinyTester.AnalogIn1_Read_Report_voltageV(); // remove unwanted loading on AIN0
whismanoid 3:fd0441f1a4ce 407 // //
whismanoid 0:49c7e35bd044 408 //
whismanoid 0:49c7e35bd044 409 //
whismanoid 0:49c7e35bd044 410 void MAX5719::Init(void)
whismanoid 0:49c7e35bd044 411 {
whismanoid 0:49c7e35bd044 412
whismanoid 0:49c7e35bd044 413 //----------------------------------------
whismanoid 0:49c7e35bd044 414 // Nominal Full-Scale Voltage Reference
whismanoid 0:49c7e35bd044 415 VRef = 4.096;
whismanoid 0:49c7e35bd044 416 }
whismanoid 0:49c7e35bd044 417
whismanoid 0:49c7e35bd044 418 //----------------------------------------
whismanoid 0:49c7e35bd044 419 // Return the DAC register value corresponding to physical voltage.
whismanoid 0:49c7e35bd044 420 // Does not perform any offset or gain correction.
whismanoid 0:49c7e35bd044 421 //
whismanoid 0:49c7e35bd044 422 // @pre VRef = Voltage of REF input, in Volts
whismanoid 0:49c7e35bd044 423 // @param[in] voltage = physical voltage in Volts
whismanoid 0:49c7e35bd044 424 // @return raw 20-bit MAX5719 code (right justified).
whismanoid 0:49c7e35bd044 425 //
whismanoid 3:fd0441f1a4ce 426 // @test group DACCodeOfVoltage // Verify function DACCodeOfVoltage (enabled by default) (no run on button)
whismanoid 0:49c7e35bd044 427 // @test group DACCodeOfVoltage tinyTester.blink_time_msec = 20 // quickly speed through the software verification
whismanoid 0:49c7e35bd044 428 // @test group DACCodeOfVoltage tinyTester.print("VRef = 4.096 MAX5719 20-bit LSB = 0.000004V = 3.90625uV")
whismanoid 0:49c7e35bd044 429 // @test group DACCodeOfVoltage VRef = 4.096
whismanoid 0:49c7e35bd044 430 // @test group DACCodeOfVoltage tinyTester.print("test_voltage_sweep V = 0.000000V to 4.096000V precision 0.100000V step 0.500000V")
whismanoid 0:49c7e35bd044 431 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.000000) expect 0x000000 // 0.000V
whismanoid 0:49c7e35bd044 432 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.500000) expect 0x01f400 // 0.500V
whismanoid 0:49c7e35bd044 433 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.000000) expect 0x03e800 // 1.000V
whismanoid 0:49c7e35bd044 434 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.500000) expect 0x05dc00 // 1.500V
whismanoid 0:49c7e35bd044 435 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.000000) expect 0x07d000 // 2.000V
whismanoid 0:49c7e35bd044 436 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.500000) expect 0x09c400 // 2.500V
whismanoid 0:49c7e35bd044 437 // @test group DACCodeOfVoltage DACCodeOfVoltage(3.000000) expect 0x0bb800 // 3.000V
whismanoid 0:49c7e35bd044 438 // @test group DACCodeOfVoltage DACCodeOfVoltage(3.500000) expect 0x0dac00 // 3.500V
whismanoid 0:49c7e35bd044 439 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.000000) expect 0x0fa000 // 4.000V
whismanoid 0:49c7e35bd044 440 // @test group DACCodeOfVoltage tinyTester.print("test_voltage_sweep V = -0.010000V to 0.100000V precision 0.010000V step 0.010000V")
whismanoid 0:49c7e35bd044 441 // @test group DACCodeOfVoltage DACCodeOfVoltage(-0.010000) expect 0x000000 // -0.010V
whismanoid 0:49c7e35bd044 442 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.000000) expect 0x000000 // 0.000V
whismanoid 0:49c7e35bd044 443 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.010000) expect 0x000a00 // 0.010V
whismanoid 0:49c7e35bd044 444 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.020000) expect 0x001400 // 0.020V
whismanoid 0:49c7e35bd044 445 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.030000) expect 0x001e00 // 0.030V
whismanoid 0:49c7e35bd044 446 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.040000) expect 0x002800 // 0.040V
whismanoid 0:49c7e35bd044 447 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.050000) expect 0x003200 // 0.050V
whismanoid 0:49c7e35bd044 448 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.060000) expect 0x003c00 // 0.060V
whismanoid 0:49c7e35bd044 449 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.070000) expect 0x004600 // 0.070V
whismanoid 0:49c7e35bd044 450 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.080000) expect 0x005000 // 0.080V
whismanoid 0:49c7e35bd044 451 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.090000) expect 0x005a00 // 0.090V
whismanoid 0:49c7e35bd044 452 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.100000) expect 0x006400 // 0.100V
whismanoid 0:49c7e35bd044 453 // @test group DACCodeOfVoltage tinyTester.print("test_voltage_sweep V = 2.047900V to 2.048100V precision 0.000010V step 0.000010V")
whismanoid 0:49c7e35bd044 454 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.047890) expect 0x07ffe4 // 2.048V
whismanoid 0:49c7e35bd044 455 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.047900) expect 0x07ffe6 // 2.048V
whismanoid 0:49c7e35bd044 456 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.047910) expect 0x07ffe9 // 2.048V
whismanoid 0:49c7e35bd044 457 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.047920) expect 0x07ffec // 2.048V
whismanoid 0:49c7e35bd044 458 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.047930) expect 0x07ffee // 2.048V
whismanoid 0:49c7e35bd044 459 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.047940) expect 0x07fff1 // 2.048V
whismanoid 0:49c7e35bd044 460 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.047950) expect 0x07fff3 // 2.048V
whismanoid 0:49c7e35bd044 461 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.047960) expect 0x07fff6 // 2.048V
whismanoid 0:49c7e35bd044 462 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.047970) expect 0x07fff8 // 2.048V
whismanoid 0:49c7e35bd044 463 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.047980) expect 0x07fffb // 2.048V
whismanoid 0:49c7e35bd044 464 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.047990) expect 0x07fffd // 2.048V
whismanoid 0:49c7e35bd044 465 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048000) expect 0x080000 // 2.048V
whismanoid 0:49c7e35bd044 466 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048010) expect 0x080003 // 2.048V
whismanoid 0:49c7e35bd044 467 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048020) expect 0x080005 // 2.048V
whismanoid 0:49c7e35bd044 468 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048030) expect 0x080008 // 2.048V
whismanoid 0:49c7e35bd044 469 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048040) expect 0x08000a // 2.048V
whismanoid 0:49c7e35bd044 470 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048050) expect 0x08000d // 2.048V
whismanoid 0:49c7e35bd044 471 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048060) expect 0x08000f // 2.048V
whismanoid 0:49c7e35bd044 472 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048070) expect 0x080012 // 2.048V
whismanoid 0:49c7e35bd044 473 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048080) expect 0x080014 // 2.048V
whismanoid 0:49c7e35bd044 474 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048090) expect 0x080017 // 2.048V
whismanoid 0:49c7e35bd044 475 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048100) expect 0x08001a // 2.048V
whismanoid 0:49c7e35bd044 476 // @test group DACCodeOfVoltage tinyTester.print("test_voltage_sweep V = 3.996000V to 4.106000V precision 0.010000V step 0.010000V")
whismanoid 0:49c7e35bd044 477 // @test group DACCodeOfVoltage DACCodeOfVoltage(3.990000) expect 0x0f9600 // 3.990V
whismanoid 0:49c7e35bd044 478 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.000000) expect 0x0fa000 // 4.000V
whismanoid 0:49c7e35bd044 479 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.010000) expect 0x0faa00 // 4.010V
whismanoid 0:49c7e35bd044 480 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.020000) expect 0x0fb400 // 4.020V
whismanoid 0:49c7e35bd044 481 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.030000) expect 0x0fbe00 // 4.030V
whismanoid 0:49c7e35bd044 482 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.040000) expect 0x0fc800 // 4.040V
whismanoid 0:49c7e35bd044 483 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.050000) expect 0x0fd200 // 4.050V
whismanoid 0:49c7e35bd044 484 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.060000) expect 0x0fdc00 // 4.060V
whismanoid 0:49c7e35bd044 485 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.070000) expect 0x0fe600 // 4.070V
whismanoid 0:49c7e35bd044 486 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.080000) expect 0x0ff000 // 4.080V
whismanoid 0:49c7e35bd044 487 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.090000) expect 0x0ffa00 // 4.090V
whismanoid 0:49c7e35bd044 488 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.100000) expect 0x0fffff // 4.100V
whismanoid 0:49c7e35bd044 489 // @test group DACCodeOfVoltage tinyTester.print("test_lsb_sweep V = 4.096000V LSBradius = 3LSB")
whismanoid 0:49c7e35bd044 490 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.095988) expect 0x0ffffd // 4.096V + -3.0LSB
whismanoid 0:49c7e35bd044 491 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.095990) expect 0x0ffffd // 4.096V + -2.5LSB 0x0ffffd not 0x0ffffe
whismanoid 0:49c7e35bd044 492 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.095992) expect 0x0ffffe // 4.096V + -2.0LSB
whismanoid 0:49c7e35bd044 493 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.095994) expect 0x0ffffe // 4.096V + -1.5LSB
whismanoid 0:49c7e35bd044 494 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.095996) expect 0x0fffff // 4.096V + -1.0LSB
whismanoid 0:49c7e35bd044 495 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.095998) expect 0x0fffff // 4.096V + -0.5LSB
whismanoid 0:49c7e35bd044 496 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.096000) expect 0x0fffff // 4.096V + 0.0LSB
whismanoid 0:49c7e35bd044 497 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.096002) expect 0x0fffff // 4.096V + 0.5LSB
whismanoid 0:49c7e35bd044 498 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.096004) expect 0x0fffff // 4.096V + 1.0LSB
whismanoid 0:49c7e35bd044 499 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.096006) expect 0x0fffff // 4.096V + 1.5LSB
whismanoid 0:49c7e35bd044 500 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.096008) expect 0x0fffff // 4.096V + 2.0LSB
whismanoid 0:49c7e35bd044 501 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.096010) expect 0x0fffff // 4.096V + 2.5LSB
whismanoid 0:49c7e35bd044 502 // @test group DACCodeOfVoltage DACCodeOfVoltage(4.096012) expect 0x0fffff // 4.096V + 3.0LSB
whismanoid 0:49c7e35bd044 503 // @test group DACCodeOfVoltage tinyTester.print("test_lsb_sweep V = 3.072000V LSBradius = 3LSB")
whismanoid 0:49c7e35bd044 504 // @test group DACCodeOfVoltage DACCodeOfVoltage(3.071988) expect 0x0bfffd // 3.072V + -3.0LSB
whismanoid 0:49c7e35bd044 505 // @test group DACCodeOfVoltage DACCodeOfVoltage(3.071990) expect 0x0bfffd // 3.072V + -2.5LSB 0x0bfffd not 0x0bfffe
whismanoid 0:49c7e35bd044 506 // @test group DACCodeOfVoltage DACCodeOfVoltage(3.071992) expect 0x0bfffe // 3.072V + -2.0LSB
whismanoid 0:49c7e35bd044 507 // @test group DACCodeOfVoltage DACCodeOfVoltage(3.071994) expect 0x0bfffe // 3.072V + -1.5LSB 0x0bfffe not 0x0bffff
whismanoid 0:49c7e35bd044 508 // @test group DACCodeOfVoltage DACCodeOfVoltage(3.071996) expect 0x0bffff // 3.072V + -1.0LSB
whismanoid 0:49c7e35bd044 509 // @test group DACCodeOfVoltage DACCodeOfVoltage(3.071998) expect 0x0bffff // 3.072V + -0.5LSB 0x0bffff not 0x0c0000
whismanoid 0:49c7e35bd044 510 // @test group DACCodeOfVoltage DACCodeOfVoltage(3.072000) expect 0x0c0000 // 3.072V + 0.0LSB
whismanoid 0:49c7e35bd044 511 // @test group DACCodeOfVoltage DACCodeOfVoltage(3.072002) expect 0x0c0001 // 3.072V + 0.5LSB
whismanoid 0:49c7e35bd044 512 // @test group DACCodeOfVoltage DACCodeOfVoltage(3.072004) expect 0x0c0001 // 3.072V + 1.0LSB
whismanoid 0:49c7e35bd044 513 // @test group DACCodeOfVoltage DACCodeOfVoltage(3.072006) expect 0x0c0002 // 3.072V + 1.5LSB
whismanoid 0:49c7e35bd044 514 // @test group DACCodeOfVoltage DACCodeOfVoltage(3.072008) expect 0x0c0002 // 3.072V + 2.0LSB
whismanoid 0:49c7e35bd044 515 // @test group DACCodeOfVoltage DACCodeOfVoltage(3.072010) expect 0x0c0003 // 3.072V + 2.5LSB
whismanoid 0:49c7e35bd044 516 // @test group DACCodeOfVoltage DACCodeOfVoltage(3.072012) expect 0x0c0003 // 3.072V + 3.0LSB
whismanoid 0:49c7e35bd044 517 // @test group DACCodeOfVoltage tinyTester.print("test_lsb_sweep V = 2.048000V LSBradius = 3LSB")
whismanoid 0:49c7e35bd044 518 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.047988) expect 0x07fffd // 2.048V + -3.0LSB
whismanoid 0:49c7e35bd044 519 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.047990) expect 0x07fffd // 2.048V + -2.5LSB
whismanoid 0:49c7e35bd044 520 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.047992) expect 0x07fffe // 2.048V + -2.0LSB
whismanoid 0:49c7e35bd044 521 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.047994) expect 0x07fffe // 2.048V + -1.5LSB 0x07fffe not 0x07ffff
whismanoid 0:49c7e35bd044 522 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.047996) expect 0x07ffff // 2.048V + -1.0LSB
whismanoid 0:49c7e35bd044 523 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.047998) expect 0x07ffff // 2.048V + -0.5LSB 0x07ffff not 0x080000
whismanoid 0:49c7e35bd044 524 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048000) expect 0x080000 // 2.048V + 0.0LSB
whismanoid 0:49c7e35bd044 525 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048002) expect 0x080001 // 2.048V + 0.5LSB
whismanoid 0:49c7e35bd044 526 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048004) expect 0x080001 // 2.048V + 1.0LSB
whismanoid 0:49c7e35bd044 527 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048006) expect 0x080002 // 2.048V + 1.5LSB
whismanoid 0:49c7e35bd044 528 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048008) expect 0x080002 // 2.048V + 2.0LSB
whismanoid 0:49c7e35bd044 529 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048010) expect 0x080003 // 2.048V + 2.5LSB
whismanoid 0:49c7e35bd044 530 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.048012) expect 0x080003 // 2.048V + 3.0LSB
whismanoid 0:49c7e35bd044 531 // @test group DACCodeOfVoltage tinyTester.print("test_lsb_sweep V = 1.024000V LSBradius = 3LSB")
whismanoid 0:49c7e35bd044 532 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.023988) expect 0x03fffd // 1.024V + -3.0LSB
whismanoid 0:49c7e35bd044 533 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.023990) expect 0x03fffd // 1.024V + -2.5LSB 0x03fffd not 0x03fffe
whismanoid 0:49c7e35bd044 534 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.023992) expect 0x03fffe // 1.024V + -2.0LSB
whismanoid 0:49c7e35bd044 535 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.023994) expect 0x03fffe // 1.024V + -1.5LSB
whismanoid 0:49c7e35bd044 536 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.023996) expect 0x03ffff // 1.024V + -1.0LSB
whismanoid 0:49c7e35bd044 537 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.023998) expect 0x03ffff // 1.024V + -0.5LSB 0x03ffff not 0x040000
whismanoid 0:49c7e35bd044 538 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.024000) expect 0x040000 // 1.024V + 0.0LSB
whismanoid 0:49c7e35bd044 539 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.024002) expect 0x040001 // 1.024V + 0.5LSB
whismanoid 0:49c7e35bd044 540 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.024004) expect 0x040001 // 1.024V + 1.0LSB
whismanoid 0:49c7e35bd044 541 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.024006) expect 0x040002 // 1.024V + 1.5LSB
whismanoid 0:49c7e35bd044 542 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.024008) expect 0x040002 // 1.024V + 2.0LSB
whismanoid 0:49c7e35bd044 543 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.024010) expect 0x040003 // 1.024V + 2.5LSB
whismanoid 0:49c7e35bd044 544 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.024012) expect 0x040003 // 1.024V + 3.0LSB
whismanoid 0:49c7e35bd044 545 // @test group DACCodeOfVoltage tinyTester.print("test_lsb_sweep V = 0.000000V LSBradius = 3LSB")
whismanoid 0:49c7e35bd044 546 // @test group DACCodeOfVoltage DACCodeOfVoltage(-0.000012) expect 0x000000 // 0.000V + -3.0LSB
whismanoid 0:49c7e35bd044 547 // @test group DACCodeOfVoltage DACCodeOfVoltage(-0.000010) expect 0x000000 // 0.000V + -2.5LSB
whismanoid 0:49c7e35bd044 548 // @test group DACCodeOfVoltage DACCodeOfVoltage(-0.000008) expect 0x000000 // 0.000V + -2.0LSB
whismanoid 0:49c7e35bd044 549 // @test group DACCodeOfVoltage DACCodeOfVoltage(-0.000006) expect 0x000000 // 0.000V + -1.5LSB
whismanoid 0:49c7e35bd044 550 // @test group DACCodeOfVoltage DACCodeOfVoltage(-0.000004) expect 0x000000 // 0.000V + -1.0LSB
whismanoid 0:49c7e35bd044 551 // @test group DACCodeOfVoltage DACCodeOfVoltage(-0.000002) expect 0x000000 // 0.000V + -0.5LSB
whismanoid 0:49c7e35bd044 552 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.000000) expect 0x000000 // 0.000V + 0.0LSB
whismanoid 0:49c7e35bd044 553 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.000002) expect 0x000001 // 0.000V + 0.5LSB
whismanoid 0:49c7e35bd044 554 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.000004) expect 0x000001 // 0.000V + 1.0LSB
whismanoid 0:49c7e35bd044 555 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.000006) expect 0x000002 // 0.000V + 1.5LSB
whismanoid 0:49c7e35bd044 556 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.000008) expect 0x000002 // 0.000V + 2.0LSB
whismanoid 0:49c7e35bd044 557 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.000010) expect 0x000003 // 0.000V + 2.5LSB
whismanoid 0:49c7e35bd044 558 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.000012) expect 0x000003 // 0.000V + 3.0LSB
whismanoid 0:49c7e35bd044 559 //
whismanoid 0:49c7e35bd044 560 // @test group DACCodeOfVoltage tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
whismanoid 0:49c7e35bd044 561 //
whismanoid 0:49c7e35bd044 562 //
whismanoid 0:49c7e35bd044 563 uint32_t MAX5719::DACCodeOfVoltage(double voltageV)
whismanoid 0:49c7e35bd044 564 {
whismanoid 0:49c7e35bd044 565
whismanoid 0:49c7e35bd044 566 //----------------------------------------
whismanoid 0:49c7e35bd044 567 // Linear map min and max endpoints
whismanoid 0:49c7e35bd044 568 const double MaxScaleVoltage = VRef; // voltage of maximum code 0xfffff
whismanoid 0:49c7e35bd044 569 const double MinScaleVoltage = 0.0; // voltage of minimum code 0x000
whismanoid 0:49c7e35bd044 570 const uint32_t FULL_SCALE_CODE_20BIT = 0xfffff;
whismanoid 0:49c7e35bd044 571 const uint32_t MaxCode = FULL_SCALE_CODE_20BIT;
whismanoid 0:49c7e35bd044 572 const uint32_t MinCode = 0x000;
whismanoid 0:49c7e35bd044 573 double codeFraction = (voltageV - MinScaleVoltage) / (MaxScaleVoltage - MinScaleVoltage);
whismanoid 0:49c7e35bd044 574 double dacRegValueIdeal = ((codeFraction * (double)(MaxCode - MinCode + 1)) + MinCode + 0.5);
whismanoid 0:49c7e35bd044 575 uint32_t dacRegValue = (uint32_t)dacRegValueIdeal;
whismanoid 0:49c7e35bd044 576 if (dacRegValueIdeal > MaxCode)
whismanoid 0:49c7e35bd044 577 {
whismanoid 0:49c7e35bd044 578 dacRegValue = MaxCode;
whismanoid 0:49c7e35bd044 579 } else if (dacRegValueIdeal < MinCode)
whismanoid 0:49c7e35bd044 580 {
whismanoid 0:49c7e35bd044 581 dacRegValue = MinCode;
whismanoid 0:49c7e35bd044 582 }
whismanoid 0:49c7e35bd044 583 return dacRegValue;
whismanoid 0:49c7e35bd044 584 }
whismanoid 0:49c7e35bd044 585
whismanoid 0:49c7e35bd044 586 //----------------------------------------
whismanoid 0:49c7e35bd044 587 // Menu item 'A'
whismanoid 0:49c7e35bd044 588 // CODE
whismanoid 0:49c7e35bd044 589 //
whismanoid 0:49c7e35bd044 590 // Load input register, but DAC registers are not updated until LOAD.
whismanoid 0:49c7e35bd044 591 // @return 1 on success; 0 on failure
whismanoid 0:49c7e35bd044 592 uint8_t MAX5719::CODE(uint32_t dacCodeLsbs)
whismanoid 0:49c7e35bd044 593 {
whismanoid 0:49c7e35bd044 594
whismanoid 0:49c7e35bd044 595 //----------------------------------------
whismanoid 0:49c7e35bd044 596 // SPI write 20-bit dacCodeLsbs in mosiData24
whismanoid 0:49c7e35bd044 597 SPIoutputCS(0);
whismanoid 0:49c7e35bd044 598 SPIwrite24bits(((dacCodeLsbs << 4) >> 16), ((dacCodeLsbs << 4) & 0xFFFF)); // 20-bit dacCodeLsbs in mosiData24
whismanoid 0:49c7e35bd044 599 SPIoutputCS(1);
whismanoid 0:49c7e35bd044 600
whismanoid 0:49c7e35bd044 601 //----------------------------------------
whismanoid 0:49c7e35bd044 602 // write-only DAC ouptut code
whismanoid 0:49c7e35bd044 603 DACCode = dacCodeLsbs;
whismanoid 0:49c7e35bd044 604
whismanoid 0:49c7e35bd044 605 //----------------------------------------
whismanoid 0:49c7e35bd044 606 // success
whismanoid 0:49c7e35bd044 607 return 1;
whismanoid 0:49c7e35bd044 608 }
whismanoid 0:49c7e35bd044 609
whismanoid 0:49c7e35bd044 610 //----------------------------------------
whismanoid 0:49c7e35bd044 611 // Menu item 'C'
whismanoid 0:49c7e35bd044 612 // CODE_LOAD
whismanoid 0:49c7e35bd044 613 //
whismanoid 0:49c7e35bd044 614 // Load input register; DAC registers are updated.
whismanoid 0:49c7e35bd044 615 // @return 1 on success; 0 on failure
whismanoid 0:49c7e35bd044 616 uint8_t MAX5719::CODE_LOAD(uint32_t dacCodeLsbs)
whismanoid 0:49c7e35bd044 617 {
whismanoid 0:49c7e35bd044 618
whismanoid 0:49c7e35bd044 619 //----------------------------------------
whismanoid 0:49c7e35bd044 620 // SPI write 20-bit dacCodeLsbs in mosiData24
whismanoid 0:49c7e35bd044 621 SPIoutputCS(0);
whismanoid 0:49c7e35bd044 622 SPIwrite24bits(((dacCodeLsbs << 4) >> 16), ((dacCodeLsbs << 4) & 0xFFFF)); // 20-bit dacCodeLsbs in mosiData24
whismanoid 0:49c7e35bd044 623 SPIoutputCS(1);
whismanoid 0:49c7e35bd044 624
whismanoid 0:49c7e35bd044 625 //----------------------------------------
whismanoid 0:49c7e35bd044 626 // write-only DAC ouptut code
whismanoid 0:49c7e35bd044 627 DACCode = dacCodeLsbs;
whismanoid 0:49c7e35bd044 628
whismanoid 0:49c7e35bd044 629 //----------------------------------------
whismanoid 0:49c7e35bd044 630 // call low-level GPIO function
whismanoid 0:49c7e35bd044 631 LDACboutputValue(0); // LDAC# Active
whismanoid 0:49c7e35bd044 632
whismanoid 0:49c7e35bd044 633 //----------------------------------------
whismanoid 0:49c7e35bd044 634 // call low-level GPIO function
whismanoid 0:49c7e35bd044 635 LDACboutputValue(1); // LDAC# Inactive
whismanoid 0:49c7e35bd044 636
whismanoid 0:49c7e35bd044 637 //----------------------------------------
whismanoid 0:49c7e35bd044 638 // success
whismanoid 0:49c7e35bd044 639 return 1;
whismanoid 0:49c7e35bd044 640 }
whismanoid 0:49c7e35bd044 641
whismanoid 0:49c7e35bd044 642 //----------------------------------------
whismanoid 0:49c7e35bd044 643 // Menu item 'B'
whismanoid 0:49c7e35bd044 644 // LOAD
whismanoid 0:49c7e35bd044 645 //
whismanoid 0:49c7e35bd044 646 // Update DAC registers from input registers.
whismanoid 0:49c7e35bd044 647 // @return 1 on success; 0 on failure
whismanoid 0:49c7e35bd044 648 uint8_t MAX5719::LOAD(void)
whismanoid 0:49c7e35bd044 649 {
whismanoid 0:49c7e35bd044 650
whismanoid 0:49c7e35bd044 651 //----------------------------------------
whismanoid 0:49c7e35bd044 652 // call low-level GPIO function
whismanoid 0:49c7e35bd044 653 LDACboutputValue(0); // LDAC# Active
whismanoid 0:49c7e35bd044 654
whismanoid 0:49c7e35bd044 655 //----------------------------------------
whismanoid 0:49c7e35bd044 656 // call low-level GPIO function
whismanoid 0:49c7e35bd044 657 LDACboutputValue(1); // LDAC# Inactive
whismanoid 0:49c7e35bd044 658
whismanoid 0:49c7e35bd044 659 //----------------------------------------
whismanoid 0:49c7e35bd044 660 // success
whismanoid 0:49c7e35bd044 661 return 1;
whismanoid 0:49c7e35bd044 662 }
whismanoid 0:49c7e35bd044 663
whismanoid 0:49c7e35bd044 664
whismanoid 0:49c7e35bd044 665 // End of file