MCP4812 library modifying MCP4822 library * Copyright (c) 2008-2010, Lerche

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MCP4812.h Source File

MCP4812.h

00001 /* MCP4812 library
00002  * MCP4822 library 
00003  * Copyright (c) 2008-2010, Lerche
00004  *
00005  * Permission is hereby granted, free of charge, to any person obtaining a copy
00006  * of this software and associated documentation files (the "Software"), to deal
00007  * in the Software without restriction, including without limitation the rights
00008  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009  * copies of the Software, and to permit persons to whom the Software is
00010  * furnished to do so, subject to the following conditions:
00011  *
00012  * The above copyright notice and this permission notice shall be included in
00013  * all copies or substantial portions of the Software.
00014  *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021  * THE SOFTWARE.
00022  * modified on 27.05.2012 for MCP4812 dual SPI DAC with 10 bits resolution
00023  */
00024 
00025 #include "mbed.h"
00026 
00027 #ifndef MCP4812_H
00028 #define MCP4812_H
00029 
00030 /** Interface to a 10-bit SPI dual-output DAC */
00031 class MCP4812 {
00032 public:
00033      /** Constructor: MCP4812
00034       * 
00035       * @param MOSI - The SPI Data out pin  
00036       * @param SCLK - The SPI clock pin
00037       * @param /CS - The ChipSelect pin 
00038       */ 
00039     MCP4812 (PinName mosi, PinName sclk, PinName ncs);
00040      /** Write to the A-output, max 1023 (0x3FF) with 2/4 mV steps
00041       *  
00042       * @param ValueA The value to be written
00043       */ 
00044     void writeA (int ValueA, int gainA);
00045      /** Write to the B-output, max 1023 (0x3FF) with 2/4 mV steps
00046       *
00047       * @param ValueB The valkue to be written
00048       */ 
00049     void writeB (int ValueB, int gainB);
00050      /** Write to any output, accoding to letter.
00051       *
00052       *
00053       */
00054     void write(char chan, int value, int gain);
00055      /** Shutdown the output on specific channel
00056       *
00057       *
00058       */
00059     void shdn();
00060     
00061     private :    
00062         SPI _spi;
00063         DigitalOut _ncs;
00064         void _init();
00065   };
00066 
00067 #endif