I want to take a value of 1ms from the pulse sensor and calculate the BPM according to this value. When I press the BPM value on the screen, I can not read anything. My code is down. Where am I making mistakes. Could you guide me. Thanks.
#include <msp430g2553.h> #include "lcdLib.h" #include <stdint.h> unsigned int ADC_Result = 0x0000; void adc_init(); void i2s(int i,char *s); char s[100]; unsigned int BPM=0; unsigned int IBI = 600; volatile int Signal; unsigned int Noise =0; unsigned long sampleCounter=0; unsigned long lastBeatTime=0; unsigned int P =512; unsigned int T = 512; unsigned int thresh = 512; unsigned int amp = 100; unsigned int Pulse= 0; unsigned int secondBeat= 0; unsigned int firstBeat= 1; unsigned int rate[10]; void timer_init(); //void lcd (void); volatile int QS=0; volatile int runningTotal = 0; void BPM_Hesapla(void); int main(void) { WDTCTL = WDTPW + WDTHOLD; DCOCTL = CALDCO_1MHZ; BCSCTL1 = CALBC1_1MHZ; P1DIR = 0x40; P1SEL = 0x01; lcdInit(); adc_init(); timer_init(); __bis_SR_register(GIE); while (1) { } } void adc_init(){ ADC10CTL0 &= ~ENC; ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + MSC ; ADC10CTL1 = INCH_0 + SHS_0 + ADC10SSEL_0 + ADC10DIV_0 + CONSEQ_2; ADC10AE0 = BIT0; } void timer_init(){ TACTL = TASSEL_2 + ID_0 + MC_1 + TAIE ; TACCR0 = 1000; TACCTL0 = CCIE; } #pragma vector=TIMER0_A0_VECTOR __interrupt void timer_interrupt(void){ ADC10CTL0 |= ENC + ADC10SC; // Start Conversion again Signal = ADC10MEM; sampleCounter += 2; Noise = sampleCounter - lastBeatTime; if(Signal < thresh && Noise > (IBI/5)*3){ if (Signal < T){ T = Signal; } } if(Signal > thresh && Signal > P){ P = Signal; } if (Noise > 250){ if ( (Signal > thresh) && (Pulse == 0) && (Noise > ((IBI/5)*3) )){ Pulse = 1; P1OUT |= 0x40; IBI = sampleCounter - lastBeatTime; lastBeatTime = sampleCounter; if(secondBeat){ secondBeat = 0; for(int i=0; i<=9; i++){ rate[i] = IBI; } } if(firstBeat){ firstBeat = 0; secondBeat = 1; return; } runningTotal = 0; for(int i=0; i<=8; i++){ rate[i] = rate[i+1]; runningTotal += rate[i]; } rate[9] = IBI; runningTotal += rate[9]; runningTotal /= 10; BPM = 60000/runningTotal; QS = 1; if((BPM>10) && (BPM<140)){ lcdSetText("BPM: ", 0, 0); i2s(BPM,s); lcdSetText(s, 0, 1); } } } if (Signal < thresh && Pulse == 1){ P1OUT &= ~0x40; Pulse = 0; amp = P - T; thresh = amp/2 + T; P = thresh; T = thresh; } if (Noise > 2500){ thresh = 512; P = 512; T = 512; firstBeat = 1; secondBeat = 0; lastBeatTime = sampleCounter; } } void i2s(int i,char *s) // Convert Integer to String {char sign;short len;char *p; sign='+';len=0;p=s; if(i<0){sign='-';i=-i;} do{*s=(i%10)+'0';s++;len++;i/=10;}while(i!=0); if(sign=='-'){*s='-';s++;len++;} for(i=0;i<len/2;i++){p[len]=p[i];p[i]=p[len-1-i];p[len-1-i]=p[len];} p[len]=0; }