Iain Duncan

Measuring heart-rate

Discussion created by Iain Duncan on Mar 2, 2010
Latest reply on Mar 7, 2010 by Iain Duncan

Using:

CW 5.9, HCS08QE32, DEMOQE

Polar RMCM-01 heart-rate receiver - outputs 1ms, 3V pulse each beat detected

 

I am trying to implement a heart-rate logger as part of a bigger project, but am having difficulty with the code. I have got some good advice from these forums, but would be greatful if you could look at my code and help me out.

/*Program to calculate HR from Polar RMCM-01 reciever - outputs 1ms digital pulse when HR detected.Set up TPM input capture to measure period between pulses, calling interrupt. Blink LED each pulse.Use period to calculate HR in bpm, take in 4 readings and calculate average bpm.Store the average HRs with time stamp.*/#define OFFTIME 3000#define NUMREADINGS 4int readings[NUMREADINGS];int index = 0;int total = 0;int average = 0;int period;// Initialise input pin and status LED, clockvoid init(void){ PTCD_PTCD0 = 0; // PTC0 as input for HR PTDD_PTDD0 = 1; // PTD0 as output for LED // Set TPM clock to 1ms??? TPM3C0SC = 0x44; // Set capture rising edge only, enable interrupt // Loop through readings for (int i = 0; i++) {     readings[i] = 0; // set readings to 0 }}// Calculate BPMvoid bpm(void) { int frequence; frequence = (60000 / period); //calculate bpm if ((frequence >= 40) && (frequence <= 220)) // limit for bpm {   total -= readings[index]; // subtract the last reading     readings[index] = frequence;     total += readings[index]; // add the reading to the total     index = (index + 1); // advance to the next index         if (index >= NUMREADINGS) // if at the end of the array     {         index = 0; // go back to beginning of array       average = total / NUMREADINGS; // calculate average bpm     } }  // Set boundries for period if (period > OFFTIME) {  average = 0;  index = 0; }}// Calculate period with ISRvoid interupt VectorNumber_Vtpm3ch0 period_isr(void){ static unsigned int previous_beat;   {   previous_beat = TPM3C0V; // store current capture   period = TPM3C0V - previous_beat; // Calculate period in ms  }    PTDD_PTDD0 = ~PTDD_PTDD0 // Blink LED on pulses}//Store heart rate (average) with timestamp??

 Other than not knowing how to set my TPM clock frequency, I don't think I have set up my hardware interrupt properly, and I'm sure there are other mistakes...any help appreciated!

 

Regards,

Iain

Outcomes