ECG_ADS1198
Dependencies: ADSlib mbed SDFileSystem
This was created for an internship project at IIT hyderabad.
main.cpp@4:dee470044b03, 2015-04-09 (annotated)
- Committer:
- joelbandi
- Date:
- Thu Apr 09 21:07:59 2015 +0000
- Revision:
- 4:dee470044b03
- Parent:
- 3:86eef673aec5
- Child:
- 5:4bcb26d018f8
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joelbandi | 0:194165295aac | 1 | #include "mbed.h" |
joelbandi | 4:dee470044b03 | 2 | #include "ADSlib/ADSlib.h" |
joelbandi | 3:86eef673aec5 | 3 | #include "SDFileSystem/SDFileSystem.h" |
joelbandi | 0:194165295aac | 4 | |
joelbandi | 3:86eef673aec5 | 5 | /***********************PROTOTYPING AND SETTINGS*********************/ |
joelbandi | 2:86845af4bcac | 6 | DigitalOut CLKSEL(p8); |
joelbandi | 3:86eef673aec5 | 7 | DigitalOut ADS1CS(p16); |
joelbandi | 3:86eef673aec5 | 8 | DigitalOut ADS2CS(p17); |
joelbandi | 3:86eef673aec5 | 9 | DigitalOut MULT_ADS(p18); |
joelbandi | 2:86845af4bcac | 10 | DigitalOut PWDN(p10); |
joelbandi | 2:86845af4bcac | 11 | DigitalOut RESETpin(p9); |
joelbandi | 3:86eef673aec5 | 12 | DigitalOut STARTpin(p19); |
joelbandi | 4:dee470044b03 | 13 | DigitalOut waitled(LED1); |
joelbandi | 2:86845af4bcac | 14 | DigitalIn DRDY(p15); |
joelbandi | 2:86845af4bcac | 15 | SPI spi(p5,p6,p7); |
joelbandi | 3:86eef673aec5 | 16 | SDFileSystem sd(p11,p12,p13,p14,"sd"); |
joelbandi | 2:86845af4bcac | 17 | signed char Input_Data_Stream[19]; |
joelbandi | 2:86845af4bcac | 18 | int16_t Input_modified[12]; |
joelbandi | 3:86eef673aec5 | 19 | LocalFileSystem local("local"); |
joelbandi | 3:86eef673aec5 | 20 | /********************************************************************/ |
joelbandi | 2:86845af4bcac | 21 | |
joelbandi | 4:dee470044b03 | 22 | int main() // main call |
joelbandi | 2:86845af4bcac | 23 | { |
joelbandi | 2:86845af4bcac | 24 | /********************POWER ON SEQUENCING *****************************/ |
joelbandi | 4:dee470044b03 | 25 | waitled =1; |
joelbandi | 4:dee470044b03 | 26 | wait_ms(500); //boot up time |
joelbandi | 2:86845af4bcac | 27 | |
joelbandi | 4:dee470044b03 | 28 | ADS1CS=1; //deselect ADS1 |
joelbandi | 2:86845af4bcac | 29 | spi.format(8,3); //spi setttings |
joelbandi | 2:86845af4bcac | 30 | spi.frequency(1000000); //spi settings |
joelbandi | 2:86845af4bcac | 31 | |
joelbandi | 2:86845af4bcac | 32 | CLKSEL = 1; //clock signal (internal) setup Frequency = 2.048 MHz |
joelbandi | 2:86845af4bcac | 33 | ADS1CS= 0; |
joelbandi | 2:86845af4bcac | 34 | spi.write(W_CONFIG1); |
joelbandi | 2:86845af4bcac | 35 | spi.write(0x00); |
joelbandi | 2:86845af4bcac | 36 | spi.write(0x64); |
joelbandi | 2:86845af4bcac | 37 | ADS1CS =1; |
joelbandi | 2:86845af4bcac | 38 | |
joelbandi | 2:86845af4bcac | 39 | PWDN = 1; |
joelbandi | 2:86845af4bcac | 40 | RESETpin = 1; |
joelbandi | 2:86845af4bcac | 41 | wait(1); //Delay for Power-On Reset and Oscillator Start-Up |
joelbandi | 2:86845af4bcac | 42 | |
joelbandi | 2:86845af4bcac | 43 | ADS1CS= 0; // intial reset command for device reset and register setting clean up |
joelbandi | 2:86845af4bcac | 44 | spi.write(RESET); |
joelbandi | 2:86845af4bcac | 45 | pause_clk(18); |
joelbandi | 2:86845af4bcac | 46 | |
joelbandi | 2:86845af4bcac | 47 | |
joelbandi | 2:86845af4bcac | 48 | spi.write(SDATAC); // device boots up in RDATAC mode set it in SDATAC mode |
joelbandi | 2:86845af4bcac | 49 | pause_clk(4); |
joelbandi | 2:86845af4bcac | 50 | |
joelbandi | 2:86845af4bcac | 51 | |
joelbandi | 2:86845af4bcac | 52 | spi.write(W_CONFIG3); // internal reference stup and enable |
joelbandi | 2:86845af4bcac | 53 | spi.write(0x00); |
joelbandi | 2:86845af4bcac | 54 | spi.write(0xC0); |
joelbandi | 2:86845af4bcac | 55 | |
joelbandi | 2:86845af4bcac | 56 | /***************POWER ON SEQUENCING COMPLETE**************************/ |
joelbandi | 2:86845af4bcac | 57 | |
joelbandi | 2:86845af4bcac | 58 | |
joelbandi | 2:86845af4bcac | 59 | /**************CHANNEL SETTINGS***************************************/ |
joelbandi | 2:86845af4bcac | 60 | spi.write(W_CHnSET); |
joelbandi | 2:86845af4bcac | 61 | spi.write(0x07); |
joelbandi | 2:86845af4bcac | 62 | spi.write((int)ADS_Default_Channel_Settings); |
joelbandi | 2:86845af4bcac | 63 | ADS1CS = 1; |
joelbandi | 2:86845af4bcac | 64 | /*********************************************************************/ |
joelbandi | 2:86845af4bcac | 65 | |
joelbandi | 2:86845af4bcac | 66 | /*****************************CONVERSION BEGINS**********************/ |
joelbandi | 2:86845af4bcac | 67 | STARTpin= 1; |
joelbandi | 2:86845af4bcac | 68 | |
joelbandi | 2:86845af4bcac | 69 | //write main superloop and rdatac mode and enable dout conversion AND SETUP FILESTORAFGE |
joelbandi | 4:dee470044b03 | 70 | Timer tensec; |
joelbandi | 4:dee470044b03 | 71 | tensec.start(); |
joelbandi | 4:dee470044b03 | 72 | while(tensec.read()<=10) { |
joelbandi | 4:dee470044b03 | 73 | spi.write(RDATAC); |
joelbandi | 4:dee470044b03 | 74 | wait_ms(10); |
joelbandi | 4:dee470044b03 | 75 | while(DRDY) {} |
joelbandi | 4:dee470044b03 | 76 | ADS1CS= 0; |
joelbandi | 4:dee470044b03 | 77 | for (int i=0; i<=18; i++) { |
joelbandi | 4:dee470044b03 | 78 | Input_Data_Stream[i] = spi.write(0x00); |
joelbandi | 4:dee470044b03 | 79 | } |
joelbandi | 4:dee470044b03 | 80 | for(int i=3; i<=17; i++) { |
joelbandi | 4:dee470044b03 | 81 | int k= 0; |
joelbandi | 4:dee470044b03 | 82 | int j= 4; |
joelbandi | 4:dee470044b03 | 83 | Input_modified[k]=Input_Data_Stream[i]<<8 + Input_Data_Stream[j]; |
joelbandi | 4:dee470044b03 | 84 | j++; |
joelbandi | 4:dee470044b03 | 85 | k++; |
joelbandi | 4:dee470044b03 | 86 | } |
joelbandi | 4:dee470044b03 | 87 | Input_modified[8]=Input_modified[7]-Input_modified[6]; |
joelbandi | 4:dee470044b03 | 88 | Input_modified[9]=-(Input_modified[7]+Input_modified[6]/2); |
joelbandi | 4:dee470044b03 | 89 | Input_modified[10]=((2*Input_modified[6])-Input_modified[7])/2; |
joelbandi | 4:dee470044b03 | 90 | Input_modified[11]=((2*Input_modified[7])-Input_modified[6])/2; |
joelbandi | 4:dee470044b03 | 91 | spi.write(SDATAC); |
joelbandi | 2:86845af4bcac | 92 | |
joelbandi | 4:dee470044b03 | 93 | /***********************FILE IO PROCEDURE ON LOCAL STORAGE******************/ |
joelbandi | 4:dee470044b03 | 94 | FILE* file = fopen("local/logfile.txt","w"); |
joelbandi | 4:dee470044b03 | 95 | for (int k =0; k<12; k++) { |
joelbandi | 4:dee470044b03 | 96 | fputc(Input_modified[k],file); |
joelbandi | 4:dee470044b03 | 97 | } |
joelbandi | 4:dee470044b03 | 98 | //dont forget to |
joelbandi | 4:dee470044b03 | 99 | //fclose(file); |
joelbandi | 4:dee470044b03 | 100 | /***************************************************************************/ |
joelbandi | 3:86eef673aec5 | 101 | |
joelbandi | 3:86eef673aec5 | 102 | |
joelbandi | 3:86eef673aec5 | 103 | ///////////////////////////OR/////////////////////////////////////////////////////////////////////// |
joelbandi | 3:86eef673aec5 | 104 | |
joelbandi | 3:86eef673aec5 | 105 | |
joelbandi | 4:dee470044b03 | 106 | /****************************SD I/O OPERATIONS *****************************/ |
joelbandi | 4:dee470044b03 | 107 | mkdir("sd/logfiledir",0777); |
joelbandi | 4:dee470044b03 | 108 | FILE* file1 = fopen("sd/logfiledir/logfile.txt","w"); |
joelbandi | 4:dee470044b03 | 109 | for (int k =0; k<12; k++) { |
joelbandi | 4:dee470044b03 | 110 | fputc(Input_modified[k],file1); |
joelbandi | 4:dee470044b03 | 111 | } |
joelbandi | 4:dee470044b03 | 112 | //dont forget to |
joelbandi | 4:dee470044b03 | 113 | //fclose(file1); |
joelbandi | 4:dee470044b03 | 114 | /***************************************************************************/ |
joelbandi | 3:86eef673aec5 | 115 | } |
joelbandi | 4:dee470044b03 | 116 | tensec.stop(); |
joelbandi | 4:dee470044b03 | 117 | waitled =0; |
joelbandi | 2:86845af4bcac | 118 | } |
joelbandi | 2:86845af4bcac | 119 | |
joelbandi | 2:86845af4bcac | 120 | |
joelbandi | 2:86845af4bcac | 121 |