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 01:18:42 2019 +0000
Revision:
1:3908aba2ea77
Parent:
0:4847beac14e9
Child:
2:609e1e5c4d51
split into .h and .cpp, improve documentation

Who changed what in which revision?

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