Simple wrapper object for LTC2606 1CH 16Bit DAC. Instantiate DacLtc2606 object instance passing reference to mbed.I2C object instance. Call write() method on DacLtc2606 instance passing 16Bit integer (0 [Off] to 32767/-32768 [Half-On] to -1 [Full-On]) to set DAC output.
DacLtc2606.h@0:896aaf4b80d0, 2012-09-13 (annotated)
- Committer:
- rkimble
- Date:
- Thu Sep 13 23:07:18 2012 +0000
- Revision:
- 0:896aaf4b80d0
- Child:
- 1:5924632f3344
Initial Release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rkimble | 0:896aaf4b80d0 | 1 | /* mbed LTC2606 1CH 16Bit DAC Library |
rkimble | 0:896aaf4b80d0 | 2 | * Copyright (c) 2012 Reed Kimble |
rkimble | 0:896aaf4b80d0 | 3 | * |
rkimble | 0:896aaf4b80d0 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
rkimble | 0:896aaf4b80d0 | 5 | * of this software and associated documentation files (the "Software"), to deal |
rkimble | 0:896aaf4b80d0 | 6 | * in the Software without restriction, including without limitation the rights |
rkimble | 0:896aaf4b80d0 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
rkimble | 0:896aaf4b80d0 | 8 | * copies of the Software, and to permit persons to whom the Software is |
rkimble | 0:896aaf4b80d0 | 9 | * furnished to do so, subject to the following conditions: |
rkimble | 0:896aaf4b80d0 | 10 | * |
rkimble | 0:896aaf4b80d0 | 11 | * The above copyright notice and this permission notice shall be included in |
rkimble | 0:896aaf4b80d0 | 12 | * all copies or substantial portions of the Software. |
rkimble | 0:896aaf4b80d0 | 13 | * |
rkimble | 0:896aaf4b80d0 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
rkimble | 0:896aaf4b80d0 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
rkimble | 0:896aaf4b80d0 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
rkimble | 0:896aaf4b80d0 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
rkimble | 0:896aaf4b80d0 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
rkimble | 0:896aaf4b80d0 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
rkimble | 0:896aaf4b80d0 | 20 | * THE SOFTWARE. |
rkimble | 0:896aaf4b80d0 | 21 | */ |
rkimble | 0:896aaf4b80d0 | 22 | |
rkimble | 0:896aaf4b80d0 | 23 | #ifndef MBED_DACLTC2606_H |
rkimble | 0:896aaf4b80d0 | 24 | #define MBED_DACLTC2606_H |
rkimble | 0:896aaf4b80d0 | 25 | |
rkimble | 0:896aaf4b80d0 | 26 | #include "mbed.h" |
rkimble | 0:896aaf4b80d0 | 27 | |
rkimble | 0:896aaf4b80d0 | 28 | /* I2C DAC controller class |
rkimble | 0:896aaf4b80d0 | 29 | */ |
rkimble | 0:896aaf4b80d0 | 30 | class DacLtc2606 { |
rkimble | 0:896aaf4b80d0 | 31 | public: |
rkimble | 0:896aaf4b80d0 | 32 | /** Create a DacLtc2606 object using to the specified I2C object |
rkimble | 0:896aaf4b80d0 | 33 | * |
rkimble | 0:896aaf4b80d0 | 34 | * @param i2c The I2C object to communicate with |
rkimble | 0:896aaf4b80d0 | 35 | */ |
rkimble | 0:896aaf4b80d0 | 36 | DacLtc2606(I2C i2c); |
rkimble | 0:896aaf4b80d0 | 37 | |
rkimble | 0:896aaf4b80d0 | 38 | /** Set the DAC output to the specifed integer value |
rkimble | 0:896aaf4b80d0 | 39 | * |
rkimble | 0:896aaf4b80d0 | 40 | * @param value The 16 bit integer to write (0 to 32767 to -32768 to -1) |
rkimble | 0:896aaf4b80d0 | 41 | */ |
rkimble | 0:896aaf4b80d0 | 42 | bool write(int value); |
rkimble | 0:896aaf4b80d0 | 43 | |
rkimble | 0:896aaf4b80d0 | 44 | /** Set the DAC output to the specified percentage of max |
rkimble | 0:896aaf4b80d0 | 45 | * |
rkimble | 0:896aaf4b80d0 | 46 | * @param percent A double from 0.0 to 1.0 representing the percent of max output power on the DAC |
rkimble | 0:896aaf4b80d0 | 47 | */ |
rkimble | 0:896aaf4b80d0 | 48 | bool write(double percent); |
rkimble | 0:896aaf4b80d0 | 49 | |
rkimble | 0:896aaf4b80d0 | 50 | private: |
rkimble | 0:896aaf4b80d0 | 51 | static const char _slave = 0xE4; |
rkimble | 0:896aaf4b80d0 | 52 | static const char _command = 0x30; |
rkimble | 0:896aaf4b80d0 | 53 | I2C _i2c; |
rkimble | 0:896aaf4b80d0 | 54 | }; |
rkimble | 0:896aaf4b80d0 | 55 | |
rkimble | 0:896aaf4b80d0 | 56 | #endif |