MCP4822 dual 12-bit Digital to Analog Converter (DAC) chip.
Embed:
(wiki syntax)
Show/hide line numbers
MCP4822.h
00001 #ifndef __MCP4822_H__ 00002 #define __MCP4822_H__ 00003 00004 #include "mbed.h" 00005 00006 /** MCP4822 dual 12-bit DAC 00007 * @author NickRyder, atyeomans 00008 * @version 1.1 00009 * @section LICENSE 00010 * The MIT License (MIT) 00011 * Copyright (c) 2013 Nick Ryder, Andrew Yeomans 00012 * 00013 * Permission is hereby granted, free of charge, to any person obtaining a copy 00014 * of this software and associated documentation files (the "Software"), to deal 00015 * in the Software without restriction, including without limitation the rights 00016 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 00017 * of the Software, and to permit persons to whom the Software is furnished to do so, 00018 * subject to the following conditions: 00019 * 00020 * The above copyright notice and this permission notice shall be included in all 00021 * copies or substantial portions of the Software. 00022 * 00023 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00024 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00025 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00026 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00027 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00028 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00029 */ 00030 00031 class MCP4822 { 00032 public: 00033 /** Create an MCP4822 instance 00034 * @param dataout SPI MOSI pin (should be p5 or p11) 00035 * @param clock SPI clock pin (should be p7 or p13) 00036 * @param chipselect SPI chip select pin (can be any) 00037 * @param latch Latch pin updates the DAC out. Can be any pin or NC, if NC then the latch pin on the DAC chip should be held to GND. 00038 */ 00039 MCP4822(PinName dataout, PinName clock, PinName chipselect, PinName latch); 00040 //! Set output A to voltage 00041 void setA(float voltage); 00042 //! Set output B to voltage 00043 void setB(float voltage); 00044 //! Set both output A to voltageA and outputB to voltageB 00045 void set(float voltageA, float voltageB); 00046 //! Latch the stored values to the output pins 00047 void latch(); 00048 //! shut down output from the DAC chip 00049 void shutdown(); 00050 //! shut down output form channel A 00051 void shutdownA(); 00052 //! shut down output form channel B 00053 void shutdownB(); 00054 //! Toggle chip select pin 00055 void chipSel(); 00056 private: 00057 DigitalOut cs, latchpin; 00058 SPI spi; 00059 void write(bool chanB, bool gain1, unsigned int voltage, bool shutdown = false); 00060 void setvoltage(float voltage, bool chanB = false); 00061 }; 00062 00063 00064 #endif
Generated on Thu Jul 21 2022 04:01:51 by 1.7.2