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