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.

Committer:
rkimble
Date:
Fri Sep 14 17:23:05 2012 +0000
Revision:
2:d101ca4ae85e
Parent:
1:5924632f3344
Improved numeric type usage/refined code.
; Added local storage and retrieval of DAC output value.

Who changed what in which revision?

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