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.h Source File

MAX5171.h

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.h
00035 // *********************************************************************
00036 // Header 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 // Device Name = MAX5171
00042 // Device Description = Low-Power, Serial, 14-Bit, 1-Channel DACs with Force/Sense Voltage Output and SPI Interface
00043 // Device DeviceBriefDescription = 14-bit Force/Sense DAC
00044 // Device Manufacturer = Maxim Integrated
00045 // Device PartNumber = MAX5171AEEE+
00046 // Device RegValue_Width = DataWidth16bit_HL
00047 //
00048 // DAC NumChannels = 1
00049 // DAC ResolutionBits = 14
00050 //
00051 // SPI CS = ActiveLow
00052 // SPI FrameStart = CS
00053 // SPI CPOL = 0
00054 // SPI CPHA = 0
00055 // SPI MOSI and MISO Data are both stable on Rising edge of SCLK
00056 // SPI SCLK Idle Low
00057 // SPI SCLKMaxMHz = 10
00058 // SPI SCLKMinMHz = 0
00059 //
00060 
00061 
00062 // Prevent multiple declaration
00063 #ifndef __MAX5171_H__
00064 #define __MAX5171_H__
00065 
00066 // standard include for target platform -- Platform_Include_Boilerplate
00067 #include "mbed.h"
00068 // Platforms:
00069 //   - MAX32625MBED
00070 //      - supports mbed-os-5.11, requires USBDevice library
00071 //      - add https://developer.mbed.org/teams/MaximIntegrated/code/USBDevice/
00072 //      - remove max32630fthr library (if present)
00073 //      - remove MAX32620FTHR library (if present)
00074 //   - MAX32600MBED
00075 //      - remove max32630fthr library (if present)
00076 //      - remove MAX32620FTHR library (if present)
00077 //      - Windows 10 note:  Don't connect HDK until you are ready to load new firmware into the board.
00078 //   - NUCLEO_F446RE
00079 //      - remove USBDevice library
00080 //      - remove max32630fthr library (if present)
00081 //      - remove MAX32620FTHR library (if present)
00082 //   - NUCLEO_F401RE
00083 //      - remove USBDevice library
00084 //      - remove max32630fthr library (if present)
00085 //      - remove MAX32620FTHR library (if present)
00086 //   - MAX32630FTHR
00087 //      - #include "max32630fthr.h"
00088 //      - add http://os.mbed.org/teams/MaximIntegrated/code/max32630fthr/
00089 //      - remove MAX32620FTHR library (if present)
00090 //   - MAX32620FTHR
00091 //      - #include "MAX32620FTHR.h"
00092 //      - remove max32630fthr library (if present)
00093 //      - add https://os.mbed.com/teams/MaximIntegrated/code/MAX32620FTHR/
00094 //      - not tested yet
00095 //   - MAX32625PICO
00096 //      - remove max32630fthr library (if present)
00097 //      - remove MAX32620FTHR library (if present)
00098 //      - not tested yet
00099 //
00100 // end Platform_Include_Boilerplate
00101 
00102 /**
00103  * @brief MAX5171 Low-Power, Serial, 14-Bit, 1-Channel DACs with Force/Sense Voltage Output and SPI Interface
00104  *
00105  *
00106  *
00107  * Datasheet: https://www.maximintegrated.com/MAX5171
00108  *
00109  *
00110  *
00111  * @code
00112  * // example code includes
00113  * // standard include for target platform -- Platform_Include_Boilerplate
00114  * #include "mbed.h"
00115  * // Platforms:
00116  * //   - MAX32625MBED
00117  * //      - supports mbed-os-5.11, requires USBDevice library
00118  * //      - add https://developer.mbed.org/teams/MaximIntegrated/code/USBDevice/
00119  * //      - remove max32630fthr library (if present)
00120  * //      - remove MAX32620FTHR library (if present)
00121  * //   - MAX32600MBED
00122  * //      - remove max32630fthr library (if present)
00123  * //      - remove MAX32620FTHR library (if present)
00124  * //      - Windows 10 note:  Don't connect HDK until you are ready to load new firmware into the board.
00125  * //   - NUCLEO_F446RE
00126  * //      - remove USBDevice library
00127  * //      - remove max32630fthr library (if present)
00128  * //      - remove MAX32620FTHR library (if present)
00129  * //   - NUCLEO_F401RE
00130  * //      - remove USBDevice library
00131  * //      - remove max32630fthr library (if present)
00132  * //      - remove MAX32620FTHR library (if present)
00133  * //   - MAX32630FTHR
00134  * //      - #include "max32630fthr.h"
00135  * //      - add http://os.mbed.org/teams/MaximIntegrated/code/max32630fthr/
00136  * //      - remove MAX32620FTHR library (if present)
00137  * //   - MAX32620FTHR
00138  * //      - #include "MAX32620FTHR.h"
00139  * //      - remove max32630fthr library (if present)
00140  * //      - add https://os.mbed.com/teams/MaximIntegrated/code/MAX32620FTHR/
00141  * //      - not tested yet
00142  * //   - MAX32625PICO
00143  * //      - remove max32630fthr library (if present)
00144  * //      - remove MAX32620FTHR library (if present)
00145  * //      - not tested yet
00146  * //
00147  * // end Platform_Include_Boilerplate
00148  * #include "MAX5171.h"
00149  *
00150  * // example code board support
00151  * //MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
00152  * //DigitalOut rLED(LED1);
00153  * //DigitalOut gLED(LED2);
00154  * //DigitalOut bLED(LED3);
00155  * //
00156  * // Arduino "shield" connector port definitions (MAX32625MBED shown)
00157  * #if defined(TARGET_MAX32625MBED)
00158  * #define A0 AIN_0
00159  * #define A1 AIN_1
00160  * #define A2 AIN_2
00161  * #define A3 AIN_3
00162  * #define D0 P0_0
00163  * #define D1 P0_1
00164  * #define D2 P0_2
00165  * #define D3 P0_3
00166  * #define D4 P0_4
00167  * #define D5 P0_5
00168  * #define D6 P0_6
00169  * #define D7 P0_7
00170  * #define D8 P1_4
00171  * #define D9 P1_5
00172  * #define D10 P1_3
00173  * #define D11 P1_1
00174  * #define D12 P1_2
00175  * #define D13 P1_0
00176  * #endif
00177  *
00178  * // example code declare SPI interface (GPIO controlled CS)
00179  * #if defined(TARGET_MAX32625MBED)
00180  * 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
00181  * DigitalOut spi_cs(SPI1_SS); // TARGET_MAX32625MBED: P1_3 Arduino 10-pin header D10
00182  * #elif defined(TARGET_MAX32600MBED)
00183  * SPI spi(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13
00184  * DigitalOut spi_cs(SPI2_SS); // Generic: Arduino 10-pin header D10
00185  * #elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F401RE)
00186  * // TODO1: avoid resource conflict between P5_0, P5_1, P5_2 SPI and DigitalInOut
00187  * // void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
00188  * //
00189  * // TODO1: NUCLEO_F446RE SPI not working; CS and MOSI data looks OK but no SCLK clock pulses.
00190  * SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); // mosi, miso, sclk spi1 TARGET_NUCLEO_F446RE: Arduino 10-pin header D11 D12 D13
00191  * DigitalOut spi_cs(SPI_CS); // TARGET_NUCLEO_F446RE: PB_6 Arduino 10-pin header D10
00192  * //
00193  * #else
00194  * SPI spi(D11, D12, D13); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13
00195  * DigitalOut spi_cs(D10); // Generic: Arduino 10-pin header D10
00196  * #endif
00197  *
00198  * // example code declare GPIO interface pins
00199  * // AnalogOut FB_pin(Px_x_PortName_To_Be_Determined); // Analog Input to MAX5171 device
00200  * DigitalOut RS_pin(D9); // Digital Configuration Input to MAX5171 device
00201  * DigitalOut PDLb_pin(D8); // Digital Configuration Input to MAX5171 device
00202  * DigitalOut CLRb_pin(D7); // Digital Configuration Input to MAX5171 device
00203  * DigitalOut SHDN_pin(D6); // Digital Configuration Input to MAX5171 device
00204  * // AnalogIn OUT_pin(A0); // Analog Output from MAX5171 device
00205  * DigitalIn UPO_pin(D5); // Digital General-Purpose Output from MAX5171 device
00206  * // example code declare device instance
00207  * MAX5171 g_MAX5171_device(spi, spi_cs, RS_pin, PDLb_pin, CLRb_pin, SHDN_pin, UPO_pin, MAX5171::MAX5171_IC);
00208  *
00209  * // example code main function
00210  * int main()
00211  * {
00212  *     g_MAX5171_device.Init();
00213  *
00214  *     while (1)
00215  *     {
00216  *         uint16_t code;
00217  *         //
00218  *         // example #1
00219  *         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)
00220  *         g_MAX5171_device.CODE_LOAD(code);
00221  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00222  *         //
00223  *         // example #2
00224  *         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)
00225  *         g_MAX5171_device.CODE_LOAD(code);
00226  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00227  *         //
00228  *         // example #3
00229  *         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)
00230  *         g_MAX5171_device.CODE_LOAD(code);
00231  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00232  *         //
00233  *         // example #4
00234  *         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)
00235  *         g_MAX5171_device.CODE_LOAD(code);
00236  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00237  *         //
00238  *         // example #5
00239  *         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)
00240  *         g_MAX5171_device.CODE_LOAD(code);
00241  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00242  *         //
00243  *         // example #6
00244  *         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)
00245  *         g_MAX5171_device.CODE_LOAD(code);
00246  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00247  *         //
00248  *         // example #7
00249  *         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)
00250  *         g_MAX5171_device.CODE_LOAD(code);
00251  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00252  *         //
00253  *         // example #8
00254  *         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)
00255  *         g_MAX5171_device.CODE_LOAD(code);
00256  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00257  *         //
00258  *         // example #9
00259  *         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)
00260  *         g_MAX5171_device.CODE_LOAD(code);
00261  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00262  *         //
00263  *         // example #10
00264  *         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)
00265  *         g_MAX5171_device.CODE_LOAD(code);
00266  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00267  *         //
00268  *         // example #11
00269  *         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)
00270  *         g_MAX5171_device.CODE_LOAD(code);
00271  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00272  *         //
00273  *         // example #12
00274  *         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)
00275  *         g_MAX5171_device.CODE_LOAD(code);
00276  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00277  *         //
00278  *         // example #13
00279  *         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)
00280  *         g_MAX5171_device.CODE_LOAD(code);
00281  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00282  *         //
00283  *         // example #14
00284  *         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)
00285  *         g_MAX5171_device.CODE_LOAD(code);
00286  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00287  *         //
00288  *         // example #15
00289  *         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)
00290  *         g_MAX5171_device.CODE_LOAD(code);
00291  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00292  *         //
00293  *         // example #16
00294  *         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)
00295  *         g_MAX5171_device.CODE_LOAD(code);
00296  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00297  *         //
00298  *         // example #17
00299  *         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)
00300  *         g_MAX5171_device.CODE_LOAD(code);
00301  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00302  *         //
00303  *         // example #18
00304  *         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)
00305  *         g_MAX5171_device.CODE_LOAD(code);
00306  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00307  *         //
00308  *         // example #19
00309  *         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)
00310  *         g_MAX5171_device.CODE_LOAD(code);
00311  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00312  *         //
00313  *         // example #20
00314  *         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)
00315  *         g_MAX5171_device.CODE_LOAD(code);
00316  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00317  *         //
00318  *         // example #21
00319  *         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)
00320  *         g_MAX5171_device.CODE_LOAD(code);
00321  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00322  *         //
00323  *         // example #22
00324  *         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)
00325  *         g_MAX5171_device.CODE_LOAD(code);
00326  *         wait_ms(3000); // wait_ms(unsigned long interval_msec)
00327  *
00328  *         // wait(3.0);
00329  *     }
00330  * }
00331  * @endcode
00332  */
00333 class MAX5171 {
00334 public:
00335     //----------------------------------------
00336     /// Command Codes (first byte)
00337     ///
00338     /// Naming convention is CMD_bitstream_FUNCTION_NAME
00339     /// - dd_dddd_dddd_dddd = data field
00340     /// - xxxx = don't care
00341     typedef enum MAX5171_CMD_enum_t {
00342         CMD_00dd_dddd_dddd_dddd_CODE = 0x0000, //!< 0b0000000000000000
00343         CMD_01dd_dddd_dddd_dddd_CODE_LOAD = 0x4000, //!< 0b0100000000000000
00344         CMD_10xx_xxxx_xxxx_xxxx_LOAD = 0x8000, //!< 0b1000000000000000
00345         CMD_1100_xxxx_xxxx_xxxx_NOP = 0xc000, //!< 0b1100000000000000
00346         CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN = 0xd000, //!< 0b1101000000000000
00347         CMD_1110_0xxx_xxxx_xxxx_UPO_LOW = 0xe000, //!< 0b1110000000000000
00348         CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH = 0xe800, //!< 0b1110100000000000
00349         CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE = 0xf000, //!< 0b1111000000000000
00350         CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE = 0xf800, //!< 0b1111100000000000
00351     } MAX5171_CMD_enum_t;
00352 
00353     /**
00354      * @brief IC's supported with this driver
00355      * @details MAX5171
00356      */
00357     typedef enum
00358     {
00359         MAX5171_IC = 0,
00360         //MAX5171_IC = 1
00361     } MAX5171_ic_t;
00362 
00363     /**********************************************************//**
00364     * @brief Constructor for MAX5171 Class.
00365     *
00366     * @details Requires an existing SPI object as well as a DigitalOut object.
00367     * The DigitalOut object is used for a chip enable signal
00368     *
00369     * On Entry:
00370     *     @param[in] spi - pointer to existing SPI object
00371     *     @param[in] cs_pin - pointer to a DigitalOut pin object
00372     *     @param[in] RS_pin - pointer to a DigitalOut pin object
00373     *     @param[in] PDLb_pin - pointer to a DigitalOut pin object
00374     *     @param[in] CLRb_pin - pointer to a DigitalOut pin object
00375     *     @param[in] SHDN_pin - pointer to a DigitalOut pin object
00376     *     @param[in] UPO_pin - pointer to a DigitalIn pin object
00377     *     @param[in] ic_variant - which type of MAX5171 is used
00378     *
00379     * On Exit:
00380     *
00381     * @return None
00382     **************************************************************/
00383     MAX5171(SPI &spi, DigitalOut &cs_pin, // SPI interface
00384             // AnalogOut &FB_pin, // Analog Input to MAX5171 device
00385             DigitalOut &RS_pin, // Digital Configuration Input to MAX5171 device
00386             DigitalOut &PDLb_pin, // Digital Configuration Input to MAX5171 device
00387             DigitalOut &CLRb_pin, // Digital Configuration Input to MAX5171 device
00388             DigitalOut &SHDN_pin, // Digital Configuration Input to MAX5171 device
00389             // AnalogIn &OUT_pin, // Analog Output from MAX5171 device
00390             DigitalIn &UPO_pin, // Digital General-Purpose Output from MAX5171 device
00391             MAX5171_ic_t ic_variant);
00392 
00393     /************************************************************
00394      * @brief Default destructor for MAX5171 Class.
00395      *
00396      * @details Destroys SPI object if owner
00397      *
00398      * On Entry:
00399      *
00400      * On Exit:
00401      *
00402      * @return None
00403      **************************************************************/
00404     ~MAX5171();
00405 
00406     /// Function pointer void f(size_t byteCount, uint8_t mosiData[], uint8_t misoData[])
00407     Callback<void(size_t, uint8_t*, uint8_t*)> onSPIprint; //!< optional @ref onSPIprint SPI diagnostic function
00408 
00409     /// set SPI SCLK frequency
00410     void spi_frequency(int spi_sclk_Hz);
00411 
00412     /// get SPI SCLK frequency
00413     int get_spi_frequency() const { return m_SPI_SCLK_Hz; }
00414 
00415     /// get SPI mode
00416     int get_spi_dataMode() const { return m_SPI_dataMode; }
00417 
00418 //----------------------------------------
00419 public:
00420 
00421     /// reference voltage, in Volts
00422     double VRef;
00423 
00424     /// shadow of dacCodeLsbs; write-only dacCodeLsbs field CMD_00dd_dddd_dddd_dddd_CODE or CMD_01dd_dddd_dddd_dddd_CODE_LOAD
00425     int16_t DACCode;
00426 
00427 
00428 //----------------------------------------
00429 // Assert SPI Chip Select
00430 // SPI chip-select for MAX5171
00431 //
00432     void SPIoutputCS(int isLogicHigh);
00433 
00434 //----------------------------------------
00435 // SPI write 16 bits
00436 // SPI interface to MAX5171 shift 16 bits mosiData into MAX5171 DIN
00437 //
00438     void SPIwrite16bits(int16_t mosiData16);
00439 
00440 private:
00441     // SPI object
00442     SPI &m_spi;
00443     int m_SPI_SCLK_Hz;
00444     int m_SPI_dataMode;
00445     int m_SPI_cs_state;
00446 
00447     // Selector pin object
00448     DigitalOut &m_cs_pin;
00449 
00450 // InputPin Name = FB
00451 // InputPin Description = Feedback Input
00452 // InputPin Function = Analog
00453 //
00454 // InputPin Name = RS
00455 // InputPin Description = Reset Mode Select (digital input). Connect to VDD to select midscale reset output value. Connect to DGND
00456 // to select 0 reset output value.
00457 // InputPin Function = Configuration
00458     DigitalOut &m_RS_pin;
00459 //
00460 // InputPin Name = PDL#
00461 // InputPin Description = Power-Down Lockout (digital input). Connect to VDD to allow shutdown. Connect to DGND to disable shutdown.
00462 // InputPin Function = Configuration
00463     DigitalOut &m_PDLb_pin;
00464 //
00465 // InputPin Name = CLR#
00466 // InputPin Description = Clear DAC (digital input). Clears the DAC to its predetermined output state as set by RS.
00467 // InputPin Function = Configuration
00468     DigitalOut &m_CLRb_pin;
00469 //
00470 // InputPin Name = SHDN
00471 // InputPin Description = Shutdown (digital input). Pulling SHDN high when PDL = VDD places the chip in shutdown mode with a
00472 // maximum shutdown current 0f 10uA.
00473 // InputPin Function = Configuration
00474     DigitalOut &m_SHDN_pin;
00475 //
00476 // OutputPin Name = OUT
00477 // OutputPin Description = Analog Voltage Output. High impedance in shutdown. Output voltage is limited to VDD.
00478 // OutputPin Function = Analog
00479     // AnalogIn &m_OUT_pin;
00480 //
00481 // OutputPin Name = UPO
00482 // OutputPin Description = User-Programmable Output. State is set by serial input.
00483 // OutputPin Function = General-Purpose
00484     DigitalIn &m_UPO_pin;
00485 //
00486 
00487     // Identifies which IC variant is being used
00488     MAX5171_ic_t m_ic_variant;
00489 
00490 public:
00491 
00492     //----------------------------------------
00493     /// Menu item '!'
00494     /// Initialize device
00495     ///
00496     /// TODO1: #170 MAX5171 Self Test for Test Fixture Firmware
00497     /// @future test group ____ // Verify function ____ (enabled by default)
00498     /// @future test
00499     ///     tinyTester.settle_time_msec = 250;
00500     ///
00501     /// @test group DACCodeOfVoltage // Verify function DACCodeOfVoltage (enabled by default)
00502     /// @test group DACCodeOfVoltage tinyTester.blink_time_msec = 20 // quickly speed through the software verification
00503     /// @test group DACCodeOfVoltage tinyTester.print("VRef = 2.500  MAX5171 14-bit LSB = 0.00015V")
00504     /// @test group DACCodeOfVoltage VRef = 2.500
00505     /// @test group DACCodeOfVoltage tinyTester.err_threshold = 0.00015259720441921504 // 14-bit LSB (2.500/16383)
00506     ///     //
00507     /// @test group DACCodeOfVoltage DACCodeOfVoltage(2.499847412109375) expect 0x3FFF
00508     /// @test group DACCodeOfVoltage DACCodeOfVoltage(2.49969482421875) expect 0x3FFE
00509     /// @test group DACCodeOfVoltage DACCodeOfVoltage(2.499542236328125) expect 0x3FFD
00510     /// @test group DACCodeOfVoltage DACCodeOfVoltage(2.4993896484375) expect 0x3FFC
00511     /// @test group DACCodeOfVoltage DACCodeOfVoltage(1.250152587890625) expect 0x2001
00512     /// @test group DACCodeOfVoltage DACCodeOfVoltage(1.25) expect 0x2000
00513     /// @test group DACCodeOfVoltage DACCodeOfVoltage(1.249847412109375) expect 0x1FFF
00514     /// @test group DACCodeOfVoltage DACCodeOfVoltage(1.24969482421875) expect 0x1FFE
00515     /// @test group DACCodeOfVoltage DACCodeOfVoltage(0.000457763671875) expect 0x0003
00516     /// @test group DACCodeOfVoltage DACCodeOfVoltage(0.00030517578125) expect 0x0002
00517     /// @test group DACCodeOfVoltage DACCodeOfVoltage(0.000152587890625) expect 0x0001
00518     /// @test group DACCodeOfVoltage DACCodeOfVoltage(0.00000) expect 0x0000
00519     /// @test group DACCodeOfVoltage tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
00520     ///     //
00521     /// @test group VoltageOfCode // Verify function VoltageOfCode (enabled by default)
00522     /// @test group VoltageOfCode tinyTester.blink_time_msec = 20 // quickly speed through the software verification
00523     /// @test group VoltageOfCode tinyTester.print("VRef = 2.500  MAX5171 14-bit LSB = 0.00015V")
00524     /// @test group VoltageOfCode VRef = 2.500
00525     /// @test group VoltageOfCode tinyTester.err_threshold = 0.00015259720441921504 // 14-bit LSB (2.500/16383)
00526     /// @test group VoltageOfCode VoltageOfCode(0x3FFF) expect 2.499847412109375
00527     /// @test group VoltageOfCode VoltageOfCode(0x3FFE) expect 2.49969482421875
00528     /// @test group VoltageOfCode VoltageOfCode(0x3FFD) expect 2.499542236328125
00529     /// @test group VoltageOfCode VoltageOfCode(0x3FFC) expect 2.4993896484375
00530     /// @test group VoltageOfCode VoltageOfCode(0x2001) expect 1.250152587890625
00531     /// @test group VoltageOfCode VoltageOfCode(0x2000) expect 1.25
00532     /// @test group VoltageOfCode VoltageOfCode(0x1FFF) expect 1.249847412109375
00533     /// @test group VoltageOfCode VoltageOfCode(0x1FFE) expect 1.24969482421875
00534     /// @test group VoltageOfCode VoltageOfCode(0x0003) expect 0.000457763671875
00535     /// @test group VoltageOfCode VoltageOfCode(0x0002) expect 0.00030517578125
00536     /// @test group VoltageOfCode VoltageOfCode(0x0001) expect 0.000152587890625
00537     /// @test group VoltageOfCode VoltageOfCode(0x0000) expect 0.00000
00538     /// @test group VoltageOfCode tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
00539     ///     //
00540     ///     // Device Testing: DAC commands, verify using on-board ADC inputs
00541     ///     //
00542     /// @test group CODE_LOAD // Verify function CODE_LOAD (enabled by default)
00543     /// @test group CODE_LOAD tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
00544     /// @test group CODE_LOAD tinyTester.settle_time_msec = 500
00545     ///     tinyTester.blink_time_msec = 75;
00546     ///     cmdLine.serial().printf("
00547     ///       MAX5171.Init()");
00548     ///     g_MAX5171_device.Init();
00549     /// @test Init()
00550     /// @test VRef expect 2.500 // Nominal Full-Scale Voltage Reference
00551     ///     //
00552     ///     tinyTester.err_threshold = 0.030; // 30mV
00553     /// @test group CODE_LOAD tinyTester.err_threshold = 0.050
00554     ///     uint16_t code = 0x3FFF;
00555     ///     //~ double voltageV = 0.5;
00556     ///     //
00557     ///     cmdLine.serial().printf("
00558     ///       MAX5171.CODE_LOAD code=%d", code);
00559     ///     g_MAX5171_device.CODE_LOAD(code);
00560     /// @test group CODE_LOAD tinyTester.print("100.0% of full scale REF(2.50V) = 2.50V Jumper FB=1-2")
00561     /// @test group CODE_LOAD CODE_LOAD(0x3FFF) // 100.0% of full scale REF(2.50V) = 2.50V
00562     ///     // tinyTester.Wait_Output_Settling replaces wait_ms
00563     ///     tinyTester.Wait_Output_Settling();
00564     /// @test group CODE_LOAD tinyTester.Wait_Output_Settling()
00565     ///     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
00566     ///     tinyTester.AnalogIn0_Read_Expect_voltageV(2.500);
00567     /// @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(2.500)
00568     ///     //
00569     ///     code = 0x0000;
00570     ///     cmdLine.serial().printf("
00571     ///       MAX5171.CODE_LOAD code=%d", code);
00572     ///     g_MAX5171_device.CODE_LOAD(code);
00573     /// @test group CODE_LOAD tinyTester.print("0.0% of full scale REF(2.50V) = 0.000V")
00574     /// @test group CODE_LOAD CODE_LOAD(0x0000) // 0.0% of full scale REF(2.50V) = 0.000V
00575     ///     // tinyTester.Wait_Output_Settling replaces wait_ms
00576     ///     tinyTester.Wait_Output_Settling();
00577     /// @test group CODE_LOAD tinyTester.Wait_Output_Settling()
00578     ///     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
00579     ///     tinyTester.AnalogIn0_Read_Expect_voltageV(0.0000);
00580     /// @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(0.0000)
00581     ///     //
00582     ///     code = 0x1FFF;
00583     ///     cmdLine.serial().printf("
00584     ///       MAX5171.CODE_LOAD code=%d", code);
00585     ///     g_MAX5171_device.CODE_LOAD(code);
00586     /// @test group CODE_LOAD tinyTester.print("50.0% of full scale REF(2.50V) = 1.25V")
00587     /// @test group CODE_LOAD CODE_LOAD(0x1FFF) // 50.0% of full scale REF(2.50V) = 1.25V
00588     ///     // tinyTester.Wait_Output_Settling replaces wait_ms
00589     ///     tinyTester.Wait_Output_Settling();
00590     /// @test group CODE_LOAD tinyTester.Wait_Output_Settling()
00591     ///     // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
00592     ///     tinyTester.AnalogIn0_Read_Expect_voltageV(1.2500);
00593     /// @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(1.2500)
00594     ///     //
00595     ///     // test UPO User Programmable Output, verify using digital input D2
00596     ///     //
00597     /// @test group UPO // Verify User Programmable Output functions UPO_HIGH and UPO_LOW (enabled by default)
00598     /// @test group UPO tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
00599     /// @test group UPO tinyTester.settle_time_msec = 500 // default 250
00600     ///     cmdLine.serial().printf("
00601     ///       MAX5171.UPO_HIGH");
00602     ///     g_MAX5171_device.UPO_HIGH();
00603     /// @test group UPO UPO_HIGH()
00604     ///     tinyTester.Wait_Output_Settling();
00605     /// @test group UPO tinyTester.Wait_Output_Settling()
00606     ///     // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
00607     ///     tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command");
00608     /// @test group CODE_LOAD tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command")
00609     ///     //
00610     ///     cmdLine.serial().printf("
00611     ///       MAX5171.UPO_LOW");
00612     ///     g_MAX5171_device.UPO_LOW();
00613     /// @test group UPO UPO_LOW()
00614     ///     tinyTester.Wait_Output_Settling();
00615     /// @test group UPO tinyTester.Wait_Output_Settling()
00616     ///     // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
00617     ///     tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 0, "UPO_pin is low after MAX5171 UPO_LOW command");
00618     /// @test group CODE_LOAD tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 0, "UPO_pin is low after MAX5171 UPO_LOW command")
00619     ///     //
00620     ///     cmdLine.serial().printf("
00621     ///       MAX5171.UPO_HIGH");
00622     ///     g_MAX5171_device.UPO_HIGH();
00623     /// @test group UPO UPO_HIGH()
00624     ///     tinyTester.Wait_Output_Settling();
00625     /// @test group UPO tinyTester.Wait_Output_Settling()
00626     ///     // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
00627     ///     tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command");
00628     /// @test group CODE_LOAD tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command")
00629     ///     //
00630     ///
00631     ///
00632     void Init(void);
00633 
00634     //----------------------------------------
00635     /// Return the DAC register value corresponding to physical voltage.
00636     /// Does not perform any offset or gain correction.
00637     ///
00638     /// @pre g_MAX5171_device.VRef = Voltage of REF input, in Volts
00639     /// @param[in] voltage = physical voltage in Volts
00640     /// @return raw 14-bit MAX5171 code (right justified).
00641     uint16_t DACCodeOfVoltage(double voltageV);
00642 
00643     //----------------------------------------
00644     /// Return the physical voltage corresponding to DAC register.
00645     /// Does not perform any offset or gain correction.
00646     ///
00647     /// @pre g_MAX5171_device.VRef = Voltage of REF input, in Volts
00648     /// @param[in] value_u14: raw 14-bit MAX5171 code (right justified).
00649     /// @return physical voltage corresponding to MAX5171 code.
00650     double VoltageOfCode(uint16_t value_u14);
00651 
00652     //----------------------------------------
00653     /// CMD_00dd_dddd_dddd_dddd_CODE
00654     ///
00655     /// Load input register; DAC registers are unchanged.
00656     /// @return 1 on success; 0 on failure
00657     uint8_t CODE(uint16_t dacCodeLsbs);
00658 
00659     //----------------------------------------
00660     /// CMD_01dd_dddd_dddd_dddd_CODE_LOAD
00661     ///
00662     /// Load input register; DAC registers are updated (start up DAC with new data).
00663     /// @return 1 on success; 0 on failure
00664     uint8_t CODE_LOAD(uint16_t dacCodeLsbs);
00665 
00666     //----------------------------------------
00667     /// CMD_10xx_xxxx_xxxx_xxxx_LOAD
00668     ///
00669     /// Update DAC register from input register (start up DAC with data previously
00670     /// stored in the input registers).
00671     /// @return 1 on success; 0 on failure
00672     uint8_t LOAD(void);
00673 
00674     //----------------------------------------
00675     /// CMD_1100_xxxx_xxxx_xxxx_NOP
00676     ///
00677     /// No operation (NOP).
00678     /// @return 1 on success; 0 on failure
00679     uint8_t NOP(void);
00680 
00681     //----------------------------------------
00682     /// CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN
00683     ///
00684     /// Shut down DAC (provided PDL# = 1).
00685     /// @return 1 on success; 0 on failure
00686     uint8_t SHUTDOWN(void);
00687 
00688     //----------------------------------------
00689     /// CMD_1110_0xxx_xxxx_xxxx_UPO_LOW
00690     ///
00691     /// UPO goes low (default).
00692     /// @return 1 on success; 0 on failure
00693     uint8_t UPO_LOW(void);
00694 
00695     //----------------------------------------
00696     /// CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH
00697     ///
00698     /// UPO goes high.
00699     /// @return 1 on success; 0 on failure
00700     uint8_t UPO_HIGH(void);
00701 
00702     //----------------------------------------
00703     /// CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE
00704     ///
00705     /// Mode 1, DOUT clocked out on SCLK's rising edge.
00706     /// @return 1 on success; 0 on failure
00707     uint8_t MODE1_DOUT_SCLK_RISING_EDGE(void);
00708 
00709     //----------------------------------------
00710     /// CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE
00711     ///
00712     /// Mode 0, DOUT clocked out on SCLK's falling edge (default).
00713     /// @return 1 on success; 0 on failure
00714     uint8_t MODE0_DOUT_SCLK_FALLING_EDGE(void);
00715 
00716 }; // end of class MAX5171
00717 
00718 #endif // __MAX5171_H__
00719 
00720 // End of file