Maxim Integrated MAX5171 14-bit Force/Sense DAC

Dependents:   MAX5171BOB_Tester MAX5171BOB_14bit_Remote_Sense_SPI_DAC MAX5171BOB_Serial_Tester

Committer:
whismanoid
Date:
Fri Jun 07 21:53:56 2019 +0000
Revision:
1:e73245718b2a
Parent:
0:80a9add62408
Child:
2:d1340b334b0d
datasheet link

Who changed what in which revision?

UserRevisionLine numberNew contents of line
whismanoid 1:e73245718b2a 1 // /*******************************************************************************
whismanoid 1:e73245718b2a 2 // * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved.
whismanoid 1:e73245718b2a 3 // *
whismanoid 1:e73245718b2a 4 // * Permission is hereby granted, free of charge, to any person obtaining a
whismanoid 1:e73245718b2a 5 // * copy of this software and associated documentation files (the "Software"),
whismanoid 1:e73245718b2a 6 // * to deal in the Software without restriction, including without limitation
whismanoid 1:e73245718b2a 7 // * the rights to use, copy, modify, merge, publish, distribute, sublicense,
whismanoid 1:e73245718b2a 8 // * and/or sell copies of the Software, and to permit persons to whom the
whismanoid 1:e73245718b2a 9 // * Software is furnished to do so, subject to the following conditions:
whismanoid 1:e73245718b2a 10 // *
whismanoid 1:e73245718b2a 11 // * The above copyright notice and this permission notice shall be included
whismanoid 1:e73245718b2a 12 // * in all copies or substantial portions of the Software.
whismanoid 1:e73245718b2a 13 // *
whismanoid 1:e73245718b2a 14 // * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
whismanoid 1:e73245718b2a 15 // * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
whismanoid 1:e73245718b2a 16 // * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
whismanoid 1:e73245718b2a 17 // * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
whismanoid 1:e73245718b2a 18 // * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
whismanoid 1:e73245718b2a 19 // * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
whismanoid 1:e73245718b2a 20 // * OTHER DEALINGS IN THE SOFTWARE.
whismanoid 1:e73245718b2a 21 // *
whismanoid 1:e73245718b2a 22 // * Except as contained in this notice, the name of Maxim Integrated
whismanoid 1:e73245718b2a 23 // * Products, Inc. shall not be used except as stated in the Maxim Integrated
whismanoid 1:e73245718b2a 24 // * Products, Inc. Branding Policy.
whismanoid 1:e73245718b2a 25 // *
whismanoid 1:e73245718b2a 26 // * The mere transfer of this software does not imply any licenses
whismanoid 1:e73245718b2a 27 // * of trade secrets, proprietary technology, copyrights, patents,
whismanoid 1:e73245718b2a 28 // * trademarks, maskwork rights, or any other form of intellectual
whismanoid 1:e73245718b2a 29 // * property whatsoever. Maxim Integrated Products, Inc. retains all
whismanoid 1:e73245718b2a 30 // * ownership rights.
whismanoid 1:e73245718b2a 31 // *******************************************************************************
whismanoid 1:e73245718b2a 32 // */
whismanoid 1:e73245718b2a 33 // *********************************************************************
whismanoid 1:e73245718b2a 34 // @file MAX5171.h
whismanoid 1:e73245718b2a 35 // *********************************************************************
whismanoid 1:e73245718b2a 36 // Header file
whismanoid 1:e73245718b2a 37 // DO NOT EDIT; except areas designated "CUSTOMIZE". Automatically generated file.
whismanoid 1:e73245718b2a 38 // generated by XMLSystemOfDevicesToMBED.py
whismanoid 1:e73245718b2a 39 // System Name = ExampleSystem
whismanoid 1:e73245718b2a 40 // System Description = Device driver example
whismanoid 1:e73245718b2a 41 // Device Name = MAX5171
whismanoid 1:e73245718b2a 42 // Device Description = Low-Power, Serial, 14-Bit, 1-Channel DACs with Force/Sense Voltage Output and SPI Interface
whismanoid 1:e73245718b2a 43 // Device Manufacturer = Maxim Integrated
whismanoid 1:e73245718b2a 44 // Device PartNumber = MAX5171AEEE+
whismanoid 1:e73245718b2a 45 // Device RegValue_Width = DataWidth16bit_HL
whismanoid 1:e73245718b2a 46 //
whismanoid 1:e73245718b2a 47 // DAC NumChannels = 1
whismanoid 1:e73245718b2a 48 // DAC ResolutionBits = 14
whismanoid 1:e73245718b2a 49 //
whismanoid 1:e73245718b2a 50 // SPI CS = ActiveLow
whismanoid 1:e73245718b2a 51 // SPI FrameStart = CS
whismanoid 1:e73245718b2a 52 // SPI CPOL = 0
whismanoid 1:e73245718b2a 53 // SPI CPHA = 0
whismanoid 1:e73245718b2a 54 // SPI MOSI and MISO Data are both stable on Rising edge of SCLK
whismanoid 1:e73245718b2a 55 // SPI SCLK Idle Low
whismanoid 1:e73245718b2a 56 // SPI SCLKMaxMHz = 10
whismanoid 1:e73245718b2a 57 // SPI SCLKMinMHz = 0
whismanoid 1:e73245718b2a 58 //
whismanoid 1:e73245718b2a 59
whismanoid 1:e73245718b2a 60
whismanoid 1:e73245718b2a 61 // Prevent multiple declaration
whismanoid 1:e73245718b2a 62 #ifndef __MAX5171_H__
whismanoid 1:e73245718b2a 63 #define __MAX5171_H__
whismanoid 1:e73245718b2a 64
whismanoid 1:e73245718b2a 65 #include "mbed.h"
whismanoid 1:e73245718b2a 66
whismanoid 1:e73245718b2a 67 // CODE GENERATOR: conditional defines
whismanoid 1:e73245718b2a 68 // CODE GENERATOR: class declaration and docstrings
whismanoid 1:e73245718b2a 69 /**
whismanoid 1:e73245718b2a 70 * @brief MAX5171 Low-Power, Serial, 14-Bit, 1-Channel DACs with Force/Sense Voltage Output and SPI Interface
whismanoid 1:e73245718b2a 71 *
whismanoid 1:e73245718b2a 72 *
whismanoid 1:e73245718b2a 73 *
whismanoid 1:e73245718b2a 74 * Datasheet: https://www.maximintegrated.com/MAX5171
whismanoid 1:e73245718b2a 75 *
whismanoid 1:e73245718b2a 76 *
whismanoid 1:e73245718b2a 77 *
whismanoid 1:e73245718b2a 78 * //---------- CODE GENERATOR: testMainCppCodeList
whismanoid 1:e73245718b2a 79 * @code
whismanoid 1:e73245718b2a 80 * // CODE GENERATOR: example code includes
whismanoid 1:e73245718b2a 81 * // example code includes
whismanoid 1:e73245718b2a 82 * #include "mbed.h"
whismanoid 1:e73245718b2a 83 * //#include "max32625.h"
whismanoid 1:e73245718b2a 84 * #include "MAX5171.h"
whismanoid 1:e73245718b2a 85 *
whismanoid 1:e73245718b2a 86 * // optional: serial port
whismanoid 1:e73245718b2a 87 * // note: some platforms such as Nucleo-F446RE do not support the USBSerial library.
whismanoid 1:e73245718b2a 88 * // In those cases, remove the USBDevice lib from the project and rebuild.
whismanoid 1:e73245718b2a 89 * #if defined(TARGET_MAX32625MBED)
whismanoid 1:e73245718b2a 90 * #include "USBSerial.h"
whismanoid 1:e73245718b2a 91 * USBSerial serial; // virtual serial port over USB (DEV connector)
whismanoid 1:e73245718b2a 92 * #elif defined(TARGET_MAX32630MBED)
whismanoid 1:e73245718b2a 93 * #include "USBSerial.h"
whismanoid 1:e73245718b2a 94 * USBSerial serial; // virtual serial port over USB (DEV connector)
whismanoid 1:e73245718b2a 95 * #else
whismanoid 1:e73245718b2a 96 * //#include "USBSerial.h"
whismanoid 1:e73245718b2a 97 * Serial serial(USBTX, USBRX); // tx, rx
whismanoid 1:e73245718b2a 98 * #endif
whismanoid 1:e73245718b2a 99 *
whismanoid 1:e73245718b2a 100 * // example code board support
whismanoid 1:e73245718b2a 101 * //MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
whismanoid 1:e73245718b2a 102 * //DigitalOut rLED(LED1);
whismanoid 1:e73245718b2a 103 * //DigitalOut gLED(LED2);
whismanoid 1:e73245718b2a 104 * //DigitalOut bLED(LED3);
whismanoid 1:e73245718b2a 105 * //
whismanoid 1:e73245718b2a 106 * // Arduino "shield" connector port definitions (MAX32625MBED shown)
whismanoid 1:e73245718b2a 107 * #if defined(TARGET_MAX32625MBED)
whismanoid 1:e73245718b2a 108 * #define A0 AIN_0
whismanoid 1:e73245718b2a 109 * #define A1 AIN_1
whismanoid 1:e73245718b2a 110 * #define A2 AIN_2
whismanoid 1:e73245718b2a 111 * #define A3 AIN_3
whismanoid 1:e73245718b2a 112 * #define D0 P0_0
whismanoid 1:e73245718b2a 113 * #define D1 P0_1
whismanoid 1:e73245718b2a 114 * #define D2 P0_2
whismanoid 1:e73245718b2a 115 * #define D3 P0_3
whismanoid 1:e73245718b2a 116 * #define D4 P0_4
whismanoid 1:e73245718b2a 117 * #define D5 P0_5
whismanoid 1:e73245718b2a 118 * #define D6 P0_6
whismanoid 1:e73245718b2a 119 * #define D7 P0_7
whismanoid 1:e73245718b2a 120 * #define D8 P1_4
whismanoid 1:e73245718b2a 121 * #define D9 P1_5
whismanoid 1:e73245718b2a 122 * #define D10 P1_3
whismanoid 1:e73245718b2a 123 * #define D11 P1_1
whismanoid 1:e73245718b2a 124 * #define D12 P1_2
whismanoid 1:e73245718b2a 125 * #define D13 P1_0
whismanoid 1:e73245718b2a 126 * #endif
whismanoid 1:e73245718b2a 127 *
whismanoid 1:e73245718b2a 128 * // example code declare SPI interface
whismanoid 1:e73245718b2a 129 * #if defined(TARGET_MAX32625MBED)
whismanoid 1:e73245718b2a 130 * SPI spi(SPI1_MOSI, SPI1_MISO, SPI1_SCK); // mosi, miso, sclk spi1 TARGET_MAX32625MBED: P1_1 P1_2 P1_0 Arduino 10-pin header D11 D12 D13
whismanoid 1:e73245718b2a 131 * DigitalOut spi_cs(SPI1_SS); // TARGET_MAX32625MBED: P1_3 Arduino 10-pin header D10
whismanoid 1:e73245718b2a 132 * #elif defined(TARGET_MAX32600MBED)
whismanoid 1:e73245718b2a 133 * SPI spi(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13
whismanoid 1:e73245718b2a 134 * DigitalOut spi_cs(SPI2_SS); // Generic: Arduino 10-pin header D10
whismanoid 1:e73245718b2a 135 * #else
whismanoid 1:e73245718b2a 136 * SPI spi(D11, D12, D13); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13
whismanoid 1:e73245718b2a 137 * DigitalOut spi_cs(D10); // Generic: Arduino 10-pin header D10
whismanoid 1:e73245718b2a 138 * #endif
whismanoid 1:e73245718b2a 139 *
whismanoid 1:e73245718b2a 140 * // example code declare GPIO interface pins
whismanoid 1:e73245718b2a 141 * // AnalogOut FB_pin(Px_x_PortName_To_Be_Determined); // Analog Input to MAX5171 device
whismanoid 1:e73245718b2a 142 * DigitalOut RS_pin(D9); // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 143 * DigitalOut PDLb_pin(D8); // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 144 * DigitalOut CLRb_pin(D7); // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 145 * DigitalOut SHDN_pin(D6); // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 146 * // AnalogIn OUT_pin(A0); // Analog Output from MAX5171 device
whismanoid 1:e73245718b2a 147 * DigitalIn UPO_pin(D5); // Digital General-Purpose Output from MAX5171 device
whismanoid 1:e73245718b2a 148 * // example code declare device instance
whismanoid 1:e73245718b2a 149 * MAX5171 g_MAX5171_device(spi, spi_cs, RS_pin, PDLb_pin, CLRb_pin, SHDN_pin, UPO_pin, MAX5171::MAX5171_IC);
whismanoid 1:e73245718b2a 150 *
whismanoid 1:e73245718b2a 151 * // example code main function
whismanoid 1:e73245718b2a 152 * int main()
whismanoid 1:e73245718b2a 153 * {
whismanoid 1:e73245718b2a 154 * while (1)
whismanoid 1:e73245718b2a 155 * {
whismanoid 1:e73245718b2a 156 * // example code: serial port banner message
whismanoid 1:e73245718b2a 157 * #if defined(TARGET_MAX32625MBED)
whismanoid 1:e73245718b2a 158 * serial.printf("MAX32625MBED ");
whismanoid 1:e73245718b2a 159 * #elif defined(TARGET_MAX32600MBED)
whismanoid 1:e73245718b2a 160 * serial.printf("MAX32600MBED ");
whismanoid 1:e73245718b2a 161 * #elif defined(TARGET_NUCLEO_F446RE)
whismanoid 1:e73245718b2a 162 * serial.printf("NUCLEO_F446RE ");
whismanoid 1:e73245718b2a 163 * #endif
whismanoid 1:e73245718b2a 164 * serial.printf("MAX5715BOB\r\n");
whismanoid 1:e73245718b2a 165 *
whismanoid 1:e73245718b2a 166 * //MAX5171 dac(spi, spi_cs, MAX5171::MAX5171_IC);
whismanoid 1:e73245718b2a 167 * //dac.Init();
whismanoid 1:e73245718b2a 168 *
whismanoid 1:e73245718b2a 169 * // CODE GENERATOR: example code: member function Init
whismanoid 1:e73245718b2a 170 * g_MAX5171_device.Init();
whismanoid 1:e73245718b2a 171 *
whismanoid 1:e73245718b2a 172 * // CODE GENERATOR: example code: has no member function REF
whismanoid 1:e73245718b2a 173 * // CODE GENERATOR: example code: member function CODE_LOAD
whismanoid 1:e73245718b2a 174 * //
whismanoid 1:e73245718b2a 175 * uint16_t code = 0xccc;
whismanoid 1:e73245718b2a 176 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 1:e73245718b2a 177 * //
whismanoid 1:e73245718b2a 178 * code = 0x800;
whismanoid 1:e73245718b2a 179 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 1:e73245718b2a 180 * //
whismanoid 1:e73245718b2a 181 * code = 0x666;
whismanoid 1:e73245718b2a 182 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 1:e73245718b2a 183 * //
whismanoid 1:e73245718b2a 184 * code = 0xFFF;
whismanoid 1:e73245718b2a 185 * g_MAX5171_device.CODE_LOAD(code);
whismanoid 1:e73245718b2a 186 *
whismanoid 1:e73245718b2a 187 * // CODE GENERATOR: example code: has no member function CODEallLOADall
whismanoid 1:e73245718b2a 188 * // CODE GENERATOR: example code: has no member function CODEnLOADn
whismanoid 1:e73245718b2a 189 * // CODE GENERATOR: example code: has no member function ScanManual
whismanoid 1:e73245718b2a 190 * // CODE GENERATOR: example code: has no member function ReadAINcode
whismanoid 1:e73245718b2a 191 * wait(3.0);
whismanoid 1:e73245718b2a 192 * }
whismanoid 1:e73245718b2a 193 * }
whismanoid 1:e73245718b2a 194 * @endcode
whismanoid 1:e73245718b2a 195 * //---------- CODE GENERATOR: end testMainCppCodeList
whismanoid 1:e73245718b2a 196 */
whismanoid 1:e73245718b2a 197 class MAX5171
whismanoid 1:e73245718b2a 198 {
whismanoid 1:e73245718b2a 199 public:
whismanoid 1:e73245718b2a 200 // CODE GENERATOR: TypedefEnum EnumItem declarations
whismanoid 1:e73245718b2a 201 // CODE GENERATOR: TypedefEnum MAX5171_CMD_enum_t
whismanoid 1:e73245718b2a 202 //----------------------------------------
whismanoid 1:e73245718b2a 203 /// Command Codes (first byte)
whismanoid 1:e73245718b2a 204 ///
whismanoid 1:e73245718b2a 205 /// Naming convention is CMD_bitstream_FUNCTION_NAME
whismanoid 1:e73245718b2a 206 /// - dd_dddd_dddd_dddd = data field
whismanoid 1:e73245718b2a 207 /// - xxxx = don't care
whismanoid 1:e73245718b2a 208 typedef enum MAX5171_CMD_enum_t {
whismanoid 1:e73245718b2a 209 CMD_00dd_dddd_dddd_dddd_CODE = 0x0000, //!< 16'b0000000000000000
whismanoid 1:e73245718b2a 210 CMD_01dd_dddd_dddd_dddd_CODE_LOAD = 0x4000, //!< 16'b0100000000000000
whismanoid 1:e73245718b2a 211 CMD_10xx_xxxx_xxxx_xxxx_LOAD = 0x8000, //!< 16'b1000000000000000
whismanoid 1:e73245718b2a 212 CMD_1100_xxxx_xxxx_xxxx_NOP = 0xc000, //!< 16'b1100000000000000
whismanoid 1:e73245718b2a 213 CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN = 0xd000, //!< 16'b1101000000000000
whismanoid 1:e73245718b2a 214 CMD_1110_0xxx_xxxx_xxxx_UPO_LOW = 0xe000, //!< 16'b1110000000000000
whismanoid 1:e73245718b2a 215 CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH = 0xe800, //!< 16'b1110100000000000
whismanoid 1:e73245718b2a 216 CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE = 0xf000, //!< 16'b1111000000000000
whismanoid 1:e73245718b2a 217 CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE = 0xf800, //!< 16'b1111100000000000
whismanoid 1:e73245718b2a 218 } MAX5171_CMD_enum_t;
whismanoid 1:e73245718b2a 219
whismanoid 1:e73245718b2a 220 // TODO1: CODE GENERATOR: ic_variant -- IC's supported with this driver
whismanoid 1:e73245718b2a 221 /**
whismanoid 1:e73245718b2a 222 * @brief IC's supported with this driver
whismanoid 1:e73245718b2a 223 * @details MAX5171
whismanoid 1:e73245718b2a 224 */
whismanoid 1:e73245718b2a 225 typedef enum {
whismanoid 1:e73245718b2a 226 MAX5171_IC = 0,
whismanoid 1:e73245718b2a 227 //MAX5171_IC = 1
whismanoid 1:e73245718b2a 228 } MAX5171_ic_t;
whismanoid 0:80a9add62408 229
whismanoid 1:e73245718b2a 230 // TODO1: CODE GENERATOR: class constructor declaration
whismanoid 1:e73245718b2a 231 /**********************************************************//**
whismanoid 1:e73245718b2a 232 * @brief Constructor for MAX5171 Class.
whismanoid 1:e73245718b2a 233 *
whismanoid 1:e73245718b2a 234 * @details Requires an existing SPI object as well as a DigitalOut object.
whismanoid 1:e73245718b2a 235 * The DigitalOut object is used for a chip enable signal
whismanoid 1:e73245718b2a 236 *
whismanoid 1:e73245718b2a 237 * On Entry:
whismanoid 1:e73245718b2a 238 * @param[in] spi - pointer to existing SPI object
whismanoid 1:e73245718b2a 239 * @param[in] cs_pin - pointer to a DigitalOut pin object
whismanoid 1:e73245718b2a 240 * CODE GENERATOR: class constructor docstrings gpio InputPin pins
whismanoid 1:e73245718b2a 241 * @param[in] RS_pin - pointer to a DigitalOut pin object
whismanoid 1:e73245718b2a 242 * @param[in] PDLb_pin - pointer to a DigitalOut pin object
whismanoid 1:e73245718b2a 243 * @param[in] CLRb_pin - pointer to a DigitalOut pin object
whismanoid 1:e73245718b2a 244 * @param[in] SHDN_pin - pointer to a DigitalOut pin object
whismanoid 1:e73245718b2a 245 * CODE GENERATOR: class constructor docstrings gpio OutputPin pins
whismanoid 1:e73245718b2a 246 * @param[in] UPO_pin - pointer to a DigitalIn pin object
whismanoid 1:e73245718b2a 247 * @param[in] ic_variant - which type of MAX5171 is used
whismanoid 1:e73245718b2a 248 *
whismanoid 1:e73245718b2a 249 * On Exit:
whismanoid 1:e73245718b2a 250 *
whismanoid 1:e73245718b2a 251 * @return None
whismanoid 1:e73245718b2a 252 **************************************************************/
whismanoid 1:e73245718b2a 253 MAX5171(SPI &spi, DigitalOut &cs_pin, // SPI interface
whismanoid 1:e73245718b2a 254 // CODE GENERATOR: class constructor declaration gpio InputPin pins
whismanoid 1:e73245718b2a 255 // AnalogOut &FB_pin, // Analog Input to MAX5171 device
whismanoid 1:e73245718b2a 256 DigitalOut &RS_pin, // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 257 DigitalOut &PDLb_pin, // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 258 DigitalOut &CLRb_pin, // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 259 DigitalOut &SHDN_pin, // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 260 // CODE GENERATOR: class constructor declaration gpio OutputPin pins
whismanoid 1:e73245718b2a 261 // AnalogIn &OUT_pin, // Analog Output from MAX5171 device
whismanoid 1:e73245718b2a 262 DigitalIn &UPO_pin, // Digital General-Purpose Output from MAX5171 device
whismanoid 1:e73245718b2a 263 MAX5171_ic_t ic_variant);
whismanoid 1:e73245718b2a 264
whismanoid 1:e73245718b2a 265 // CODE GENERATOR: class destructor declaration
whismanoid 1:e73245718b2a 266 /************************************************************
whismanoid 1:e73245718b2a 267 * @brief Default destructor for MAX5171 Class.
whismanoid 1:e73245718b2a 268 *
whismanoid 1:e73245718b2a 269 * @details Destroys SPI object if owner
whismanoid 1:e73245718b2a 270 *
whismanoid 1:e73245718b2a 271 * On Entry:
whismanoid 1:e73245718b2a 272 *
whismanoid 1:e73245718b2a 273 * On Exit:
whismanoid 1:e73245718b2a 274 *
whismanoid 1:e73245718b2a 275 * @return None
whismanoid 1:e73245718b2a 276 **************************************************************/
whismanoid 1:e73245718b2a 277 ~MAX5171();
whismanoid 1:e73245718b2a 278
whismanoid 1:e73245718b2a 279 // CODE GENERATOR: spi_frequency setter declaration
whismanoid 1:e73245718b2a 280 // set SPI SCLK frequency
whismanoid 1:e73245718b2a 281 void spi_frequency(int spi_sclk_Hz);
whismanoid 1:e73245718b2a 282
whismanoid 1:e73245718b2a 283 //----------------------------------------
whismanoid 1:e73245718b2a 284 // CODE GENERATOR: omit typedef enum MAX5171_device_t, class members instead of global device object
whismanoid 1:e73245718b2a 285 public:
whismanoid 1:e73245718b2a 286
whismanoid 1:e73245718b2a 287 /// reference voltage, in Volts
whismanoid 1:e73245718b2a 288 double VRef;
whismanoid 1:e73245718b2a 289
whismanoid 1:e73245718b2a 290 /// shadow of write-only dacCodeLsbs field CMD_00dd_dddd_dddd_dddd_CODE or CMD_01dd_dddd_dddd_dddd_CODE_LOAD
whismanoid 1:e73245718b2a 291 int16_t DACCode;
whismanoid 1:e73245718b2a 292
whismanoid 1:e73245718b2a 293 // CODE GENERATOR: omit global g_MAX5171_device
whismanoid 1:e73245718b2a 294
whismanoid 1:e73245718b2a 295 // CODE GENERATOR: extern function declarations
whismanoid 1:e73245718b2a 296 // CODE GENERATOR: extern function declaration SPIoutputCS
whismanoid 1:e73245718b2a 297 //----------------------------------------
whismanoid 1:e73245718b2a 298 // Assert SPI Chip Select
whismanoid 1:e73245718b2a 299 // SPI chip-select for MAX5171
whismanoid 1:e73245718b2a 300 //
whismanoid 1:e73245718b2a 301 void SPIoutputCS(int isLogicHigh);
whismanoid 1:e73245718b2a 302
whismanoid 1:e73245718b2a 303 // CODE GENERATOR: extern function declaration SPIwrite16bits
whismanoid 1:e73245718b2a 304 //----------------------------------------
whismanoid 1:e73245718b2a 305 // SPI write 16 bits
whismanoid 1:e73245718b2a 306 // SPI interface to MAX5171 shift 16 bits mosiData into MAX5171 DIN
whismanoid 1:e73245718b2a 307 //
whismanoid 1:e73245718b2a 308 void SPIwrite16bits(int16_t mosiData16);
whismanoid 1:e73245718b2a 309
whismanoid 1:e73245718b2a 310 // CODE GENERATOR: class member data
whismanoid 1:e73245718b2a 311 private:
whismanoid 1:e73245718b2a 312 // CODE GENERATOR: class member data for SPI interface
whismanoid 1:e73245718b2a 313 // SPI object
whismanoid 1:e73245718b2a 314 SPI &m_spi;
whismanoid 1:e73245718b2a 315 int m_SPI_SCLK_Hz;
whismanoid 1:e73245718b2a 316 int m_SPI_dataMode;
whismanoid 1:e73245718b2a 317 int m_SPI_cs_state;
whismanoid 1:e73245718b2a 318
whismanoid 1:e73245718b2a 319 // Selector pin object
whismanoid 1:e73245718b2a 320 DigitalOut &m_cs_pin;
whismanoid 1:e73245718b2a 321
whismanoid 1:e73245718b2a 322 // CODE GENERATOR: class member data for gpio InputPin pins
whismanoid 1:e73245718b2a 323 // InputPin Name = FB
whismanoid 1:e73245718b2a 324 // InputPin Description = Feedback Input
whismanoid 1:e73245718b2a 325 // InputPin Function = Analog
whismanoid 1:e73245718b2a 326 //
whismanoid 1:e73245718b2a 327 // InputPin Name = RS
whismanoid 1:e73245718b2a 328 // InputPin Description = Reset Mode Select (digital input). Connect to VDD to select midscale reset output value. Connect to DGND
whismanoid 1:e73245718b2a 329 // to select 0 reset output value.
whismanoid 1:e73245718b2a 330 // InputPin Function = Configuration
whismanoid 1:e73245718b2a 331 DigitalOut &m_RS_pin;
whismanoid 1:e73245718b2a 332 //
whismanoid 1:e73245718b2a 333 // InputPin Name = PDL#
whismanoid 1:e73245718b2a 334 // InputPin Description = Power-Down Lockout (digital input). Connect to VDD to allow shutdown. Connect to DGND to disable shutdown.
whismanoid 1:e73245718b2a 335 // InputPin Function = Configuration
whismanoid 1:e73245718b2a 336 DigitalOut &m_PDLb_pin;
whismanoid 1:e73245718b2a 337 //
whismanoid 1:e73245718b2a 338 // InputPin Name = CLR#
whismanoid 1:e73245718b2a 339 // InputPin Description = Clear DAC (digital input). Clears the DAC to its predetermined output state as set by RS.
whismanoid 1:e73245718b2a 340 // InputPin Function = Configuration
whismanoid 1:e73245718b2a 341 DigitalOut &m_CLRb_pin;
whismanoid 1:e73245718b2a 342 //
whismanoid 1:e73245718b2a 343 // InputPin Name = SHDN
whismanoid 1:e73245718b2a 344 // InputPin Description = Shutdown (digital input). Pulling SHDN high when PDL = VDD places the chip in shutdown mode with a
whismanoid 1:e73245718b2a 345 // maximum shutdown current 0f 10uA.
whismanoid 1:e73245718b2a 346 // InputPin Function = Configuration
whismanoid 1:e73245718b2a 347 DigitalOut &m_SHDN_pin;
whismanoid 1:e73245718b2a 348 //
whismanoid 1:e73245718b2a 349 // CODE GENERATOR: class member data for gpio OutputPin pins
whismanoid 1:e73245718b2a 350 // OutputPin Name = OUT
whismanoid 1:e73245718b2a 351 // OutputPin Description = Analog Voltage Output. High impedance in shutdown. Output voltage is limited to VDD.
whismanoid 1:e73245718b2a 352 // OutputPin Function = Analog
whismanoid 1:e73245718b2a 353 // AnalogIn &m_OUT_pin;
whismanoid 1:e73245718b2a 354 //
whismanoid 1:e73245718b2a 355 // OutputPin Name = UPO
whismanoid 1:e73245718b2a 356 // OutputPin Description = User-Programmable Output. State is set by serial input.
whismanoid 1:e73245718b2a 357 // OutputPin Function = General-Purpose
whismanoid 1:e73245718b2a 358 DigitalIn &m_UPO_pin;
whismanoid 1:e73245718b2a 359 //
whismanoid 1:e73245718b2a 360
whismanoid 1:e73245718b2a 361 // Identifies which IC variant is being used
whismanoid 1:e73245718b2a 362 MAX5171_ic_t m_ic_variant;
whismanoid 1:e73245718b2a 363
whismanoid 1:e73245718b2a 364 public:
whismanoid 1:e73245718b2a 365
whismanoid 1:e73245718b2a 366 // CODE GENERATOR: class member function declarations
whismanoid 1:e73245718b2a 367 //----------------------------------------
whismanoid 1:e73245718b2a 368 /// Initialize device
whismanoid 1:e73245718b2a 369 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 370 uint8_t Init(void);
whismanoid 1:e73245718b2a 371
whismanoid 1:e73245718b2a 372 //----------------------------------------
whismanoid 1:e73245718b2a 373 /// Return the DAC register value corresponding to physical voltage.
whismanoid 1:e73245718b2a 374 /// Does not perform any offset or gain correction.
whismanoid 1:e73245718b2a 375 ///
whismanoid 1:e73245718b2a 376 /// @pre g_MAX5171_device.VRef = Voltage of REF input, in Volts
whismanoid 1:e73245718b2a 377 /// @param[in] voltage = physical voltage in Volts
whismanoid 1:e73245718b2a 378 /// @return raw 14-bit MAX5171 code (right justified).
whismanoid 1:e73245718b2a 379 uint16_t DACCodeOfVoltage(double voltageV);
whismanoid 1:e73245718b2a 380
whismanoid 1:e73245718b2a 381 //----------------------------------------
whismanoid 1:e73245718b2a 382 /// Return the physical voltage corresponding to DAC register.
whismanoid 1:e73245718b2a 383 /// Does not perform any offset or gain correction.
whismanoid 1:e73245718b2a 384 ///
whismanoid 1:e73245718b2a 385 /// @pre g_MAX5171_device.VRef = Voltage of REF input, in Volts
whismanoid 1:e73245718b2a 386 /// @param[in] value_u14: raw 14-bit MAX5171 code (right justified).
whismanoid 1:e73245718b2a 387 /// @return physical voltage corresponding to MAX5171 code.
whismanoid 1:e73245718b2a 388 double VoltageOfCode(uint16_t value_u14);
whismanoid 1:e73245718b2a 389
whismanoid 1:e73245718b2a 390 //----------------------------------------
whismanoid 1:e73245718b2a 391 /// CMD_00dd_dddd_dddd_dddd_CODE
whismanoid 1:e73245718b2a 392 ///
whismanoid 1:e73245718b2a 393 /// Load input register; DAC registers are unchanged.
whismanoid 1:e73245718b2a 394 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 395 uint8_t CODE(uint16_t dacCodeLsbs);
whismanoid 1:e73245718b2a 396
whismanoid 1:e73245718b2a 397 //----------------------------------------
whismanoid 1:e73245718b2a 398 /// CMD_01dd_dddd_dddd_dddd_CODE_LOAD
whismanoid 1:e73245718b2a 399 ///
whismanoid 1:e73245718b2a 400 /// Load input register; DAC registers are updated (start up DAC with new data).
whismanoid 1:e73245718b2a 401 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 402 uint8_t CODE_LOAD(uint16_t dacCodeLsbs);
whismanoid 1:e73245718b2a 403
whismanoid 1:e73245718b2a 404 //----------------------------------------
whismanoid 1:e73245718b2a 405 /// CMD_10xx_xxxx_xxxx_xxxx_LOAD
whismanoid 1:e73245718b2a 406 ///
whismanoid 1:e73245718b2a 407 /// Update DAC register from input register (start up DAC with data previously
whismanoid 1:e73245718b2a 408 /// stored in the input registers).
whismanoid 1:e73245718b2a 409 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 410 uint8_t LOAD(void);
whismanoid 1:e73245718b2a 411
whismanoid 1:e73245718b2a 412 //----------------------------------------
whismanoid 1:e73245718b2a 413 /// CMD_1100_xxxx_xxxx_xxxx_NOP
whismanoid 1:e73245718b2a 414 ///
whismanoid 1:e73245718b2a 415 /// No operation (NOP).
whismanoid 1:e73245718b2a 416 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 417 uint8_t NOP(void);
whismanoid 1:e73245718b2a 418
whismanoid 1:e73245718b2a 419 //----------------------------------------
whismanoid 1:e73245718b2a 420 /// CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN
whismanoid 1:e73245718b2a 421 ///
whismanoid 1:e73245718b2a 422 /// Shut down DAC (provided PDL# = 1).
whismanoid 1:e73245718b2a 423 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 424 uint8_t SHUTDOWN(void);
whismanoid 1:e73245718b2a 425
whismanoid 1:e73245718b2a 426 //----------------------------------------
whismanoid 1:e73245718b2a 427 /// CMD_1110_0xxx_xxxx_xxxx_UPO_LOW
whismanoid 1:e73245718b2a 428 ///
whismanoid 1:e73245718b2a 429 /// UPO goes low (default).
whismanoid 1:e73245718b2a 430 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 431 uint8_t UPO_LOW(void);
whismanoid 1:e73245718b2a 432
whismanoid 1:e73245718b2a 433 //----------------------------------------
whismanoid 1:e73245718b2a 434 /// CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH
whismanoid 1:e73245718b2a 435 ///
whismanoid 1:e73245718b2a 436 /// UPO goes high.
whismanoid 1:e73245718b2a 437 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 438 uint8_t UPO_HIGH(void);
whismanoid 1:e73245718b2a 439
whismanoid 1:e73245718b2a 440 //----------------------------------------
whismanoid 1:e73245718b2a 441 /// CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE
whismanoid 1:e73245718b2a 442 ///
whismanoid 1:e73245718b2a 443 /// Mode 1, DOUT clocked out on SCLK’s rising edge.
whismanoid 1:e73245718b2a 444 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 445 uint8_t MODE1_DOUT_SCLK_RISING_EDGE(void);
whismanoid 1:e73245718b2a 446
whismanoid 1:e73245718b2a 447 //----------------------------------------
whismanoid 1:e73245718b2a 448 /// CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE
whismanoid 1:e73245718b2a 449 ///
whismanoid 1:e73245718b2a 450 /// Mode 0, DOUT clocked out on SCLK’s falling edge (default).
whismanoid 1:e73245718b2a 451 /// @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 452 uint8_t MODE0_DOUT_SCLK_FALLING_EDGE(void);
whismanoid 1:e73245718b2a 453
whismanoid 1:e73245718b2a 454 }; // end of class MAX5171
whismanoid 1:e73245718b2a 455
whismanoid 1:e73245718b2a 456 #endif // __MAX5171_H__
whismanoid 1:e73245718b2a 457
whismanoid 1:e73245718b2a 458 // End of file