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: Calculating Heart Beats per Minute

Part Number: MSP430G2553
Other Parts Discussed in Thread: MSP430G2253

Tool/software: Code Composer Studio

So here I have code that gets 10 pulses from the heart beat sensor and averages them out. Can someone give me some sample code/ help me figure out a way to calculate the heart beats per minute(You can assume the default value of the pulse sensor is about 470 when no one is touching it). If you can write me some very simple heart beat per minute code, it will help me tremendously. 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
}

  • " If you can write me some very simple heart beat per minute code, "

    this is all you need

      bpm = heart_beats / measurement_duration_in_min;  //calculate bpm

  • Thanks, but thats what I already have. I'm trying to find a way to calculate the heart_beats and duration. I need to find the max pulses because those indicate a heart beat.
  • Hi,

    What sensor are you using? Can you give more information on what the expected pulses look like?

    Also, could you clarify what you are trying to do? You said you are looking for hear beats per minute. To do this, as Danny said, you would just device the number of pulses by the time duration.

    Regards,
    Nathan
  • The pulse sensor I am using is: 

    https://www.amazon.com/Heart-Sensor-Pulsesensor-Arduino-Raspberry/dp/B01CBGH4N6

    The expected pulses should have an analog value in the 700s. When nobody is touching the pulse sensor, the analog value is around 500. 

    I'm trying to measure the heart beats per minute, where I'm getting pulses from the sensor but only the peaks represent heart beats, so I need to find the time between peaks and not just pulses. Hope that helps. Thanks

  • Below is just skeleton, but should get you going.

    * Initialize a timer and set the clock source to something you know (e.g. 32678Hz).
    * Clear the timer counter;
    *Loop Starts Here:
    ** if (value is > 470){
    ***Read timer counter and convert to time. This is the period between any two beats (should be easy to calculate BPM from this)
    ***Clear timer counter.
    **}
    *loop back
  • Hi,

    Please see Mike's example, but also note that you may not need to use the timer if you know exactly at what rate the sensor produces the pulses. For example, if you find that every 5 pulses is a heartbeat, then you know that the time between heartbeats is 5 times the time between pulses produces by the sensor.

    Regards,
    Nathan
  • If the output is an analog signal proportinal to the pulse rate, you just need to adc it and that's it.

    Calibrating it however would be difficult.

**Attention** This is a public forum