This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430G2553: Hello, I've successfully interfaced the MSP430G2553 with a pulse sensor, but I'm having trouble making sense of the values and calculating heart beats per minute

Part Number: MSP430G2553


Tool/software: Code Composer Studio

The code that I have is as follows, I'm trying to calculate heart beats per minute but don't know where to begin. I know of the various methods to calculate hbm but don't know where to begin. So what the code does is get 10 values from the pulse sensor and averages them out - (so basically it doesn't do much at all). Can anyone give me an idea of how I should go about calculating hbm such as by using a thresholding method? Any advice would be very helpful. Thanks!

#include  "msp430g2253.h"
 
// Variables
int adc[50] = {0}; //Sets up an array of 10 integers and zero's the values
int avg_adc = 0;
 
// Function prototypes
void adc_Setup();
void adc_Sam10();
 
void main()
{
      WDTCTL = WDTPW + WDTHOLD;         // Stop WDT
      adc_Setup();                      // Fucntion call for adc_setup
 
      while(1)
      {
          long adctot = 0;
          adc_Sam10();      // Function call for adc_samp
          // Add all the sampled data and divide by 10 to find average
          int i = 0;
          for(i = 0; i <= 49; i++){
              adctot = adctot + adc[i];
          }
          avg_adc = adctot/50;
      }
}
 
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
  __bic_SR_register_on_exit(CPUOFF);        // Clear CPUOFF bit from 0(SR)
}
 
// ADC set-up function
void adc_Setup()
{
    ADC10CTL1 = CONSEQ_2 + INCH_0;                      // Repeat single channel, A0
    ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE;   // Sample & Hold Time + ADC10 ON + Interrupt Enable
    ADC10DTC1 = 0x32;                                  // 1000 conversions
    ADC10AE0 |= 0x01;                                   // P1.0 ADC option select
}
 
// ADC sample conversion function
void adc_Sam10()
{
    ADC10CTL0 &= ~ENC;              // Disable Conversion
    while (ADC10CTL1 & BUSY);       // Wait if ADC10 busy
    ADC10SA = (int)adc;             // Transfers data to next array (DTC auto increments address)
    ADC10CTL0 |= ENC + ADC10SC;     // Enable Conversion and conversion start
    __bis_SR_register(CPUOFF + GIE);// Low Power Mode 0, ADC10_ISR
}

  • Hi Sarosh,

    You would basically calculate the period between 2 pulses. Let's assume that your code logic is as follows:

    • At the very first pulse, you start a timer and reset its counter.
    • At any other pulse, you measure the counter (which now gives you the period) and reset the counter again for the next pulse.

    From calculating the period between 2 pulses, you should be able to calculate the heart rate. You could do it at every reading, or you could average the period between 10 pulses.

  • Hi,

    Has this issue been resolved? If so, please mark it as answered. If no response soon, this thread will be closed due to inactivity.

    Regards,
    Nathan

**Attention** This is a public forum