Maxim Integrated MAX5171 14-bit Force/Sense DAC

Dependents:   MAX5171BOB_Tester MAX5171BOB_14bit_Remote_Sense_SPI_DAC MAX5171BOB_Serial_Tester

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MAX5171.cpp Source File

MAX5171.cpp

00001 // /*******************************************************************************
00002 // * Copyright (C) 2020 Maxim Integrated Products, Inc., All Rights Reserved.
00003 // *
00004 // * Permission is hereby granted, free of charge, to any person obtaining a
00005 // * copy of this software and associated documentation files (the "Software"),
00006 // * to deal in the Software without restriction, including without limitation
00007 // * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008 // * and/or sell copies of the Software, and to permit persons to whom the
00009 // * Software is furnished to do so, subject to the following conditions:
00010 // *
00011 // * The above copyright notice and this permission notice shall be included
00012 // * in all copies or substantial portions of the Software.
00013 // *
00014 // * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015 // * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016 // * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017 // * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018 // * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019 // * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020 // * OTHER DEALINGS IN THE SOFTWARE.
00021 // *
00022 // * Except as contained in this notice, the name of Maxim Integrated
00023 // * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024 // * Products, Inc. Branding Policy.
00025 // *
00026 // * The mere transfer of this software does not imply any licenses
00027 // * of trade secrets, proprietary technology, copyrights, patents,
00028 // * trademarks, maskwork rights, or any other form of intellectual
00029 // * property whatsoever. Maxim Integrated Products, Inc. retains all
00030 // * ownership rights.
00031 // *******************************************************************************
00032 // */
00033 // *********************************************************************
00034 // @file MAX5171.cpp
00035 // *********************************************************************
00036 // Device Driver file
00037 // DO NOT EDIT; except areas designated "CUSTOMIZE". Automatically generated file.
00038 // generated by XMLSystemOfDevicesToMBED.py
00039 // System Name = ExampleSystem
00040 // System Description = Device driver example
00041 
00042 #include "MAX5171.h"
00043 
00044 // Device Name = MAX5171
00045 // Device Description = Low-Power, Serial, 14-Bit, 1-Channel DACs with Force/Sense Voltage Output and SPI Interface
00046 // Device DeviceBriefDescription = 14-bit Force/Sense DAC
00047 // Device Manufacturer = Maxim Integrated
00048 // Device PartNumber = MAX5171AEEE+
00049 // Device RegValue_Width = DataWidth16bit_HL
00050 //
00051 // DAC NumChannels = 1
00052 // DAC ResolutionBits = 14
00053 //
00054 // SPI CS = ActiveLow
00055 // SPI FrameStart = CS
00056 // SPI CPOL = 0
00057 // SPI CPHA = 0
00058 // SPI MOSI and MISO Data are both stable on Rising edge of SCLK
00059 // SPI SCLK Idle Low
00060 // SPI SCLKMaxMHz = 10
00061 // SPI SCLKMinMHz = 0
00062 //
00063 // InputPin Name = FB
00064 // InputPin Description = Feedback Input
00065 // InputPin Function = Analog
00066 //
00067 // InputPin Name = RS
00068 // InputPin Description = Reset Mode Select (digital input). Connect to VDD to select midscale reset output value. Connect to DGND
00069 // to select 0 reset output value.
00070 // InputPin Function = Configuration
00071 //
00072 // InputPin Name = PDL#
00073 // InputPin Description = Power-Down Lockout (digital input). Connect to VDD to allow shutdown. Connect to DGND to disable shutdown.
00074 // InputPin Function = Configuration
00075 //
00076 // InputPin Name = CLR#
00077 // InputPin Description = Clear DAC (digital input). Clears the DAC to its predetermined output state as set by RS.
00078 // InputPin Function = Configuration
00079 //
00080 // InputPin Name = SHDN
00081 // InputPin Description = Shutdown (digital input). Pulling SHDN high when PDL = VDD places the chip in shutdown mode with a
00082 // maximum shutdown current 0f 10uA.
00083 // InputPin Function = Configuration
00084 //
00085 // OutputPin Name = OUT
00086 // OutputPin Description = Analog Voltage Output. High impedance in shutdown. Output voltage is limited to VDD.
00087 // OutputPin Function = Analog
00088 //
00089 // OutputPin Name = UPO
00090 // OutputPin Description = User-Programmable Output. State is set by serial input.
00091 // OutputPin Function = General-Purpose
00092 //
00093 // SupplyPin Name = VDD
00094 // SupplyPin Description = Positive Supply. Bypass to AGND with a 4.7uF capacitor in parallel with a 0.1uF capacitor.
00095 // SupplyPin VinMax = 4.50
00096 // SupplyPin VinMin = 5.50
00097 // SupplyPin Function = Analog
00098 //
00099 // SupplyPin Name = REF
00100 // SupplyPin Description = Reference Input. Maximum VREF is VDD - 1.4V. Connect an external +2.5V reference.
00101 // SupplyPin VinMax = VDD-1.4
00102 // SupplyPin VinMin = 0
00103 // SupplyPin Function = Analog
00104 //
00105 // SupplyPin Name = DGND
00106 // SupplyPin Description = Digital Ground.
00107 // SupplyPin VinMax = 0
00108 // SupplyPin VinMin = 0
00109 // SupplyPin Function = Analog
00110 //
00111 // SupplyPin Name = AGND
00112 // SupplyPin Description = Analog Ground.
00113 // SupplyPin VinMax = 0
00114 // SupplyPin VinMin = 0
00115 // SupplyPin Function = Analog
00116 //
00117 
00118 MAX5171::MAX5171(SPI &spi, DigitalOut &cs_pin, // SPI interface
00119                  // AnalogOut &FB_pin, // Analog Input to MAX5171 device
00120                  DigitalOut &RS_pin, // Digital Configuration Input to MAX5171 device
00121                  DigitalOut &PDLb_pin, // Digital Configuration Input to MAX5171 device
00122                  DigitalOut &CLRb_pin, // Digital Configuration Input to MAX5171 device
00123                  DigitalOut &SHDN_pin, // Digital Configuration Input to MAX5171 device
00124                  // AnalogIn &OUT_pin, // Analog Output from MAX5171 device
00125                  DigitalIn &UPO_pin, // Digital General-Purpose Output from MAX5171 device
00126                  MAX5171_ic_t ic_variant)
00127     : m_spi(spi), m_cs_pin(cs_pin), // SPI interface
00128     // m_FB_pin(FB_pin), // Analog Input to MAX5171 device
00129     m_RS_pin(RS_pin), // Digital Configuration Input to MAX5171 device
00130     m_PDLb_pin(PDLb_pin), // Digital Configuration Input to MAX5171 device
00131     m_CLRb_pin(CLRb_pin), // Digital Configuration Input to MAX5171 device
00132     m_SHDN_pin(SHDN_pin), // Digital Configuration Input to MAX5171 device
00133     // m_OUT_pin(OUT_pin), // Analog Output from MAX5171 device
00134     m_UPO_pin(UPO_pin), // Digital General-Purpose Output from MAX5171 device
00135     m_ic_variant(ic_variant)
00136 {
00137     // SPI CS = ActiveLow
00138     // SPI FrameStart = CS
00139     m_SPI_cs_state = 1;
00140     if (m_cs_pin.is_connected()) { // avoid mbed runtime error if pin is NC not connected
00141         m_cs_pin = m_SPI_cs_state;
00142     }
00143 
00144     // SPI CPOL = 0
00145     // SPI CPHA = 0
00146     // SPI MOSI and MISO Data are both stable on Rising edge of SCLK
00147     // SPI SCLK Idle Low
00148     m_SPI_dataMode = 0; //SPI_MODE0; // CPOL=0,CPHA=0: Rising Edge stable; SCLK idle Low
00149     m_spi.format(8,m_SPI_dataMode);         // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0
00150 
00151     // SPI SCLKMaxMHz = 10
00152     // SPI SCLKMinMHz = 0
00153     //#define SPI_SCLK_Hz 48000000 // 48MHz
00154     //#define SPI_SCLK_Hz 24000000 // 24MHz
00155     //#define SPI_SCLK_Hz 12000000 // 12MHz
00156     //#define SPI_SCLK_Hz 6000000 // 6MHz
00157     //#define SPI_SCLK_Hz 4000000 // 4MHz
00158     //#define SPI_SCLK_Hz 2000000 // 2MHz
00159     //#define SPI_SCLK_Hz 1000000 // 1MHz
00160     m_SPI_SCLK_Hz = 10000000; // 10MHz; MAX5171 limit is 10MHz
00161     m_spi.frequency(m_SPI_SCLK_Hz);
00162 
00163     //
00164     // FB Analog Input to MAX5171 device
00165     //
00166     // RS Configuration Input to MAX5171 device
00167     m_RS_pin = 1; // output logic high -- initial value in constructor
00168     //
00169     // PDLb Configuration Input to MAX5171 device
00170     m_PDLb_pin = 1; // output logic high -- initial value in constructor
00171     //
00172     // CLRb Configuration Input to MAX5171 device
00173     m_CLRb_pin = 1; // output logic high -- initial value in constructor
00174     //
00175     // SHDN Configuration Input to MAX5171 device
00176     m_SHDN_pin = 1; // output logic high -- initial value in constructor
00177     //
00178     // OUT Analog Output from device
00179     //
00180     // UPO General-Purpose Output from device
00181 }
00182 
00183 MAX5171::~MAX5171()
00184 {
00185     // do nothing
00186 }
00187 
00188 /// set SPI SCLK frequency
00189 void MAX5171::spi_frequency(int spi_sclk_Hz)
00190 {
00191     m_SPI_SCLK_Hz = spi_sclk_Hz;
00192     m_spi.frequency(m_SPI_SCLK_Hz);
00193 }
00194 
00195 // Assert SPI Chip Select
00196 // SPI chip-select for MAX5171
00197 //
00198 inline void MAX5171::SPIoutputCS(int isLogicHigh)
00199 {
00200     m_SPI_cs_state = isLogicHigh;
00201     if (m_cs_pin.is_connected()) { // avoid mbed runtime error if pin is NC not connected
00202         m_cs_pin = m_SPI_cs_state;
00203     }
00204 }
00205 
00206 // SPI write 16 bits
00207 // SPI interface to MAX5171 shift 16 bits mosiData into MAX5171 DIN
00208 //
00209 void MAX5171::SPIwrite16bits(int16_t mosiData16)
00210 {
00211     size_t byteCount = 2;
00212     static char mosiData[2];
00213     static char misoData[2];
00214     mosiData[0] = (char)((mosiData16 >> 8) & 0xFF); // MSByte
00215     mosiData[1] = (char)((mosiData16 >> 0) & 0xFF); // LSByte
00216     //
00217     // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts()
00218     //~ noInterrupts();
00219     //
00220     //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin
00221     //
00222     unsigned int numBytesTransferred = m_spi.write(mosiData, byteCount, misoData, byteCount);
00223     //~ m_spi.transfer(mosiData8_FF0000);
00224     //~ m_spi.transfer(mosiData16_00FF00);
00225     //~ m_spi.transfer(mosiData16_0000FF);
00226     //
00227     //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin
00228     //
00229     // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts()
00230     //~ interrupts();
00231     // Optional Diagnostic function to print SPI transactions
00232     if (onSPIprint)
00233     {
00234         onSPIprint(byteCount, (uint8_t*)mosiData, (uint8_t*)misoData);
00235     }
00236     //
00237     // VERIFY: SPIwrite24bits print diagnostic information
00238     //cmdLine.serial().printf(" MOSI->"));
00239     //cmdLine.serial().printf(" 0x"));
00240     //Serial.print( (mosiData8_FF0000 & 0xFF), HEX);
00241     //cmdLine.serial().printf(" 0x"));
00242     //Serial.print( (mosiData16_00FF00 & 0xFF), HEX);
00243     //cmdLine.serial().printf(" 0x"));
00244     //Serial.print( (mosiData16_0000FF & 0xFF), HEX);
00245     // hex dump mosiData[0..byteCount-1]
00246 #if 0 // HAS_MICROUSBSERIAL
00247     cmdLine_microUSBserial.serial().printf("\r\nSPI");
00248     if (byteCount > 7) {
00249         cmdLine_microUSBserial.serial().printf(" byteCount:%d", byteCount);
00250     }
00251     cmdLine_microUSBserial.serial().printf(" MOSI->");
00252     for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++)
00253     {
00254         cmdLine_microUSBserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]);
00255     }
00256     // hex dump misoData[0..byteCount-1]
00257     cmdLine_microUSBserial.serial().printf(" MISO<-");
00258     for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++)
00259     {
00260         cmdLine_microUSBserial.serial().printf(" 0x%2.2X", misoData[byteIndex]);
00261     }
00262     cmdLine_microUSBserial.serial().printf(" ");
00263 #endif
00264 #if 0 // HAS_DAPLINK_SERIAL
00265     cmdLine_DAPLINKserial.serial().printf("\r\nSPI");
00266     if (byteCount > 7) {
00267         cmdLine_DAPLINKserial.serial().printf(" byteCount:%d", byteCount);
00268     }
00269     cmdLine_DAPLINKserial.serial().printf(" MOSI->");
00270     for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++)
00271     {
00272         cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]);
00273     }
00274     // hex dump misoData[0..byteCount-1]
00275     cmdLine_DAPLINKserial.serial().printf(" MISO<-");
00276     for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++)
00277     {
00278         cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", misoData[byteIndex]);
00279     }
00280     cmdLine_DAPLINKserial.serial().printf(" ");
00281 #endif
00282     // VERIFY: DIAGNOSTIC: print MAX5715 device register write
00283     // TODO: MAX5715_print_register_verbose(mosiData8_FF0000, mosiData16_00FFFF);
00284     // TODO: print_verbose_SPI_diagnostic(mosiData16_FF00, mosiData16_00FF, misoData16_FF00, misoData16_00FF);
00285     //
00286     // int misoData16 = (misoData16_FF00 << 8) | misoData16_00FF;
00287     // return misoData16;
00288 }
00289 
00290 //----------------------------------------
00291 // Menu item '!'
00292 // Initialize device
00293 //
00294 // TODO1: #170 MAX5171 Self Test for Test Fixture Firmware
00295 // @future test group ____ // Verify function ____ (enabled by default)
00296 // @future test
00297 //     tinyTester.settle_time_msec = 250;
00298 //
00299 // @test group DACCodeOfVoltage // Verify function DACCodeOfVoltage (enabled by default)
00300 // @test group DACCodeOfVoltage tinyTester.blink_time_msec = 20 // quickly speed through the software verification
00301 // @test group DACCodeOfVoltage tinyTester.print("VRef = 2.500  MAX5171 14-bit LSB = 0.00015V")
00302 // @test group DACCodeOfVoltage VRef = 2.500
00303 // @test group DACCodeOfVoltage tinyTester.err_threshold = 0.00015259720441921504 // 14-bit LSB (2.500/16383)
00304 //     //
00305 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.499847412109375) expect 0x3FFF
00306 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.49969482421875) expect 0x3FFE
00307 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.499542236328125) expect 0x3FFD
00308 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.4993896484375) expect 0x3FFC
00309 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.250152587890625) expect 0x2001
00310 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.25) expect 0x2000
00311 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.249847412109375) expect 0x1FFF
00312 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.24969482421875) expect 0x1FFE
00313 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.000457763671875) expect 0x0003
00314 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.00030517578125) expect 0x0002
00315 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.000152587890625) expect 0x0001
00316 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.00000) expect 0x0000
00317 // @test group DACCodeOfVoltage tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
00318 //     //
00319 // @test group VoltageOfCode // Verify function VoltageOfCode (enabled by default)
00320 // @test group VoltageOfCode tinyTester.blink_time_msec = 20 // quickly speed through the software verification
00321 // @test group VoltageOfCode tinyTester.print("VRef = 2.500  MAX5171 14-bit LSB = 0.00015V")
00322 // @test group VoltageOfCode VRef = 2.500
00323 // @test group VoltageOfCode tinyTester.err_threshold = 0.00015259720441921504 // 14-bit LSB (2.500/16383)
00324 // @test group VoltageOfCode VoltageOfCode(0x3FFF) expect 2.499847412109375
00325 // @test group VoltageOfCode VoltageOfCode(0x3FFE) expect 2.49969482421875
00326 // @test group VoltageOfCode VoltageOfCode(0x3FFD) expect 2.499542236328125
00327 // @test group VoltageOfCode VoltageOfCode(0x3FFC) expect 2.4993896484375
00328 // @test group VoltageOfCode VoltageOfCode(0x2001) expect 1.250152587890625
00329 // @test group VoltageOfCode VoltageOfCode(0x2000) expect 1.25
00330 // @test group VoltageOfCode VoltageOfCode(0x1FFF) expect 1.249847412109375
00331 // @test group VoltageOfCode VoltageOfCode(0x1FFE) expect 1.24969482421875
00332 // @test group VoltageOfCode VoltageOfCode(0x0003) expect 0.000457763671875
00333 // @test group VoltageOfCode VoltageOfCode(0x0002) expect 0.00030517578125
00334 // @test group VoltageOfCode VoltageOfCode(0x0001) expect 0.000152587890625
00335 // @test group VoltageOfCode VoltageOfCode(0x0000) expect 0.00000
00336 // @test group VoltageOfCode tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
00337 //     //
00338 //     // Device Testing: DAC commands, verify using on-board ADC inputs
00339 //     //
00340 // @test group CODE_LOAD // Verify function CODE_LOAD (enabled by default)
00341 // @test group CODE_LOAD tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
00342 // @test group CODE_LOAD tinyTester.settle_time_msec = 500
00343 //     tinyTester.blink_time_msec = 75;
00344 //     cmdLine.serial().printf("
00345 //       MAX5171.Init()");
00346 //     Init();
00347 // @test Init()
00348 // @test VRef expect 2.500 // Nominal Full-Scale Voltage Reference
00349 //     //
00350 //     tinyTester.err_threshold = 0.030; // 30mV
00351 // @test group CODE_LOAD tinyTester.err_threshold = 0.050
00352 //     uint16_t code = 0x3FFF;
00353 //     //~ double voltageV = 0.5;
00354 //     //
00355 //     cmdLine.serial().printf("
00356 //       MAX5171.CODE_LOAD code=%d", code);
00357 //     CODE_LOAD(code);
00358 // @test group CODE_LOAD tinyTester.print("100.0% of full scale REF(2.50V) = 2.50V Jumper FB=1-2")
00359 // @test group CODE_LOAD CODE_LOAD(0x3FFF) // 100.0% of full scale REF(2.50V) = 2.50V
00360 //     // tinyTester.Wait_Output_Settling replaces wait_ms
00361 //     tinyTester.Wait_Output_Settling();
00362 // @test group CODE_LOAD tinyTester.Wait_Output_Settling()
00363 //     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
00364 //     tinyTester.AnalogIn0_Read_Expect_voltageV(2.500);
00365 // @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(2.500)
00366 //     //
00367 //     code = 0x0000;
00368 //     cmdLine.serial().printf("
00369 //       MAX5171.CODE_LOAD code=%d", code);
00370 //     CODE_LOAD(code);
00371 // @test group CODE_LOAD tinyTester.print("0.0% of full scale REF(2.50V) = 0.000V")
00372 // @test group CODE_LOAD CODE_LOAD(0x0000) // 0.0% of full scale REF(2.50V) = 0.000V
00373 //     // tinyTester.Wait_Output_Settling replaces wait_ms
00374 //     tinyTester.Wait_Output_Settling();
00375 // @test group CODE_LOAD tinyTester.Wait_Output_Settling()
00376 //     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
00377 //     tinyTester.AnalogIn0_Read_Expect_voltageV(0.0000);
00378 // @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(0.0000)
00379 //     //
00380 //     code = 0x1FFF;
00381 //     cmdLine.serial().printf("
00382 //       MAX5171.CODE_LOAD code=%d", code);
00383 //     CODE_LOAD(code);
00384 // @test group CODE_LOAD tinyTester.print("50.0% of full scale REF(2.50V) = 1.25V")
00385 // @test group CODE_LOAD CODE_LOAD(0x1FFF) // 50.0% of full scale REF(2.50V) = 1.25V
00386 //     // tinyTester.Wait_Output_Settling replaces wait_ms
00387 //     tinyTester.Wait_Output_Settling();
00388 // @test group CODE_LOAD tinyTester.Wait_Output_Settling()
00389 //     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
00390 //     tinyTester.AnalogIn0_Read_Expect_voltageV(1.2500);
00391 // @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(1.2500)
00392 //     //
00393 //     // test UPO User Programmable Output, verify using digital input D2
00394 //     //
00395 // @test group UPO // Verify User Programmable Output functions UPO_HIGH and UPO_LOW (enabled by default)
00396 // @test group UPO tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
00397 // @test group UPO tinyTester.settle_time_msec = 500 // default 250
00398 //     cmdLine.serial().printf("
00399 //       MAX5171.UPO_HIGH");
00400 //     UPO_HIGH();
00401 // @test group UPO UPO_HIGH()
00402 //     tinyTester.Wait_Output_Settling();
00403 // @test group UPO tinyTester.Wait_Output_Settling()
00404 //     // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
00405 //     tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command");
00406 // @test group CODE_LOAD tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command")
00407 //     //
00408 //     cmdLine.serial().printf("
00409 //       MAX5171.UPO_LOW");
00410 //     UPO_LOW();
00411 // @test group UPO UPO_LOW()
00412 //     tinyTester.Wait_Output_Settling();
00413 // @test group UPO tinyTester.Wait_Output_Settling()
00414 //     // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
00415 //     tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 0, "UPO_pin is low after MAX5171 UPO_LOW command");
00416 // @test group CODE_LOAD tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 0, "UPO_pin is low after MAX5171 UPO_LOW command")
00417 //     //
00418 //     cmdLine.serial().printf("
00419 //       MAX5171.UPO_HIGH");
00420 //     UPO_HIGH();
00421 // @test group UPO UPO_HIGH()
00422 //     tinyTester.Wait_Output_Settling();
00423 // @test group UPO tinyTester.Wait_Output_Settling()
00424 //     // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
00425 //     tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command");
00426 // @test group CODE_LOAD tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command")
00427 //     //
00428 //
00429 //
00430 void MAX5171::Init(void)
00431 {
00432     
00433     //----------------------------------------
00434     // Nominal Full-Scale Voltage Reference
00435     VRef = 2.500;
00436 }
00437 
00438 //----------------------------------------
00439 // Return the DAC register value corresponding to physical voltage.
00440 // Does not perform any offset or gain correction.
00441 //
00442 // @pre VRef = Voltage of REF input, in Volts
00443 // @param[in] voltage = physical voltage in Volts
00444 // @return raw 14-bit MAX5171 code (right justified).
00445 uint16_t MAX5171::DACCodeOfVoltage(double voltageV)
00446 {
00447     
00448     //----------------------------------------
00449     // Linear map min and max endpoints
00450     const double MaxScaleVoltage = VRef; // voltage of maximum code 0x3fff
00451     const double MinScaleVoltage = 0.0; // voltage of minimum code 0x000
00452     const uint16_t FULL_SCALE_CODE_14BIT = 0x3fff;
00453     const uint16_t MaxCode = FULL_SCALE_CODE_14BIT;
00454     const uint16_t MinCode = 0x000;
00455     double codeFraction = (voltageV - MinScaleVoltage) / (MaxScaleVoltage - MinScaleVoltage);
00456     double dacRegValueIdeal = ((codeFraction * (double)(MaxCode - MinCode + 1)) + MinCode + 0.5);
00457     uint16_t dacRegValue = (uint16_t)dacRegValueIdeal;
00458     if (dacRegValueIdeal > MaxCode)
00459     {
00460         dacRegValue = MaxCode;
00461     } else if (dacRegValueIdeal < MinCode)
00462     {
00463         dacRegValue = MinCode;
00464     }
00465     return dacRegValue;
00466 }
00467 
00468 //----------------------------------------
00469 // Return the physical voltage corresponding to DAC register.
00470 // Does not perform any offset or gain correction.
00471 //
00472 // @pre VRef = Voltage of REF input, in Volts
00473 // @param[in] value_u14: raw 14-bit MAX5171 code (right justified).
00474 // @return physical voltage corresponding to MAX5171 code.
00475 double MAX5171::VoltageOfCode(uint16_t value_u14)
00476 {
00477     
00478     //----------------------------------------
00479     // Linear map min and max endpoints
00480     double MaxScaleVoltage = VRef; // voltage of maximum code 0x3fff
00481     double MinScaleVoltage = 0.0; // voltage of minimum code 0x000
00482     const uint16_t FULL_SCALE_CODE_14BIT = 0x3fff;
00483     const uint16_t MaxCode = FULL_SCALE_CODE_14BIT;
00484     const uint16_t MinCode = 0x000;
00485     double codeFraction = ((double)value_u14 - MinCode) / (MaxCode - MinCode + 1);
00486     return MinScaleVoltage + ((MaxScaleVoltage - MinScaleVoltage) * codeFraction);
00487 }
00488 
00489 //----------------------------------------
00490 // CMD_00dd_dddd_dddd_dddd_CODE
00491 //
00492 // Load input register; DAC registers are unchanged.
00493 // @return 1 on success; 0 on failure
00494 uint8_t MAX5171::CODE(uint16_t dacCodeLsbs)
00495 {
00496     
00497     //----------------------------------------
00498     // Define command code
00499     uint16_t mosiData16 = CMD_00dd_dddd_dddd_dddd_CODE
00500         | ((0x3FFF & dacCodeLsbs) << 0); // left-align dddd_dddd_dddd
00501     
00502     //----------------------------------------
00503     // SPI write 16-bit mosiData16
00504     SPIoutputCS(0);
00505     SPIwrite16bits(mosiData16);
00506     SPIoutputCS(1);
00507     
00508     //----------------------------------------
00509     // shadow of write-only register CMD_00dd_dddd_dddd_dddd_CODE
00510     DACCode = dacCodeLsbs;
00511     
00512     //----------------------------------------
00513     // success
00514     return 1;
00515 }
00516 
00517 //----------------------------------------
00518 // CMD_01dd_dddd_dddd_dddd_CODE_LOAD
00519 //
00520 // Load input register; DAC registers are updated (start up DAC with new data).
00521 // @return 1 on success; 0 on failure
00522 uint8_t MAX5171::CODE_LOAD(uint16_t dacCodeLsbs)
00523 {
00524     
00525     //----------------------------------------
00526     // Define command code
00527     uint16_t mosiData16 = CMD_01dd_dddd_dddd_dddd_CODE_LOAD
00528         | ((0x3FFF & dacCodeLsbs) << 0); // left-align dddd_dddd_dddd
00529     
00530     //----------------------------------------
00531     // SPI write 16-bit mosiData16
00532     SPIoutputCS(0);
00533     SPIwrite16bits(mosiData16);
00534     SPIoutputCS(1);
00535     
00536     //----------------------------------------
00537     // shadow of write-only register CMD_00dd_dddd_dddd_dddd_CODE
00538     DACCode = dacCodeLsbs;
00539     
00540     //----------------------------------------
00541     // success
00542     return 1;
00543 }
00544 
00545 //----------------------------------------
00546 // CMD_10xx_xxxx_xxxx_xxxx_LOAD
00547 //
00548 // Update DAC register from input register (start up DAC with data previously
00549 // stored in the input registers).
00550 // @return 1 on success; 0 on failure
00551 uint8_t MAX5171::LOAD(void)
00552 {
00553     
00554     //----------------------------------------
00555     // Define command code
00556     uint16_t mosiData16 = CMD_10xx_xxxx_xxxx_xxxx_LOAD;
00557     
00558     //----------------------------------------
00559     // SPI write 16-bit mosiData16
00560     SPIoutputCS(0);
00561     SPIwrite16bits(mosiData16);
00562     SPIoutputCS(1);
00563     
00564     //----------------------------------------
00565     // success
00566     return 1;
00567 }
00568 
00569 //----------------------------------------
00570 // CMD_1100_xxxx_xxxx_xxxx_NOP
00571 //
00572 // No operation (NOP).
00573 // @return 1 on success; 0 on failure
00574 uint8_t MAX5171::NOP(void)
00575 {
00576     
00577     //----------------------------------------
00578     // Define command code
00579     uint16_t mosiData16 = CMD_1100_xxxx_xxxx_xxxx_NOP;
00580     
00581     //----------------------------------------
00582     // SPI write 16-bit mosiData16
00583     SPIoutputCS(0);
00584     SPIwrite16bits(mosiData16);
00585     SPIoutputCS(1);
00586     
00587     //----------------------------------------
00588     // success
00589     return 1;
00590 }
00591 
00592 //----------------------------------------
00593 // CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN
00594 //
00595 // Shut down DAC (provided PDL# = 1).
00596 // @return 1 on success; 0 on failure
00597 uint8_t MAX5171::SHUTDOWN(void)
00598 {
00599     
00600     //----------------------------------------
00601     // Define command code
00602     uint16_t mosiData16 = CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN;
00603     
00604     //----------------------------------------
00605     // SPI write 16-bit mosiData16
00606     SPIoutputCS(0);
00607     SPIwrite16bits(mosiData16);
00608     SPIoutputCS(1);
00609     
00610     //----------------------------------------
00611     // success
00612     return 1;
00613 }
00614 
00615 //----------------------------------------
00616 // CMD_1110_0xxx_xxxx_xxxx_UPO_LOW
00617 //
00618 // UPO goes low (default).
00619 // @return 1 on success; 0 on failure
00620 uint8_t MAX5171::UPO_LOW(void)
00621 {
00622     
00623     //----------------------------------------
00624     // Define command code
00625     uint16_t mosiData16 = CMD_1110_0xxx_xxxx_xxxx_UPO_LOW;
00626     
00627     //----------------------------------------
00628     // SPI write 16-bit mosiData16
00629     SPIoutputCS(0);
00630     SPIwrite16bits(mosiData16);
00631     SPIoutputCS(1);
00632     
00633     //----------------------------------------
00634     // success
00635     return 1;
00636 }
00637 
00638 //----------------------------------------
00639 // CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH
00640 //
00641 // UPO goes high.
00642 // @return 1 on success; 0 on failure
00643 uint8_t MAX5171::UPO_HIGH(void)
00644 {
00645     
00646     //----------------------------------------
00647     // Define command code
00648     uint16_t mosiData16 = CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH;
00649     
00650     //----------------------------------------
00651     // SPI write 16-bit mosiData16
00652     SPIoutputCS(0);
00653     SPIwrite16bits(mosiData16);
00654     SPIoutputCS(1);
00655     
00656     //----------------------------------------
00657     // success
00658     return 1;
00659 }
00660 
00661 //----------------------------------------
00662 // CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE
00663 //
00664 // Mode 1, DOUT clocked out on SCLK's rising edge.
00665 // @return 1 on success; 0 on failure
00666 uint8_t MAX5171::MODE1_DOUT_SCLK_RISING_EDGE(void)
00667 {
00668     
00669     //----------------------------------------
00670     // Define command code
00671     uint16_t mosiData16 = CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE;
00672     
00673     //----------------------------------------
00674     // SPI write 16-bit mosiData16
00675     SPIoutputCS(0);
00676     SPIwrite16bits(mosiData16);
00677     SPIoutputCS(1);
00678     
00679     //----------------------------------------
00680     // success
00681     return 1;
00682 }
00683 
00684 //----------------------------------------
00685 // CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE
00686 //
00687 // Mode 0, DOUT clocked out on SCLK's falling edge (default).
00688 // @return 1 on success; 0 on failure
00689 uint8_t MAX5171::MODE0_DOUT_SCLK_FALLING_EDGE(void)
00690 {
00691     
00692     //----------------------------------------
00693     // Define command code
00694     uint16_t mosiData16 = CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE;
00695     
00696     //----------------------------------------
00697     // SPI write 16-bit mosiData16
00698     SPIoutputCS(0);
00699     SPIwrite16bits(mosiData16);
00700     SPIoutputCS(1);
00701     
00702     //----------------------------------------
00703     // success
00704     return 1;
00705 }
00706 
00707 
00708 // End of file