Maxim Integrated 16-Bit, Unbuffered Output Voltage DAC. Driver/library for MAX541

Dependents:   MAX541_Hello_DAC_on_MAX32625MBED MAX5715BOB_Tester MAX11131BOB_Tester MAX5171BOB_Tester ... more

Committer:
whismanoid
Date:
Thu May 09 06:19:44 2019 +0000
Revision:
2:609e1e5c4d51
Parent:
1:3908aba2ea77
Child:
3:016c812266e7
MAX541 class documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
whismanoid 0:4847beac14e9 1 /*******************************************************************************
whismanoid 0:4847beac14e9 2 * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved.
whismanoid 0:4847beac14e9 3 *
whismanoid 0:4847beac14e9 4 * Permission is hereby granted, free of charge, to any person obtaining a
whismanoid 0:4847beac14e9 5 * copy of this software and associated documentation files (the "Software"),
whismanoid 0:4847beac14e9 6 * to deal in the Software without restriction, including without limitation
whismanoid 0:4847beac14e9 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
whismanoid 0:4847beac14e9 8 * and/or sell copies of the Software, and to permit persons to whom the
whismanoid 0:4847beac14e9 9 * Software is furnished to do so, subject to the following conditions:
whismanoid 0:4847beac14e9 10 *
whismanoid 0:4847beac14e9 11 * The above copyright notice and this permission notice shall be included
whismanoid 0:4847beac14e9 12 * in all copies or substantial portions of the Software.
whismanoid 0:4847beac14e9 13 *
whismanoid 0:4847beac14e9 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
whismanoid 0:4847beac14e9 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
whismanoid 0:4847beac14e9 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
whismanoid 0:4847beac14e9 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
whismanoid 0:4847beac14e9 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
whismanoid 0:4847beac14e9 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
whismanoid 0:4847beac14e9 20 * OTHER DEALINGS IN THE SOFTWARE.
whismanoid 0:4847beac14e9 21 *
whismanoid 0:4847beac14e9 22 * Except as contained in this notice, the name of Maxim Integrated
whismanoid 0:4847beac14e9 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
whismanoid 0:4847beac14e9 24 * Products, Inc. Branding Policy.
whismanoid 0:4847beac14e9 25 *
whismanoid 0:4847beac14e9 26 * The mere transfer of this software does not imply any licenses
whismanoid 0:4847beac14e9 27 * of trade secrets, proprietary technology, copyrights, patents,
whismanoid 0:4847beac14e9 28 * trademarks, maskwork rights, or any other form of intellectual
whismanoid 0:4847beac14e9 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
whismanoid 0:4847beac14e9 30 * ownership rights.
whismanoid 0:4847beac14e9 31 *******************************************************************************
whismanoid 0:4847beac14e9 32 */
whismanoid 2:609e1e5c4d51 33 // *********************************************************************
whismanoid 2:609e1e5c4d51 34 // @file MAX541.h
whismanoid 2:609e1e5c4d51 35 // *********************************************************************
whismanoid 0:4847beac14e9 36
whismanoid 2:609e1e5c4d51 37 // Prevent multiple declaration
whismanoid 1:3908aba2ea77 38 #ifndef MAX541_H
whismanoid 1:3908aba2ea77 39 #define MAX541_H
whismanoid 1:3908aba2ea77 40
whismanoid 1:3908aba2ea77 41 #include "mbed.h"
whismanoid 0:4847beac14e9 42
whismanoid 2:609e1e5c4d51 43 /**
whismanoid 2:609e1e5c4d51 44 * @brief MAX541 Ultra-Small, 12-Bit, 4-Channel, Buffered Output Voltage DAC with Internal Reference and SPI Interface
whismanoid 2:609e1e5c4d51 45 *
whismanoid 1:3908aba2ea77 46 * @version 1.0000.0
whismanoid 1:3908aba2ea77 47 *
whismanoid 1:3908aba2ea77 48 * @details The MAX541 is an SPI programmable voltage DAC.
whismanoid 1:3908aba2ea77 49 * This driver enables writing of voltage ouptut values to the output register.
whismanoid 1:3908aba2ea77 50 *
whismanoid 2:609e1e5c4d51 51 * Datasheet: https://www.maximintegrated.com/MAX541
whismanoid 2:609e1e5c4d51 52 *
whismanoid 1:3908aba2ea77 53 * @code
whismanoid 1:3908aba2ea77 54 * #include "mbed.h"
whismanoid 1:3908aba2ea77 55 * #include "MAX541.h"
whismanoid 1:3908aba2ea77 56 *
whismanoid 2:609e1e5c4d51 57 * // Connect MAX541 to Arduino compatible connector as shown:
whismanoid 2:609e1e5c4d51 58 * // MAX541BCPA+
whismanoid 2:609e1e5c4d51 59 * // --------__--------
whismanoid 2:609e1e5c4d51 60 * // output --| 1 OUT VDD 8 |-- IOREF (3V3 or 5V logic supply)
whismanoid 2:609e1e5c4d51 61 * // GND --| 2 AGND DGND 7 |-- GND
whismanoid 2:609e1e5c4d51 62 * // V3.3 --| 3 REF DIN 6 |-- D11/SPI_MOSI
whismanoid 2:609e1e5c4d51 63 * // D10/SPI_SS --| 4 CS SCLK 5 |-- D13/SPI_SCLK
whismanoid 2:609e1e5c4d51 64 * // ------------------
whismanoid 2:609e1e5c4d51 65 *
whismanoid 1:3908aba2ea77 66 * // example code declare SPI interface
whismanoid 1:3908aba2ea77 67 * #if defined(TARGET_MAX32625MBED)
whismanoid 1:3908aba2ea77 68 * SPI spi_max541(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:3908aba2ea77 69 * DigitalOut spi_max541_cs(SPI1_SS); // TARGET_MAX32625MBED: P1_3 Arduino 10-pin header D10
whismanoid 1:3908aba2ea77 70 * // alternate spi connection
whismanoid 1:3908aba2ea77 71 * // SPI spi2_max541(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi2 TARGET_MAX32625MBED: P2_5 P2_6 P2_4 Arduino 2x3-pin header; microSD
whismanoid 1:3908aba2ea77 72 * // DigitalOut spi2_max541_cs(SPI2_SS); // TARGET_MAX32625MBED: P2_7 Arduino 2x3-pin header
whismanoid 1:3908aba2ea77 73 * #elif defined(TARGET_MAX32600MBED)
whismanoid 2:609e1e5c4d51 74 * SPI spi_max541(SPI2_MOSI, SPI2_MISO, SPI2_SCK);
whismanoid 2:609e1e5c4d51 75 * DigitalOut spi_max541_cs(SPI2_SS);
whismanoid 1:3908aba2ea77 76 * #else
whismanoid 2:609e1e5c4d51 77 * SPI spi_max541(D11, D12, D13); // Arduino 10-pin header
whismanoid 2:609e1e5c4d51 78 * DigitalOut spi_max541_cs(D10); // Arduino 10-pin header
whismanoid 1:3908aba2ea77 79 * #endif
whismanoid 1:3908aba2ea77 80 *
whismanoid 1:3908aba2ea77 81 * int main()
whismanoid 1:3908aba2ea77 82 * {
whismanoid 1:3908aba2ea77 83 * MAX541 max541(spi_max541, spi_max541_cs);
whismanoid 1:3908aba2ea77 84 * max541.VRef = 3.30;
whismanoid 1:3908aba2ea77 85 *
whismanoid 1:3908aba2ea77 86 * double voltageV = 1.0f;
whismanoid 1:3908aba2ea77 87 * max541.Set_Voltage(voltageV);
whismanoid 1:3908aba2ea77 88 *
whismanoid 1:3908aba2ea77 89 * //wait(1.0);
whismanoid 1:3908aba2ea77 90 * }
whismanoid 1:3908aba2ea77 91 * @endcode
whismanoid 1:3908aba2ea77 92 */
whismanoid 1:3908aba2ea77 93 class MAX541
whismanoid 1:3908aba2ea77 94 {
whismanoid 1:3908aba2ea77 95 public:
whismanoid 1:3908aba2ea77 96
whismanoid 2:609e1e5c4d51 97 /** ********************************************************
whismanoid 1:3908aba2ea77 98 * @brief Constructor for MAX541 Class.
whismanoid 1:3908aba2ea77 99 *
whismanoid 1:3908aba2ea77 100 * @details Allows user to use existing SPI object
whismanoid 1:3908aba2ea77 101 *
whismanoid 1:3908aba2ea77 102 * On Entry:
whismanoid 1:3908aba2ea77 103 * @param[in] spi - pointer to existing SPI object
whismanoid 1:3908aba2ea77 104 * @param[in] cs_pin - pointer to a DigitalOut pin object
whismanoid 1:3908aba2ea77 105 *
whismanoid 1:3908aba2ea77 106 * On Exit:
whismanoid 1:3908aba2ea77 107 *
whismanoid 1:3908aba2ea77 108 * @return None
whismanoid 2:609e1e5c4d51 109 */
whismanoid 1:3908aba2ea77 110 MAX541(SPI &spi, DigitalOut &cs_pin);
whismanoid 1:3908aba2ea77 111
whismanoid 2:609e1e5c4d51 112 /** ********************************************************
whismanoid 2:609e1e5c4d51 113 * @brief Default destructor for MAX541 Class.
whismanoid 2:609e1e5c4d51 114 *
whismanoid 2:609e1e5c4d51 115 * @details Destroys SPI object if owner
whismanoid 1:3908aba2ea77 116 *
whismanoid 2:609e1e5c4d51 117 * On Entry:
whismanoid 1:3908aba2ea77 118 *
whismanoid 2:609e1e5c4d51 119 * On Exit:
whismanoid 2:609e1e5c4d51 120 *
whismanoid 2:609e1e5c4d51 121 * @return None
whismanoid 2:609e1e5c4d51 122 */
whismanoid 1:3908aba2ea77 123 ~MAX541();
whismanoid 0:4847beac14e9 124
whismanoid 0:4847beac14e9 125 private:
whismanoid 2:609e1e5c4d51 126 /** SPI object */
whismanoid 0:4847beac14e9 127 SPI &m_spi;
whismanoid 0:4847beac14e9 128 int m_SPI_SCLK_Hz;
whismanoid 0:4847beac14e9 129 int m_SPI_dataMode;
whismanoid 0:4847beac14e9 130
whismanoid 2:609e1e5c4d51 131 /** Selector pin object */
whismanoid 0:4847beac14e9 132 DigitalOut &m_cs_pin;
whismanoid 0:4847beac14e9 133
whismanoid 0:4847beac14e9 134 public:
whismanoid 2:609e1e5c4d51 135 /** Reference voltage, in Volts.
whismanoid 2:609e1e5c4d51 136 * Default value is 3.3 unless otherwise specified.
whismanoid 2:609e1e5c4d51 137 * For best performance, an external 2.5V reference should be used.
whismanoid 2:609e1e5c4d51 138 */
whismanoid 0:4847beac14e9 139 double VRef;
whismanoid 1:3908aba2ea77 140
whismanoid 2:609e1e5c4d51 141 /** Full-scale (maximum) raw DAC code, in LSBs.
whismanoid 2:609e1e5c4d51 142 */
whismanoid 0:4847beac14e9 143 const float max541codeFS = (float)((uint32_t)0xffff);
whismanoid 1:3908aba2ea77 144
whismanoid 2:609e1e5c4d51 145 /** Raw DAC code, in LSBs.
whismanoid 1:3908aba2ea77 146 *
whismanoid 2:609e1e5c4d51 147 * The DAC output voltage is a function of raw DAC code:
whismanoid 2:609e1e5c4d51 148 * VOUT = VREF * (code / 65536)
whismanoid 1:3908aba2ea77 149 *
whismanoid 2:609e1e5c4d51 150 * The full-scale voltage is VREF * 65535 / 65536.
whismanoid 2:609e1e5c4d51 151 */
whismanoid 0:4847beac14e9 152 uint16_t max541_code;
whismanoid 0:4847beac14e9 153
whismanoid 2:609e1e5c4d51 154 /** Set the MAX541 output voltage.
whismanoid 1:3908aba2ea77 155 *
whismanoid 2:609e1e5c4d51 156 * @pre VRef = Full-Scale reference voltage, in Volts
whismanoid 2:609e1e5c4d51 157 * @param[in] voltageV = output voltage, in Volts
whismanoid 2:609e1e5c4d51 158 */
whismanoid 1:3908aba2ea77 159 void Set_Voltage(double voltageV);
whismanoid 0:4847beac14e9 160
whismanoid 2:609e1e5c4d51 161 /** Get the MAX541 output voltage.
whismanoid 1:3908aba2ea77 162 *
whismanoid 2:609e1e5c4d51 163 * @returns output voltage, in Volts
whismanoid 2:609e1e5c4d51 164 */
whismanoid 1:3908aba2ea77 165 double Get_Voltage() const;
whismanoid 0:4847beac14e9 166
whismanoid 2:609e1e5c4d51 167 /** Set the MAX541 output code.
whismanoid 1:3908aba2ea77 168 *
whismanoid 2:609e1e5c4d51 169 * @param[in] max541_mosiData16 = raw DAC code, in LSBs
whismanoid 2:609e1e5c4d51 170 */
whismanoid 1:3908aba2ea77 171 void Set_Code(int16_t max541_mosiData16);
whismanoid 0:4847beac14e9 172
whismanoid 2:609e1e5c4d51 173 /** Get the MAX541 output code.
whismanoid 1:3908aba2ea77 174 *
whismanoid 2:609e1e5c4d51 175 * @returns raw DAC code, in LSBs
whismanoid 2:609e1e5c4d51 176 */
whismanoid 1:3908aba2ea77 177 uint16_t Get_Code(void) const;
whismanoid 0:4847beac14e9 178
whismanoid 0:4847beac14e9 179 };
whismanoid 1:3908aba2ea77 180
whismanoid 1:3908aba2ea77 181 #endif/* MAX541_H */