Driver, C++ code, and library for the MAX5487, MAX5488, MAX5489. dual channel, SPI bus, 256-tap digital potentiometer. Non-volatile memory (EEPROM) is available for returning the wipers to their previously stored positions upon power-up.

Dependents:   MAX5487_Digital_Potentiometer_Resistor_MAX32630FTHR_Host

Committer:
jungkeviny
Date:
Sun Jul 15 03:49:41 2018 +0000
Revision:
3:4d4053c4c29e
Parent:
2:80e026469122
Updated docs

Who changed what in which revision?

UserRevisionLine numberNew 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 3:4d4053c4c29e 15 * for the MAX5487, MAX5488, MAX5489.
jungkeviny 1:bc368afe2ec8 16 *
jungkeviny 3:4d4053c4c29e 17 * @details The MAX5487 contains two SPI programmable potentiometers.
jungkeviny 1:bc368afe2ec8 18 * This driver enables setting the potentiometer wiper values as well
jungkeviny 3:4d4053c4c29e 19 * as the nonvolatile memory. This driver is compatible with the
jungkeviny 3:4d4053c4c29e 20 * MAX5487, MAX5488, MAX5489.
jungkeviny 1:bc368afe2ec8 21 *
jungkeviny 1:bc368afe2ec8 22 * @code
jungkeviny 1:bc368afe2ec8 23 * #include "mbed.h"
jungkeviny 1:bc368afe2ec8 24 * #include "max32630fthr.h"
jungkeviny 1:bc368afe2ec8 25 * #include "USBSerial.h"
jungkeviny 1:bc368afe2ec8 26 * #include "MAX5487.h"
jungkeviny 1:bc368afe2ec8 27 * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
jungkeviny 1:bc368afe2ec8 28 * Serial daplink(P2_1, P2_0);
jungkeviny 1:bc368afe2ec8 29 * USBSerial microUSB;
jungkeviny 1:bc368afe2ec8 30 * DigitalOut led1(LED1); // led to blink
jungkeviny 1:bc368afe2ec8 31 * DigitalOut selectPin(P3_0); // Pin 6_0 is used to drive chip enable low
jungkeviny 1:bc368afe2ec8 32 * SPI spi(P5_1, P5_2, P5_0); // mosi, miso, sclk
jungkeviny 1:bc368afe2ec8 33
jungkeviny 1:bc368afe2ec8 34 * int main()
jungkeviny 1:bc368afe2ec8 35 * {
jungkeviny 1:bc368afe2ec8 36 * MAX5487 test(spi, selectPin);
jungkeviny 1:bc368afe2ec8 37 * spi.format(8,0);
jungkeviny 1:bc368afe2ec8 38 * spi.frequency(1000000);
jungkeviny 1:bc368afe2ec8 39 * test.writeCommand(MAX5487::Wiper_RegA, 0x55);
jungkeviny 1:bc368afe2ec8 40 *
jungkeviny 1:bc368afe2ec8 41 * //... rest of application
jungkeviny 1:bc368afe2ec8 42 * }
jungkeviny 1:bc368afe2ec8 43 * @endcode
jungkeviny 1:bc368afe2ec8 44 */
jungkeviny 1:bc368afe2ec8 45
jungkeviny 0:3d525ab09933 46
jungkeviny 0:3d525ab09933 47
jungkeviny 0:3d525ab09933 48 class MAX5487{
jungkeviny 1:bc368afe2ec8 49 public:
jungkeviny 1:bc368afe2ec8 50 /**
jungkeviny 1:bc368afe2ec8 51 * @brief Commands supported by the potentiometer
jungkeviny 1:bc368afe2ec8 52 * @details write commands that don't involve copying
jungkeviny 2:80e026469122 53 * require an 8 bit value specified. Copy commands don't
jungkeviny 2:80e026469122 54 * requre sending an 8 bit value.
jungkeviny 1:bc368afe2ec8 55 */
jungkeviny 0:3d525ab09933 56 typedef enum {
jungkeviny 1:bc368afe2ec8 57 Wiper_RegA = 0x01, //Position of Wiper A
jungkeviny 1:bc368afe2ec8 58 Wiper_RegB = 0x02, //Position of Wiper B
jungkeviny 1:bc368afe2ec8 59 NV_RegA = 0x11, //Non Volatile Register A
jungkeviny 1:bc368afe2ec8 60 NV_RegB = 0x12, //Non Volatile Register B
jungkeviny 1:bc368afe2ec8 61 Copy_Wiper_RegA_to_NV_RegA = 0x21, //Copy Wiper A position to Non Volatile Register A
jungkeviny 1:bc368afe2ec8 62 Copy_Wiper_RegB_to_NV_RegB = 0x22, //Copy Wiper B position to Non Volatile Register B
jungkeviny 1:bc368afe2ec8 63 Copy_Wiper_RegAB_to_NV_RegAB = 0x23, //Copy both Wiper A & B positions to respective Non Volatile Registers
jungkeviny 1:bc368afe2ec8 64 Copy_NV_RegA_to_Wiper_RegA = 0x31, //Copy Non Volatile Register A to Wiper Register A
jungkeviny 1:bc368afe2ec8 65 Copy_NV_RegB_to_Wiper_RegB = 0x32, //Copy Non Volatile Register B to Wiper Register B
jungkeviny 1:bc368afe2ec8 66 Copy_NV_RegAB_to_Wiper_RegAB = 0x33 //Copy Non Volatile Register A & B to Wiper Register A & B
jungkeviny 0:3d525ab09933 67 } setting_t;
jungkeviny 1:bc368afe2ec8 68
jungkeviny 1:bc368afe2ec8 69 /**********************************************************//**
jungkeviny 1:bc368afe2ec8 70 * @brief Constructor for MAX5487 Class.
jungkeviny 1:bc368afe2ec8 71 *
jungkeviny 1:bc368afe2ec8 72 * @details Requires an existing SPI object as well as a DigitalOut object.
jungkeviny 1:bc368afe2ec8 73 * The DigitalOut object is used for a chip enable signal
jungkeviny 1:bc368afe2ec8 74 *
jungkeviny 1:bc368afe2ec8 75 * On Entry:
jungkeviny 1:bc368afe2ec8 76 * @param[in] spi - pointer to existing SPI object
jungkeviny 1:bc368afe2ec8 77 * @param[in] pin - pointer to a DigitalOut pin object
jungkeviny 1:bc368afe2ec8 78 *
jungkeviny 1:bc368afe2ec8 79 * On Exit:
jungkeviny 1:bc368afe2ec8 80 *
jungkeviny 1:bc368afe2ec8 81 * @return None
jungkeviny 1:bc368afe2ec8 82 **************************************************************/
jungkeviny 1:bc368afe2ec8 83 MAX5487(SPI &spi, DigitalOut &pin);
jungkeviny 1:bc368afe2ec8 84
jungkeviny 1:bc368afe2ec8 85 /**
jungkeviny 1:bc368afe2ec8 86 * @brief Send write command
jungkeviny 1:bc368afe2ec8 87 * @param setting - Command sent to MAX5487 register
jungkeviny 1:bc368afe2ec8 88 * @param value - 8 bit Value to write
jungkeviny 1:bc368afe2ec8 89 * @return void, output is sent through serial port
jungkeviny 1:bc368afe2ec8 90 */
jungkeviny 1:bc368afe2ec8 91 void writeCommand(MAX5487::setting_t setting, int value);
jungkeviny 1:bc368afe2ec8 92
jungkeviny 1:bc368afe2ec8 93 /**
jungkeviny 1:bc368afe2ec8 94 * @brief Send copy command
jungkeviny 1:bc368afe2ec8 95 * @param setting - Command sent to MAX5487 register
jungkeviny 1:bc368afe2ec8 96 * @return void
jungkeviny 1:bc368afe2ec8 97 */
jungkeviny 1:bc368afe2ec8 98 void writeCommand(MAX5487::setting_t setting);
jungkeviny 0:3d525ab09933 99
jungkeviny 0:3d525ab09933 100
jungkeviny 2:80e026469122 101 /************************************************************
jungkeviny 1:bc368afe2ec8 102 * @brief Default destructor for MAX5487 Class.
jungkeviny 1:bc368afe2ec8 103 *
jungkeviny 1:bc368afe2ec8 104 * @details Destroys SPI object if owner
jungkeviny 1:bc368afe2ec8 105 *
jungkeviny 1:bc368afe2ec8 106 * On Entry:
jungkeviny 1:bc368afe2ec8 107 *
jungkeviny 1:bc368afe2ec8 108 * On Exit:
jungkeviny 1:bc368afe2ec8 109 *
jungkeviny 1:bc368afe2ec8 110 * @return None
jungkeviny 1:bc368afe2ec8 111 **************************************************************/
jungkeviny 0:3d525ab09933 112 ~MAX5487();
jungkeviny 1:bc368afe2ec8 113 private:
jungkeviny 1:bc368afe2ec8 114 // SPI object
jungkeviny 1:bc368afe2ec8 115 SPI &m_spi;
jungkeviny 1:bc368afe2ec8 116 // Selector pin object
jungkeviny 1:bc368afe2ec8 117 DigitalOut &m_pin;
jungkeviny 1:bc368afe2ec8 118 };
jungkeviny 1:bc368afe2ec8 119
jungkeviny 1:bc368afe2ec8 120 #endif