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.
Dependencies: mbed
main.cpp
00001 /* -- MBED - AD7190 00002 00003 Porting by Rododo Science. .... 2019/9/13 00004 00005 -- */ 00006 00007 00008 #include "mbed.h" 00009 #include "AD7190.h" 00010 SPI spi(D11, D12, D13); // mosi, miso, sclk 00011 DigitalOut cs(D10); // Different CS operations 00012 DigitalIn ad_rdy(D9); // Use of a _RDY Pin 00013 00014 00015 Serial pc(USBTX, USBRX); // tx, rx 00016 00017 void setup() 00018 { 00019 cs.write(1); 00020 wait(1); 00021 pc.printf("Example Start\n"); 00022 cs.write(0); 00023 while(AD7190_Init(800)==0){ 00024 pc.printf("Can't allocate AD7190\r\n"); 00025 wait(5); 00026 } 00027 00028 /* Calibrates channel AIN3(+) - AIN4(-). */ 00029 AD7190_Calibrate(AD7190_MODE_CAL_INT_ZERO, AD7190_CH_AIN3P_AIN4M); 00030 00031 } 00032 00033 void loop() 00034 { 00035 00036 unsigned long val = AD7190_TemperatureRead(); 00037 //pc.printf("Temperature = \t =%lu \r\n", val); 00038 00039 AD7190_ChannelSelect(AD7190_CH_AIN1P_AIN2M); 00040 /* Selects unipolar operation and ADC's input range to +-Vref/1. plesase refer AD7190_CONF_GAIN(x) */ 00041 AD7190_RangeSetup(0, AD7190_CONF_GAIN_64); 00042 00043 //val = AD7190_SingleConversion(); 00044 //pc.printf("ADC = \t%lu \r\n", val); 00045 00046 val = AD7190_ContinuousReadAvg(8); 00047 //pc.printf("ADC_avg = \t%lu \r\n", val); 00048 00049 double voltageAn34 = ( val * 0.00000011921 - 1 ) * 4.096 /64 ; //AIN=(輸出碼/2^23-1)*(Vref/gain) 00050 00051 00052 pc.printf("%f \r\n", voltageAn34); 00053 wait(0.01); 00054 00055 00056 } 00057 00058 00059 //---DON'T CHANGE BELOW---- 00060 // MBED compensate 00061 // main() runs in its own thread in the OS 00062 int main() { 00063 //---Enable Debug--- 00064 pc.baud(115200); 00065 //--Mark out to disable debug 00066 setup(); 00067 while (true) { 00068 loop(); 00069 } 00070 }
Generated on Sun Jul 17 2022 14:10:57 by
1.7.2