ECG_ADS1198

Dependencies:   ADSlib mbed SDFileSystem

This was created for an internship project at IIT hyderabad.

Revision:
4:dee470044b03
Parent:
3:86eef673aec5
Child:
5:4bcb26d018f8
--- a/main.cpp	Tue Apr 07 18:49:23 2015 +0000
+++ b/main.cpp	Thu Apr 09 21:07:59 2015 +0000
@@ -1,5 +1,5 @@
 #include "mbed.h"
-#include "ADSlib.h"
+#include "ADSlib/ADSlib.h"
 #include "SDFileSystem/SDFileSystem.h"
 
 /***********************PROTOTYPING AND SETTINGS*********************/
@@ -10,6 +10,7 @@
 DigitalOut PWDN(p10);
 DigitalOut RESETpin(p9);
 DigitalOut STARTpin(p19);
+DigitalOut waitled(LED1);
 DigitalIn DRDY(p15);
 SPI spi(p5,p6,p7);
 SDFileSystem sd(p11,p12,p13,p14,"sd");
@@ -18,12 +19,13 @@
 LocalFileSystem local("local");
 /********************************************************************/
 
-int main()       // main call
+int main()                          // main call
 {
     /********************POWER ON SEQUENCING *****************************/
-    wait_ms(500);                   // boot up time
+    waitled =1;
+    wait_ms(500);                   //boot up time
 
-    ADS1CS=1;                       // deselect ADS1
+    ADS1CS=1;                       //deselect ADS1
     spi.format(8,3);                //spi setttings
     spi.frequency(1000000);         //spi settings
 
@@ -65,61 +67,54 @@
     STARTpin= 1;
 
     //write main superloop and rdatac mode and enable dout conversion AND SETUP FILESTORAFGE
+    Timer tensec;
+    tensec.start();
+    while(tensec.read()<=10) {
+        spi.write(RDATAC);
+        wait_ms(10);
+        while(DRDY) {}
+        ADS1CS= 0;
+        for (int i=0; i<=18; i++) {
+            Input_Data_Stream[i] = spi.write(0x00);
+        }
+        for(int i=3; i<=17; i++) {
+            int k= 0;
+            int j= 4;
+            Input_modified[k]=Input_Data_Stream[i]<<8 + Input_Data_Stream[j];
+            j++;
+            k++;
+        }
+        Input_modified[8]=Input_modified[7]-Input_modified[6];
+        Input_modified[9]=-(Input_modified[7]+Input_modified[6]/2);
+        Input_modified[10]=((2*Input_modified[6])-Input_modified[7])/2;
+        Input_modified[11]=((2*Input_modified[7])-Input_modified[6])/2;
+        spi.write(SDATAC);
 
-    spi.write(RDATAC);
-    wait_ms(10);
-    while(DRDY) {}
-    ADS1CS= 0;
-    for (int i=0; i<=18; i++) {
-        Input_Data_Stream[i] = spi.write(0x00);
-    }
-    for(int i=3; i<=17; i++) {
-        int k= 0;
-        int j= 4;
-        Input_modified[k]=Input_Data_Stream[i]<<8 + Input_Data_Stream[j];
-        j++;
-        k++;
-    }
-    Input_modified[8]=Input_modified[7]-Input_modified[6];
-    Input_modified[9]=-(Input_modified[7]+Input_modified[6]/2);
-    Input_modified[10]=((2*Input_modified[6])-Input_modified[7])/2;
-    Input_modified[11]=((2*Input_modified[7])-Input_modified[6])/2;
-    spi.write(SDATAC);
-
-    /***********************FILE IO PROCEDURE ON LOCAL STORAGE******************/
-    FILE* file = fopen("local/logfile.txt","w");
-    for (int k =0; k<12; k++) {
-        fputc(Input_modified[k],file);
-    }
-    //dont forget to fclose(file);
-    /***************************************************************************/
+        /***********************FILE IO PROCEDURE ON LOCAL STORAGE******************/
+        FILE* file = fopen("local/logfile.txt","w");
+        for (int k =0; k<12; k++) {
+            fputc(Input_modified[k],file);
+        }
+        //dont forget to 
+        //fclose(file);
+        /***************************************************************************/
 
 
 ///////////////////////////OR///////////////////////////////////////////////////////////////////////
 
 
-    /****************************SD I/O OPERATIONS *****************************/
-    mkdir("sd/logfiledir",0777);
-    FILE* file1 = fopen("sd/logfiledir/logfile.txt","w");
-    for (int k =0; k<12; k++) {
-        fputc(Input_modified[k],file1);
+        /****************************SD I/O OPERATIONS *****************************/
+        mkdir("sd/logfiledir",0777);
+        FILE* file1 = fopen("sd/logfiledir/logfile.txt","w");
+        for (int k =0; k<12; k++) {
+            fputc(Input_modified[k],file1);
+        }
+        //dont forget to 
+        //fclose(file1);
+        /***************************************************************************/
     }
-    //dont forget to fclose(file1);
-    /***************************************************************************/
-    
-
-
-
-
-
-
-
-
-
-
-
-
-
+    tensec.stop();
+    waitled =0;
 }