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
Diff: MAX541.h
- Revision:
- 1:3908aba2ea77
- Parent:
- 0:4847beac14e9
- Child:
- 2:609e1e5c4d51
--- a/MAX541.h Mon Apr 22 21:18:58 2019 +0000 +++ b/MAX541.h Thu May 09 01:18:42 2019 +0000 @@ -1,4 +1,5 @@ /******************************************************************************* +* @file MAX541.h * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -31,75 +32,155 @@ ******************************************************************************* */ -class MAX541 { -public: - MAX541(SPI &spi, DigitalOut &cs_pin) - : m_spi(spi), m_cs_pin(cs_pin) // SPI interface - { - VRef = 3.3f; - m_cs_pin = 1; +#ifndef MAX541_H +#define MAX541_H + +#include "mbed.h" - m_SPI_dataMode = 0; // SPI_MODE0: CPOL=0,CPHA=0: Rising Edge stable; SCLK idle Low - m_spi.format(8,m_SPI_dataMode); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0 - m_SPI_SCLK_Hz = 4000000; // 4MHz - m_spi.frequency(m_SPI_SCLK_Hz); - } - ~MAX541() - { - } +/** @brief MAX541 Ultra-Small, 12-Bit, 4-Channel, Buffered Output Voltage DAC with Internal Reference and SPI Interface + * @version 1.0000.0 + * + * @details The MAX541 is an SPI programmable voltage DAC. + * This driver enables writing of voltage ouptut values to the output register. + * + * @code + * #include "mbed.h" + * #include "MAX541.h" + * + * // example code declare SPI interface + * #if defined(TARGET_MAX32625MBED) + * 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 + * DigitalOut spi_max541_cs(SPI1_SS); // TARGET_MAX32625MBED: P1_3 Arduino 10-pin header D10 + * // alternate spi connection + * // 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 + * // DigitalOut spi2_max541_cs(SPI2_SS); // TARGET_MAX32625MBED: P2_7 Arduino 2x3-pin header + * #elif defined(TARGET_MAX32600MBED) + * SPI spi_max541(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13 + * DigitalOut spi_max541_cs(SPI2_SS); // Generic: Arduino 10-pin header D10 + * #else + * SPI spi_max541(D11, D12, D13); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13 + * DigitalOut spi_max541_cs(D10); // Generic: Arduino 10-pin header D10 + * #endif + * + * int main() + * { + * MAX541 max541(spi_max541, spi_max541_cs); + * max541.VRef = 3.30; + * + * double voltageV = 1.0f; + * max541.Set_Voltage(voltageV); + * + * //wait(1.0); + * } + * @endcode + */ +class MAX541 +{ +public: + + /********************************************************** + * @brief Constructor for MAX541 Class. + * + * @details Allows user to use existing SPI object + * + * On Entry: + * @param[in] spi - pointer to existing SPI object + * @param[in] cs_pin - pointer to a DigitalOut pin object + * + * On Exit: + * + * @return None + **************************************************************/ + MAX541(SPI &spi, DigitalOut &cs_pin); + + /********************************************************** + * @brief more documentation + * + * @details more documentation + * + **************************************************************/ + ~MAX541(); private: - // SPI object + /********************************************************** + * @brief SPI object + * + * @details more documentation + * + **************************************************************/ SPI &m_spi; int m_SPI_SCLK_Hz; int m_SPI_dataMode; - // Selector pin object + /********************************************************** + * @brief Selector pin object + * + * @details more documentation + * + **************************************************************/ DigitalOut &m_cs_pin; public: + /********************************************************** + * @brief more documentation + * + * @details more documentation + * + **************************************************************/ double VRef; + + /********************************************************** + * @brief more documentation + * + * @details more documentation + * + **************************************************************/ const float max541codeFS = (float)((uint32_t)0xffff); + + /********************************************************** + * @brief more documentation + * + * @details more documentation + * + **************************************************************/ uint16_t max541_code; - // set the MAX541 output voltage - void Set_Voltage(double voltageV) - { - if (voltageV >= VRef) { - Set_Code(max541codeFS); - } - else if (voltageV <= 0.0f) { - Set_Code(0); - } - else { - Set_Code(voltageV / VRef * max541codeFS); - } - } + + /********************************************************** + * @brief set the MAX541 output voltage + * + * @details more documentation + * + **************************************************************/ + void Set_Voltage(double voltageV); - // get the MAX541 output voltage - double Get_Voltage() const - { - return (VRef * max541_code) / max541codeFS; - } + + /********************************************************** + * @brief get the MAX541 output voltage + * + * @details more documentation + * + **************************************************************/ + double Get_Voltage() const; - // set the MAX541 output code - void Set_Code(int16_t max541_mosiData16) - { - max541_code = (uint16_t)max541_mosiData16; - size_t max541_byteCount = 2; - static char max541_mosiData[2]; - static char max541_misoData[2]; - max541_mosiData[0] = (char)((max541_mosiData16 >> 8) & 0xFF); // MSByte - max541_mosiData[1] = (char)((max541_mosiData16 >> 0) & 0xFF); // LSByte - m_cs_pin = 0; - m_spi.write(max541_mosiData, max541_byteCount, max541_misoData, max541_byteCount); - m_cs_pin = 1; - } + + /********************************************************** + * @brief set the MAX541 output code + * + * @details more documentation + * + **************************************************************/ + void Set_Code(int16_t max541_mosiData16); - // get the MAX541 output code - uint16_t Get_Code(void) const - { - return max541_code; - } + + /********************************************************** + * @brief get the MAX541 output code + * + * @details more documentation + * + **************************************************************/ + uint16_t Get_Code(void) const; }; + +#endif/* MAX541_H */