Driver C++ source code for MAX5216/MAX5214 16-bit/14-bit DAC SPI (50MHz) bus ICs. Low power Digital-to_Analog Converter chips which accept supply voltages of 2.7V to 5.5V. Features Rail-to-Rail Buffered Output Operation and Safe Power-On Reset (POR) to Zero DAC Output.
Dependents: MAX5216_16_Bit_DAC_Hello_Code
Fork of MAX5487_Digital_Pot_Potentiometer_Rheostat_Resistor_Wiper by
MAX5487.h@2:80e026469122, 2018-07-15 (annotated)
- Committer:
- jungkeviny
- Date:
- Sun Jul 15 03:36:25 2018 +0000
- Revision:
- 2:80e026469122
- Parent:
- 1:bc368afe2ec8
- Child:
- 3:4d4053c4c29e
changed documentations
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jungkeviny | 1:bc368afe2ec8 | 1 | /******************************************************************************* |
jungkeviny | 1:bc368afe2ec8 | 2 | * @file MAX5487.h |
jungkeviny | 1:bc368afe2ec8 | 3 | |
jungkeviny | 1:bc368afe2ec8 | 4 | ******************************************************************************* |
jungkeviny | 1:bc368afe2ec8 | 5 | */ |
jungkeviny | 1:bc368afe2ec8 | 6 | |
jungkeviny | 2:80e026469122 | 7 | #ifndef MAX5487_H |
jungkeviny | 2:80e026469122 | 8 | #define MAX5487_H |
jungkeviny | 2:80e026469122 | 9 | |
jungkeviny | 2:80e026469122 | 10 | #include "mbed.h" |
jungkeviny | 1:bc368afe2ec8 | 11 | |
jungkeviny | 1:bc368afe2ec8 | 12 | |
jungkeviny | 1:bc368afe2ec8 | 13 | /** |
jungkeviny | 1:bc368afe2ec8 | 14 | * @brief Dual Channel SPI Digital Potentiometers with Non Volatile Memory |
jungkeviny | 1:bc368afe2ec8 | 15 | * |
jungkeviny | 1:bc368afe2ec8 | 16 | * @details The MAX5487 contains two SPI porgrammable potentiometers. |
jungkeviny | 1:bc368afe2ec8 | 17 | * This driver enables setting the potentiometer wiper values as well |
jungkeviny | 1:bc368afe2ec8 | 18 | * as the nonvolatile memory. |
jungkeviny | 1:bc368afe2ec8 | 19 | * |
jungkeviny | 1:bc368afe2ec8 | 20 | * @code |
jungkeviny | 1:bc368afe2ec8 | 21 | * #include "mbed.h" |
jungkeviny | 1:bc368afe2ec8 | 22 | * #include "max32630fthr.h" |
jungkeviny | 1:bc368afe2ec8 | 23 | * #include "USBSerial.h" |
jungkeviny | 1:bc368afe2ec8 | 24 | * #include "MAX5487.h" |
jungkeviny | 1:bc368afe2ec8 | 25 | * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
jungkeviny | 1:bc368afe2ec8 | 26 | * Serial daplink(P2_1, P2_0); |
jungkeviny | 1:bc368afe2ec8 | 27 | * USBSerial microUSB; |
jungkeviny | 1:bc368afe2ec8 | 28 | * DigitalOut led1(LED1); // led to blink |
jungkeviny | 1:bc368afe2ec8 | 29 | * DigitalOut selectPin(P3_0); // Pin 6_0 is used to drive chip enable low |
jungkeviny | 1:bc368afe2ec8 | 30 | * SPI spi(P5_1, P5_2, P5_0); // mosi, miso, sclk |
jungkeviny | 1:bc368afe2ec8 | 31 | |
jungkeviny | 1:bc368afe2ec8 | 32 | * int main() |
jungkeviny | 1:bc368afe2ec8 | 33 | * { |
jungkeviny | 1:bc368afe2ec8 | 34 | * MAX5487 test(spi, selectPin); |
jungkeviny | 1:bc368afe2ec8 | 35 | * spi.format(8,0); |
jungkeviny | 1:bc368afe2ec8 | 36 | * spi.frequency(1000000); |
jungkeviny | 1:bc368afe2ec8 | 37 | * test.writeCommand(MAX5487::Wiper_RegA, 0x55); |
jungkeviny | 1:bc368afe2ec8 | 38 | * |
jungkeviny | 1:bc368afe2ec8 | 39 | * //... rest of application |
jungkeviny | 1:bc368afe2ec8 | 40 | * } |
jungkeviny | 1:bc368afe2ec8 | 41 | * @endcode |
jungkeviny | 1:bc368afe2ec8 | 42 | */ |
jungkeviny | 1:bc368afe2ec8 | 43 | |
jungkeviny | 0:3d525ab09933 | 44 | |
jungkeviny | 0:3d525ab09933 | 45 | |
jungkeviny | 0:3d525ab09933 | 46 | class MAX5487{ |
jungkeviny | 1:bc368afe2ec8 | 47 | public: |
jungkeviny | 1:bc368afe2ec8 | 48 | /** |
jungkeviny | 1:bc368afe2ec8 | 49 | * @brief Commands supported by the potentiometer |
jungkeviny | 1:bc368afe2ec8 | 50 | * @details write commands that don't involve copying |
jungkeviny | 2:80e026469122 | 51 | * require an 8 bit value specified. Copy commands don't |
jungkeviny | 2:80e026469122 | 52 | * requre sending an 8 bit value. |
jungkeviny | 1:bc368afe2ec8 | 53 | */ |
jungkeviny | 0:3d525ab09933 | 54 | typedef enum { |
jungkeviny | 1:bc368afe2ec8 | 55 | Wiper_RegA = 0x01, //Position of Wiper A |
jungkeviny | 1:bc368afe2ec8 | 56 | Wiper_RegB = 0x02, //Position of Wiper B |
jungkeviny | 1:bc368afe2ec8 | 57 | NV_RegA = 0x11, //Non Volatile Register A |
jungkeviny | 1:bc368afe2ec8 | 58 | NV_RegB = 0x12, //Non Volatile Register B |
jungkeviny | 1:bc368afe2ec8 | 59 | Copy_Wiper_RegA_to_NV_RegA = 0x21, //Copy Wiper A position to Non Volatile Register A |
jungkeviny | 1:bc368afe2ec8 | 60 | Copy_Wiper_RegB_to_NV_RegB = 0x22, //Copy Wiper B position to Non Volatile Register B |
jungkeviny | 1:bc368afe2ec8 | 61 | Copy_Wiper_RegAB_to_NV_RegAB = 0x23, //Copy both Wiper A & B positions to respective Non Volatile Registers |
jungkeviny | 1:bc368afe2ec8 | 62 | Copy_NV_RegA_to_Wiper_RegA = 0x31, //Copy Non Volatile Register A to Wiper Register A |
jungkeviny | 1:bc368afe2ec8 | 63 | Copy_NV_RegB_to_Wiper_RegB = 0x32, //Copy Non Volatile Register B to Wiper Register B |
jungkeviny | 1:bc368afe2ec8 | 64 | Copy_NV_RegAB_to_Wiper_RegAB = 0x33 //Copy Non Volatile Register A & B to Wiper Register A & B |
jungkeviny | 0:3d525ab09933 | 65 | } setting_t; |
jungkeviny | 1:bc368afe2ec8 | 66 | |
jungkeviny | 1:bc368afe2ec8 | 67 | /**********************************************************//** |
jungkeviny | 1:bc368afe2ec8 | 68 | * @brief Constructor for MAX5487 Class. |
jungkeviny | 1:bc368afe2ec8 | 69 | * |
jungkeviny | 1:bc368afe2ec8 | 70 | * @details Requires an existing SPI object as well as a DigitalOut object. |
jungkeviny | 1:bc368afe2ec8 | 71 | * The DigitalOut object is used for a chip enable signal |
jungkeviny | 1:bc368afe2ec8 | 72 | * |
jungkeviny | 1:bc368afe2ec8 | 73 | * On Entry: |
jungkeviny | 1:bc368afe2ec8 | 74 | * @param[in] spi - pointer to existing SPI object |
jungkeviny | 1:bc368afe2ec8 | 75 | * @param[in] pin - pointer to a DigitalOut pin object |
jungkeviny | 1:bc368afe2ec8 | 76 | * |
jungkeviny | 1:bc368afe2ec8 | 77 | * On Exit: |
jungkeviny | 1:bc368afe2ec8 | 78 | * |
jungkeviny | 1:bc368afe2ec8 | 79 | * @return None |
jungkeviny | 1:bc368afe2ec8 | 80 | **************************************************************/ |
jungkeviny | 1:bc368afe2ec8 | 81 | MAX5487(SPI &spi, DigitalOut &pin); |
jungkeviny | 1:bc368afe2ec8 | 82 | |
jungkeviny | 1:bc368afe2ec8 | 83 | /** |
jungkeviny | 1:bc368afe2ec8 | 84 | * @brief Send write command |
jungkeviny | 1:bc368afe2ec8 | 85 | * @param setting - Command sent to MAX5487 register |
jungkeviny | 1:bc368afe2ec8 | 86 | * @param value - 8 bit Value to write |
jungkeviny | 1:bc368afe2ec8 | 87 | * @return void, output is sent through serial port |
jungkeviny | 1:bc368afe2ec8 | 88 | */ |
jungkeviny | 1:bc368afe2ec8 | 89 | void writeCommand(MAX5487::setting_t setting, int value); |
jungkeviny | 1:bc368afe2ec8 | 90 | |
jungkeviny | 1:bc368afe2ec8 | 91 | /** |
jungkeviny | 1:bc368afe2ec8 | 92 | * @brief Send copy command |
jungkeviny | 1:bc368afe2ec8 | 93 | * @param setting - Command sent to MAX5487 register |
jungkeviny | 1:bc368afe2ec8 | 94 | * @return void |
jungkeviny | 1:bc368afe2ec8 | 95 | */ |
jungkeviny | 1:bc368afe2ec8 | 96 | void writeCommand(MAX5487::setting_t setting); |
jungkeviny | 0:3d525ab09933 | 97 | |
jungkeviny | 0:3d525ab09933 | 98 | |
jungkeviny | 2:80e026469122 | 99 | /************************************************************ |
jungkeviny | 1:bc368afe2ec8 | 100 | * @brief Default destructor for MAX5487 Class. |
jungkeviny | 1:bc368afe2ec8 | 101 | * |
jungkeviny | 1:bc368afe2ec8 | 102 | * @details Destroys SPI object if owner |
jungkeviny | 1:bc368afe2ec8 | 103 | * |
jungkeviny | 1:bc368afe2ec8 | 104 | * On Entry: |
jungkeviny | 1:bc368afe2ec8 | 105 | * |
jungkeviny | 1:bc368afe2ec8 | 106 | * On Exit: |
jungkeviny | 1:bc368afe2ec8 | 107 | * |
jungkeviny | 1:bc368afe2ec8 | 108 | * @return None |
jungkeviny | 1:bc368afe2ec8 | 109 | **************************************************************/ |
jungkeviny | 0:3d525ab09933 | 110 | ~MAX5487(); |
jungkeviny | 1:bc368afe2ec8 | 111 | private: |
jungkeviny | 1:bc368afe2ec8 | 112 | // SPI object |
jungkeviny | 1:bc368afe2ec8 | 113 | SPI &m_spi; |
jungkeviny | 1:bc368afe2ec8 | 114 | // Selector pin object |
jungkeviny | 1:bc368afe2ec8 | 115 | DigitalOut &m_pin; |
jungkeviny | 1:bc368afe2ec8 | 116 | }; |
jungkeviny | 1:bc368afe2ec8 | 117 | |
jungkeviny | 1:bc368afe2ec8 | 118 | #endif |