Arduino code for biomedical project (Interrupt subroutine)

volatile int Max =512; volatile int Min = 512; volatile int th = 512; volatile int A = 100; volatile int interval[10]; //array of del_t volatile boolean Beat1 = true; volatile boolean Beat2 = false; volatile unsigned long C_1 = 0; volatile unsigned long C_last = 0; void interruptSetup(){ TCCR2A = 0x02; TCCR2B = 0x06; // 256 prescaler OCR2A = 0X7C; // top count 124, 500 Hz sampling interval TIMSK2 = 0x02; sei(); // enables global interrupts } // interrupt service routine ISR(TIMER2_COMPA_vect){ cli(); // disbles interrupts output = analogRead(input); C_1 += 2; int time = C_1 - C_last; if(output < th && time > (del_t*(3/5))){ // dichrotic noise comes within 3/5th of beat to beat interval, needs to be avoided if (output < Min){ Min = output; } } if(output > th && output > Max){ Max = output; } if (time > 250){ if ( (output > th) && (pp == false) && (time > (del_t*(3/5))) ){ pp = true; del_t = C_1 - C_last; C_last = C_1; if(Beat2){ Beat2 = false; for(int i=0; i<=9; i++){ interval[i] = del_t; } } if(Beat1){ Beat1 = false; Beat2 = true; sei(); return; } word sum = 0; for(int i=0; i<=8; i++){ interval[i] = interval[i+1]; sum += interval[i]; } interval[9] = del_t; sum += interval[9]; sum /= 10; BPM = 60000/sum; // 1 minute = 60 second = 60000 mili second h_beat = true; } } if (output < th && pp == true){ pp = false; A = Max - Min; th = A/2 + Min; Max = th; Min = th; } if (time > 2500){ th = 512; Max = 512; Min = 512; C_last = C_1; Beat1 = true; Beat2 = false; } sei(); }// end isr

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.