ECG_ADS1198
Dependencies: ADSlib mbed SDFileSystem
This was created for an internship project at IIT hyderabad.
main.cpp@2:86845af4bcac, 2015-04-05 (annotated)
- Committer:
- joelbandi
- Date:
- Sun Apr 05 20:34:03 2015 +0000
- Revision:
- 2:86845af4bcac
- Parent:
- 1:65a219536d66
- Child:
- 3:86eef673aec5
SUPERFIX;
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 | 0:194165295aac | 3 | |
joelbandi | 2:86845af4bcac | 4 | /***********************PROTOTYPING**********************************/ |
joelbandi | 2:86845af4bcac | 5 | DigitalOut CLKSEL(p8); |
joelbandi | 2:86845af4bcac | 6 | DigitalOut ADS1CS(p11); |
joelbandi | 2:86845af4bcac | 7 | DigitalOut ADS2CS(p12); |
joelbandi | 2:86845af4bcac | 8 | DigitalOut MULT_ADS(p13); |
joelbandi | 2:86845af4bcac | 9 | DigitalOut PWDN(p10); |
joelbandi | 2:86845af4bcac | 10 | DigitalOut RESETpin(p9); |
joelbandi | 2:86845af4bcac | 11 | DigitalOut STARTpin(p14); |
joelbandi | 2:86845af4bcac | 12 | DigitalIn DRDY(p15); |
joelbandi | 2:86845af4bcac | 13 | SPI spi(p5,p6,p7); |
joelbandi | 2:86845af4bcac | 14 | /********************************************************************/ |
joelbandi | 2:86845af4bcac | 15 | signed char Input_Data_Stream[19]; |
joelbandi | 2:86845af4bcac | 16 | int16_t Input_modified[12]; |
joelbandi | 2:86845af4bcac | 17 | |
joelbandi | 2:86845af4bcac | 18 | int main() // main call |
joelbandi | 2:86845af4bcac | 19 | { |
joelbandi | 2:86845af4bcac | 20 | /********************POWER ON SEQUENCING *****************************/ |
joelbandi | 2:86845af4bcac | 21 | wait_ms(500); // boot up time |
joelbandi | 2:86845af4bcac | 22 | |
joelbandi | 2:86845af4bcac | 23 | ADS1CS=1; // deselect ADS1 |
joelbandi | 2:86845af4bcac | 24 | spi.format(8,3); //spi setttings |
joelbandi | 2:86845af4bcac | 25 | spi.frequency(1000000); //spi settings |
joelbandi | 2:86845af4bcac | 26 | |
joelbandi | 2:86845af4bcac | 27 | CLKSEL = 1; //clock signal (internal) setup Frequency = 2.048 MHz |
joelbandi | 2:86845af4bcac | 28 | ADS1CS= 0; |
joelbandi | 2:86845af4bcac | 29 | spi.write(W_CONFIG1); |
joelbandi | 2:86845af4bcac | 30 | spi.write(0x00); |
joelbandi | 2:86845af4bcac | 31 | spi.write(0x64); |
joelbandi | 2:86845af4bcac | 32 | ADS1CS =1; |
joelbandi | 2:86845af4bcac | 33 | |
joelbandi | 2:86845af4bcac | 34 | PWDN = 1; |
joelbandi | 2:86845af4bcac | 35 | RESETpin = 1; |
joelbandi | 2:86845af4bcac | 36 | wait(1); //Delay for Power-On Reset and Oscillator Start-Up |
joelbandi | 2:86845af4bcac | 37 | |
joelbandi | 2:86845af4bcac | 38 | ADS1CS= 0; // intial reset command for device reset and register setting clean up |
joelbandi | 2:86845af4bcac | 39 | spi.write(RESET); |
joelbandi | 2:86845af4bcac | 40 | pause_clk(18); |
joelbandi | 2:86845af4bcac | 41 | |
joelbandi | 2:86845af4bcac | 42 | |
joelbandi | 2:86845af4bcac | 43 | spi.write(SDATAC); // device boots up in RDATAC mode set it in SDATAC mode |
joelbandi | 2:86845af4bcac | 44 | pause_clk(4); |
joelbandi | 2:86845af4bcac | 45 | |
joelbandi | 2:86845af4bcac | 46 | |
joelbandi | 2:86845af4bcac | 47 | spi.write(W_CONFIG3); // internal reference stup and enable |
joelbandi | 2:86845af4bcac | 48 | spi.write(0x00); |
joelbandi | 2:86845af4bcac | 49 | spi.write(0xC0); |
joelbandi | 2:86845af4bcac | 50 | |
joelbandi | 2:86845af4bcac | 51 | /***************POWER ON SEQUENCING COMPLETE**************************/ |
joelbandi | 2:86845af4bcac | 52 | |
joelbandi | 2:86845af4bcac | 53 | |
joelbandi | 2:86845af4bcac | 54 | /**************CHANNEL SETTINGS***************************************/ |
joelbandi | 2:86845af4bcac | 55 | spi.write(W_CHnSET); |
joelbandi | 2:86845af4bcac | 56 | spi.write(0x07); |
joelbandi | 2:86845af4bcac | 57 | spi.write((int)ADS_Default_Channel_Settings); |
joelbandi | 2:86845af4bcac | 58 | ADS1CS = 1; |
joelbandi | 2:86845af4bcac | 59 | /*********************************************************************/ |
joelbandi | 2:86845af4bcac | 60 | |
joelbandi | 2:86845af4bcac | 61 | /*****************************CONVERSION BEGINS**********************/ |
joelbandi | 2:86845af4bcac | 62 | STARTpin= 1; |
joelbandi | 2:86845af4bcac | 63 | |
joelbandi | 2:86845af4bcac | 64 | //write main superloop and rdatac mode and enable dout conversion AND SETUP FILESTORAFGE |
joelbandi | 2:86845af4bcac | 65 | |
joelbandi | 2:86845af4bcac | 66 | spi.write(RDATAC); |
joelbandi | 2:86845af4bcac | 67 | wait_ms(10); |
joelbandi | 2:86845af4bcac | 68 | while(DRDY) {} |
joelbandi | 2:86845af4bcac | 69 | ADS1CS= 0; |
joelbandi | 2:86845af4bcac | 70 | for (int i=0; i<=18; i++) { |
joelbandi | 2:86845af4bcac | 71 | Input_Data_Stream[i] = spi.write(0x00); |
joelbandi | 2:86845af4bcac | 72 | } |
joelbandi | 2:86845af4bcac | 73 | for(int i=3; i<=17; i++) { |
joelbandi | 2:86845af4bcac | 74 | int k= 0; |
joelbandi | 2:86845af4bcac | 75 | int j= 4; |
joelbandi | 2:86845af4bcac | 76 | Input_modified[k]=Input_Data_Stream[i]<<8 + Input_Data_Stream[j]; |
joelbandi | 2:86845af4bcac | 77 | j++; |
joelbandi | 2:86845af4bcac | 78 | k++; |
joelbandi | 2:86845af4bcac | 79 | } |
joelbandi | 2:86845af4bcac | 80 | Input_modified[8]=Input_modified[7]-Input_modified[6]; |
joelbandi | 2:86845af4bcac | 81 | Input_modified[9]=-(Input_modified[7]+Input_modified[6]/2); |
joelbandi | 2:86845af4bcac | 82 | Input_modified[10]=((2*Input_modified[6])-Input_modified[7])/2; |
joelbandi | 2:86845af4bcac | 83 | Input_modified[11]=((2*Input_modified[7])-Input_modified[6])/2; |
joelbandi | 2:86845af4bcac | 84 | spi.write(SDATAC); |
joelbandi | 2:86845af4bcac | 85 | |
joelbandi | 0:194165295aac | 86 | |
joelbandi | 0:194165295aac | 87 | |
joelbandi | 2:86845af4bcac | 88 | |
joelbandi | 2:86845af4bcac | 89 | |
joelbandi | 2:86845af4bcac | 90 | |
joelbandi | 2:86845af4bcac | 91 | |
joelbandi | 0:194165295aac | 92 | |
joelbandi | 2:86845af4bcac | 93 | |
joelbandi | 2:86845af4bcac | 94 | } |
joelbandi | 2:86845af4bcac | 95 | |
joelbandi | 2:86845af4bcac | 96 | |
joelbandi | 2:86845af4bcac | 97 |