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: ADSlib mbed SDFileSystem
main.cpp
00001 #include "mbed.h" 00002 #include "ADSlib/ADSlib.h" 00003 #include "SDFileSystem/SDFileSystem.h" 00004 00005 /***********************PROTOTYPING AND SETTINGS*********************/ 00006 DigitalOut CLKSEL(p8); 00007 DigitalOut ADS1CS(p16); 00008 DigitalOut ADS2CS(p17); 00009 DigitalIn MULT_ADS(p18); 00010 DigitalOut PWDN(p10); 00011 DigitalOut RESETpin(p9); 00012 DigitalOut STARTpin(p19); 00013 DigitalOut waitled(LED1); 00014 DigitalIn DRDY(p15); 00015 SPI spi(p5,p6,p7); 00016 SDFileSystem sd(p11,p12,p13,p14,"sd"); 00017 signed char Input_Data_Stream[]; 00018 uint16_t Input_modified[]; 00019 LocalFileSystem local("local"); 00020 /********************************************************************/ 00021 00022 int main() // main call 00023 { 00024 /********************POWER ON SEQUENCING *****************************/ 00025 waitled =1; 00026 wait_ms(500); //boot up time 00027 00028 ADS1CS=1; //deselect ADS1 00029 spi.format(8,3); //spi setttings 00030 spi.frequency(1000000); //spi settings 00031 00032 CLKSEL = 1; //clock signal (internal) setup Frequency = 2.048 MHz 00033 ADS1CS= 0; 00034 spi.write(W_CONFIG1); 00035 spi.write(0x00); 00036 spi.write(0x64); 00037 ADS1CS =1; 00038 00039 PWDN = 1; 00040 RESETpin = 1; 00041 wait(1); //Delay for Power-On Reset and Oscillator Start-Up 00042 00043 ADS1CS= 0; // intial reset command for device reset and register setting clean up 00044 spi.write(RESET); 00045 pause_clk(18); 00046 00047 00048 spi.write(SDATAC); // device boots up in RDATAC mode set it in SDATAC mode 00049 pause_clk(4); 00050 00051 00052 spi.write(W_CONFIG3); // internal reference stup and enable 00053 spi.write(0x00); 00054 spi.write(0xC0); 00055 00056 /***************POWER ON SEQUENCING COMPLETE**************************/ 00057 00058 00059 /**************CHANNEL SETTINGS***************************************/ 00060 spi.write(W_CHnSET); 00061 spi.write(0x07); 00062 spi.write((int)ADS_Default_Channel_Settings); 00063 ADS1CS = 1; 00064 /*********************************************************************/ 00065 00066 /*****************************CONVERSION BEGINS**********************/ 00067 STARTpin= 1; 00068 00069 //write main superloop and rdatac mode and enable dout conversion AND SETUP FILESTORAFGE 00070 Timer tensec; 00071 tensec.start(); 00072 00073 00074 00075 00076 if (MULT_ADS = 0) { 00077 while(tensec.read()<=10) { 00078 spi.write(RDATAC); 00079 wait_ms(10); 00080 while(DRDY) {} 00081 ADS1CS= 0; 00082 for (int i=0; i<=18; i++) { 00083 Input_Data_Stream[i] = spi.write(0x00); 00084 } 00085 int k= 0; 00086 int j= 4; 00087 for(int i=3; i<=17; i++) { 00088 Input_modified[k]=Input_Data_Stream[i]<<8 + Input_Data_Stream[j]; 00089 j++; 00090 k++; 00091 } 00092 Input_modified[8]=Input_modified[7]-Input_modified[6]; 00093 Input_modified[9]=-(Input_modified[7]+Input_modified[6]/2); 00094 Input_modified[10]=((2*Input_modified[6])-Input_modified[7])/2; 00095 Input_modified[11]=((2*Input_modified[7])-Input_modified[6])/2; 00096 spi.write(SDATAC); 00097 00098 /***********************FILE IO PROCEDURE ON LOCAL STORAGE******************/ 00099 FILE* file = fopen("local/logfile.txt","w"); 00100 for (int k =0; k<12; k++) { 00101 fputc(Input_modified[k],file); 00102 } 00103 //dont forget to 00104 //fclose(file); 00105 /***************************************************************************/ 00106 00107 00108 ///////////////////////////OR/////////////////////////////////////////////////////////////////////// 00109 00110 00111 /****************************SD I/O OPERATIONS *****************************/ 00112 mkdir("sd/logfiledir",0777); 00113 FILE* file1 = fopen("sd/logfiledir/logfile.txt","w"); 00114 for (int k =0; k<12; k++) { 00115 fputc(Input_modified[k],file1); 00116 } 00117 //dont forget to 00118 //fclose(file1); 00119 /***************************************************************************/ 00120 } 00121 } 00122 00123 00124 if (MULT_ADS = 0) { 00125 while(tensec.read()<=10) { 00126 spi.write(RDATAC); 00127 wait_ms(10); 00128 while(DRDY) {} 00129 ADS1CS= 0; 00130 for (int i=0; i<=18; i++) { 00131 Input_Data_Stream[i] = spi.write(0x00); 00132 } 00133 int k= 0; 00134 int j= 4; 00135 for(int i=3; i<=17; i++) { 00136 Input_modified[k]=Input_Data_Stream[i]<<8 + Input_Data_Stream[j]; 00137 j++; 00138 k++; 00139 } 00140 Input_modified[8]=Input_modified[7]-Input_modified[6]; 00141 Input_modified[9]=-(Input_modified[7]+Input_modified[6]/2); 00142 Input_modified[10]=((2*Input_modified[6])-Input_modified[7])/2; 00143 Input_modified[11]=((2*Input_modified[7])-Input_modified[6])/2; 00144 spi.write(SDATAC); 00145 00146 /***********************FILE IO PROCEDURE ON LOCAL STORAGE******************/ 00147 FILE* file = fopen("local/logfile.txt","w"); 00148 for (int k =0; k<12; k++) { 00149 fputc(Input_modified[k],file); 00150 } 00151 //dont forget to 00152 //fclose(file); 00153 /***************************************************************************/ 00154 00155 00156 ///////////////////////////OR/////////////////////////////////////////////////////////////////////// 00157 00158 00159 /****************************SD I/O OPERATIONS *****************************/ 00160 mkdir("sd/logfiledir",0777); 00161 FILE* file1 = fopen("sd/logfiledir/logfile.txt","w"); 00162 for (int k =0; k<12; k++) { 00163 fputc(Input_modified[k],file1); 00164 } 00165 //dont forget to 00166 //fclose(file1); 00167 /***************************************************************************/ 00168 } 00169 } 00170 00171 00172 00173 00174 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 00185 00186 00187 00188 00189 00190 00191 00192 00193 00194 00195 00196 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 00214 00215 00216 00217 00218 00219 00220 00221 00222 00223 tensec.stop(); 00224 waitled =0; 00225 } 00226 00227 00228
Generated on Fri Jul 15 2022 03:28:24 by
1.7.2