Interface to Analog devices AD5258 digital I2C potentiometer
AD5258.h@3:f5b60d166896, 2013-11-12 (annotated)
- Committer:
- RodColeman
- Date:
- Tue Nov 12 13:51:04 2013 +0000
- Revision:
- 3:f5b60d166896
- Parent:
- 2:8a71db02417b
add GPL
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RodColeman | 3:f5b60d166896 | 1 | /* Copyright 2013 Rod Coleman |
RodColeman | 3:f5b60d166896 | 2 | |
RodColeman | 3:f5b60d166896 | 3 | This program is free software: you can redistribute it and/or modify |
RodColeman | 3:f5b60d166896 | 4 | it under the terms of the GNU General Public License as published by |
RodColeman | 3:f5b60d166896 | 5 | the Free Software Foundation, either version 3 of the License, or |
RodColeman | 3:f5b60d166896 | 6 | (at your option) any later version. |
RodColeman | 3:f5b60d166896 | 7 | |
RodColeman | 3:f5b60d166896 | 8 | This program is distributed in the hope that it will be useful, |
RodColeman | 3:f5b60d166896 | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
RodColeman | 3:f5b60d166896 | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
RodColeman | 3:f5b60d166896 | 11 | GNU General Public License for more details. |
RodColeman | 3:f5b60d166896 | 12 | |
RodColeman | 3:f5b60d166896 | 13 | You should have received a copy of the GNU General Public License |
RodColeman | 3:f5b60d166896 | 14 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
RodColeman | 3:f5b60d166896 | 15 | */ |
RodColeman | 3:f5b60d166896 | 16 | |
RodColeman | 0:8920c7d857d8 | 17 | #include "mbed.h" |
RodColeman | 0:8920c7d857d8 | 18 | |
RodColeman | 0:8920c7d857d8 | 19 | #ifndef MBED_AD5258_H |
RodColeman | 0:8920c7d857d8 | 20 | #define MBED_AD5258_H |
RodColeman | 0:8920c7d857d8 | 21 | |
RodColeman | 2:8a71db02417b | 22 | // Interface to the AD5258 I2C 64-step (0x00 to 0x3F)6-Bit digital Potentiometer |
RodColeman | 2:8a71db02417b | 23 | |
RodColeman | 2:8a71db02417b | 24 | // measure reference voltage on the pin6 of U3 LM293 |
RodColeman | 2:8a71db02417b | 25 | // be sure to remove R11, and check R4 is 220 |
RodColeman | 2:8a71db02417b | 26 | |
RodColeman | 2:8a71db02417b | 27 | /*Examples: RDAC = |
RodColeman | 2:8a71db02417b | 28 | 0x00, Vref=1,0V |
RodColeman | 2:8a71db02417b | 29 | 0x03, Vref=1,1V |
RodColeman | 2:8a71db02417b | 30 | 0x05, Vref=1,2V |
RodColeman | 2:8a71db02417b | 31 | 0x0F, Vref=1,5V |
RodColeman | 2:8a71db02417b | 32 | 0x20, Vref=1,82V // default |
RodColeman | 2:8a71db02417b | 33 | 0x30, Vref=2,0V |
RodColeman | 2:8a71db02417b | 34 | 0x3F, Vref=2,2V |
RodColeman | 2:8a71db02417b | 35 | */ |
RodColeman | 2:8a71db02417b | 36 | |
RodColeman | 0:8920c7d857d8 | 37 | |
RodColeman | 0:8920c7d857d8 | 38 | class AD5258 { |
RodColeman | 0:8920c7d857d8 | 39 | public: |
RodColeman | 0:8920c7d857d8 | 40 | /** Create an instance of the AD5258 connected to specfied I2C pins, with the specified address. |
RodColeman | 0:8920c7d857d8 | 41 | * |
RodColeman | 0:8920c7d857d8 | 42 | * @param sda The I2C data pin |
RodColeman | 0:8920c7d857d8 | 43 | * @param scl The I2C clock pin |
RodColeman | 0:8920c7d857d8 | 44 | * @param address The I2C address for this AD5258 |
RodColeman | 0:8920c7d857d8 | 45 | */ |
RodColeman | 0:8920c7d857d8 | 46 | AD5258(PinName sda, PinName scl, int address); |
RodColeman | 0:8920c7d857d8 | 47 | |
RodColeman | 0:8920c7d857d8 | 48 | /** Read the RDAC value |
RodColeman | 0:8920c7d857d8 | 49 | * |
RodColeman | 0:8920c7d857d8 | 50 | * @return The 6-bit value read |
RodColeman | 0:8920c7d857d8 | 51 | */ |
RodColeman | 0:8920c7d857d8 | 52 | int read(); |
RodColeman | 0:8920c7d857d8 | 53 | |
RodColeman | 1:64570234d7b5 | 54 | /** Write to the RDAC |
RodColeman | 0:8920c7d857d8 | 55 | * |
RodColeman | 0:8920c7d857d8 | 56 | * @param data The 6-bits value: 0x00 to 0x3F to write to the pots RDAC |
RodColeman | 0:8920c7d857d8 | 57 | */ |
RodColeman | 0:8920c7d857d8 | 58 | void write(int data); |
RodColeman | 1:64570234d7b5 | 59 | |
RodColeman | 1:64570234d7b5 | 60 | // READ and WRITE EEPROM |
RodColeman | 1:64570234d7b5 | 61 | |
RodColeman | 1:64570234d7b5 | 62 | /** Read the EEPROM value |
RodColeman | 1:64570234d7b5 | 63 | * |
RodColeman | 1:64570234d7b5 | 64 | * @return The 6-bit value read |
RodColeman | 1:64570234d7b5 | 65 | */ |
RodColeman | 1:64570234d7b5 | 66 | int readEE(); |
RodColeman | 1:64570234d7b5 | 67 | |
RodColeman | 1:64570234d7b5 | 68 | /** Write to the RDAC |
RodColeman | 1:64570234d7b5 | 69 | * |
RodColeman | 1:64570234d7b5 | 70 | * @param data The 6-bits value: 0x00 to 0x3F to write to the pots RDAC |
RodColeman | 1:64570234d7b5 | 71 | */ |
RodColeman | 1:64570234d7b5 | 72 | void writeEE(int data); |
RodColeman | 1:64570234d7b5 | 73 | |
RodColeman | 1:64570234d7b5 | 74 | |
RodColeman | 1:64570234d7b5 | 75 | |
RodColeman | 1:64570234d7b5 | 76 | |
RodColeman | 1:64570234d7b5 | 77 | // STORE and RESTORE: |
RodColeman | 1:64570234d7b5 | 78 | |
RodColeman | 1:64570234d7b5 | 79 | /** store the RDAC value into the EEPROM, for nonvolatile keeping of the value |
RodColeman | 1:64570234d7b5 | 80 | * |
RodColeman | 1:64570234d7b5 | 81 | */ |
RodColeman | 1:64570234d7b5 | 82 | void store(void); |
RodColeman | 1:64570234d7b5 | 83 | |
RodColeman | 1:64570234d7b5 | 84 | /** restore to the RDAC the value from the EEPROM. NOP issued afterward, to put back into low-power idle mode |
RodColeman | 1:64570234d7b5 | 85 | * |
RodColeman | 1:64570234d7b5 | 86 | */ |
RodColeman | 1:64570234d7b5 | 87 | void restore(void); |
RodColeman | 2:8a71db02417b | 88 | |
RodColeman | 2:8a71db02417b | 89 | |
RodColeman | 2:8a71db02417b | 90 | /** update write protect bit |
RodColeman | 2:8a71db02417b | 91 | * |
RodColeman | 2:8a71db02417b | 92 | * @param enable: TRUE to SET WP, FALSE to lift WP |
RodColeman | 2:8a71db02417b | 93 | */ |
RodColeman | 2:8a71db02417b | 94 | |
RodColeman | 2:8a71db02417b | 95 | void writeProtect(bool enable); |
RodColeman | 2:8a71db02417b | 96 | |
RodColeman | 2:8a71db02417b | 97 | // TODO: tolerance register access |
RodColeman | 2:8a71db02417b | 98 | |
RodColeman | 1:64570234d7b5 | 99 | |
RodColeman | 0:8920c7d857d8 | 100 | |
RodColeman | 0:8920c7d857d8 | 101 | private: |
RodColeman | 0:8920c7d857d8 | 102 | I2C _i2c; |
RodColeman | 0:8920c7d857d8 | 103 | int _address; |
RodColeman | 0:8920c7d857d8 | 104 | }; |
RodColeman | 0:8920c7d857d8 | 105 | |
RodColeman | 0:8920c7d857d8 | 106 | #endif |