MCP4812 library modifying MCP4822 library * Copyright (c) 2008-2010, Lerche
MCP4812.h@0:a68207b74d7d, 2012-06-02 (annotated)
- Committer:
- afejer
- Date:
- Sat Jun 02 13:51:53 2012 +0000
- Revision:
- 0:a68207b74d7d
Revision 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
afejer | 0:a68207b74d7d | 1 | /* MCP4812 library |
afejer | 0:a68207b74d7d | 2 | * MCP4822 library |
afejer | 0:a68207b74d7d | 3 | * Copyright (c) 2008-2010, Lerche |
afejer | 0:a68207b74d7d | 4 | * |
afejer | 0:a68207b74d7d | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
afejer | 0:a68207b74d7d | 6 | * of this software and associated documentation files (the "Software"), to deal |
afejer | 0:a68207b74d7d | 7 | * in the Software without restriction, including without limitation the rights |
afejer | 0:a68207b74d7d | 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
afejer | 0:a68207b74d7d | 9 | * copies of the Software, and to permit persons to whom the Software is |
afejer | 0:a68207b74d7d | 10 | * furnished to do so, subject to the following conditions: |
afejer | 0:a68207b74d7d | 11 | * |
afejer | 0:a68207b74d7d | 12 | * The above copyright notice and this permission notice shall be included in |
afejer | 0:a68207b74d7d | 13 | * all copies or substantial portions of the Software. |
afejer | 0:a68207b74d7d | 14 | * |
afejer | 0:a68207b74d7d | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
afejer | 0:a68207b74d7d | 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
afejer | 0:a68207b74d7d | 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
afejer | 0:a68207b74d7d | 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
afejer | 0:a68207b74d7d | 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
afejer | 0:a68207b74d7d | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
afejer | 0:a68207b74d7d | 21 | * THE SOFTWARE. |
afejer | 0:a68207b74d7d | 22 | * modified on 27.05.2012 for MCP4812 dual SPI DAC with 10 bits resolution |
afejer | 0:a68207b74d7d | 23 | */ |
afejer | 0:a68207b74d7d | 24 | |
afejer | 0:a68207b74d7d | 25 | #include "mbed.h" |
afejer | 0:a68207b74d7d | 26 | |
afejer | 0:a68207b74d7d | 27 | #ifndef MCP4812_H |
afejer | 0:a68207b74d7d | 28 | #define MCP4812_H |
afejer | 0:a68207b74d7d | 29 | |
afejer | 0:a68207b74d7d | 30 | /** Interface to a 10-bit SPI dual-output DAC */ |
afejer | 0:a68207b74d7d | 31 | class MCP4812 { |
afejer | 0:a68207b74d7d | 32 | public: |
afejer | 0:a68207b74d7d | 33 | /** Constructor: MCP4812 |
afejer | 0:a68207b74d7d | 34 | * |
afejer | 0:a68207b74d7d | 35 | * @param MOSI - The SPI Data out pin |
afejer | 0:a68207b74d7d | 36 | * @param SCLK - The SPI clock pin |
afejer | 0:a68207b74d7d | 37 | * @param /CS - The ChipSelect pin |
afejer | 0:a68207b74d7d | 38 | */ |
afejer | 0:a68207b74d7d | 39 | MCP4812 (PinName mosi, PinName sclk, PinName ncs); |
afejer | 0:a68207b74d7d | 40 | /** Write to the A-output, max 1023 (0x3FF) with 2/4 mV steps |
afejer | 0:a68207b74d7d | 41 | * |
afejer | 0:a68207b74d7d | 42 | * @param ValueA The value to be written |
afejer | 0:a68207b74d7d | 43 | */ |
afejer | 0:a68207b74d7d | 44 | void writeA (int ValueA, int gainA); |
afejer | 0:a68207b74d7d | 45 | /** Write to the B-output, max 1023 (0x3FF) with 2/4 mV steps |
afejer | 0:a68207b74d7d | 46 | * |
afejer | 0:a68207b74d7d | 47 | * @param ValueB The valkue to be written |
afejer | 0:a68207b74d7d | 48 | */ |
afejer | 0:a68207b74d7d | 49 | void writeB (int ValueB, int gainB); |
afejer | 0:a68207b74d7d | 50 | /** Write to any output, accoding to letter. |
afejer | 0:a68207b74d7d | 51 | * |
afejer | 0:a68207b74d7d | 52 | * |
afejer | 0:a68207b74d7d | 53 | */ |
afejer | 0:a68207b74d7d | 54 | void write(char chan, int value, int gain); |
afejer | 0:a68207b74d7d | 55 | /** Shutdown the output on specific channel |
afejer | 0:a68207b74d7d | 56 | * |
afejer | 0:a68207b74d7d | 57 | * |
afejer | 0:a68207b74d7d | 58 | */ |
afejer | 0:a68207b74d7d | 59 | void shdn(); |
afejer | 0:a68207b74d7d | 60 | |
afejer | 0:a68207b74d7d | 61 | private : |
afejer | 0:a68207b74d7d | 62 | SPI _spi; |
afejer | 0:a68207b74d7d | 63 | DigitalOut _ncs; |
afejer | 0:a68207b74d7d | 64 | void _init(); |
afejer | 0:a68207b74d7d | 65 | }; |
afejer | 0:a68207b74d7d | 66 | |
afejer | 0:a68207b74d7d | 67 | #endif |