Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
MCP4922.cpp
00001 #include "MCP4922.h" 00002 #include "mbed.h" 00003 00004 MCP4922::MCP4922(PinName MOSI,PinName SCK,PinName CS,PinName LDAC): 00005 dac_SPI(MOSI,NC,SCK),dac_cs(CS),dac_l(LDAC) 00006 { 00007 dac_SPI.format(16,0); 00008 dac_SPI.frequency(20000000); 00009 dac_cs=1; 00010 dac_l=1; 00011 } 00012 00013 void MCP4922::write(int ch,float value) 00014 { 00015 if(value<0) { 00016 value=0; 00017 } else if(value>1) { 00018 value=1; 00019 } 00020 dac_cs=0; 00021 int data; 00022 if(ch==0) { 00023 data=(0b0011<<12)|(int)(value*0xFFF); 00024 } else if(ch==1) { 00025 data=(0b1011<<12)|(int)(value*0xFFF); 00026 } 00027 dac_SPI.write(data); 00028 dac_cs=1; 00029 dac_l=0; 00030 dac_l=1; 00031 }
Generated on Tue Aug 23 2022 19:17:12 by
1.7.2