cancel
Showing results for 
Search instead for 
Did you mean: 

Calculating a pulse period ?

antonius
Senior

Dear Members,

How can I count a pulse from a sensor with timer ?

How can I calculate the period of this pulse ?

samplebuff[i].ired   = buffer_rx[ j ];

       samplebuff[i].ired  <<=  8U;

       samplebuff[i].ired  |=  buffer_rx[ j + 1 ];

between

samplebuff[i].ired   = buffer_rx[ j ];

and another

samplebuff[i].ired   = buffer_rx[ j ];

?

Thanks

11 REPLIES 11
 HAL_I2C_Master_Receive(&hi2c2, 0xAF, buffer_rx ,number_sample*4, 100); //receive 4 bytes from MAX30100
 
   for(i=j=0;i<=number_sample;i++,j+=4)
 
  {   
 
       samplesRecorded++;
 
       period[i]= HAL_GetTick();
 
      printf("========================IR RED BEGIN==========================\r\n"); 
 
       samplebuff[i].ired   = buffer_rx[ j ];
 
       samplebuff[i].ired  <<=  8U;
 
       samplebuff[i].ired  |=  buffer_rx[ j + 1 ];
 
       printf("Data %u ",i);
 
       printf("Output MAX30100,0x09 register (FIFO DATA) IR : %u \r\n", samplebuff[i].ired);
 
   
 
 
 
      dcFilterIR = dcRemoval(samplebuff[i].ired,dcFilterIR);
 
      printf("DC filterIR = %f\r\n",dcFilterIR);
 
   
 
      meanDiffResIR=medfilter(dcFilterIR);
 
      printf("MeanDiff filterIR = %f\r\n",meanDiffResIR);
 
      lowPassFilterIR = lowPassButterworthFilter(meanDiffResIR);
 
      printf("LowPass filterIR = %f\r\n",lowPassFilterIR);
 
 
      printf("Timestamp After IRRED data= %u \r\n",period[i]);
 
       max = 0;
 
           if ( lowPassFilterIR>max)
 
               {
 
                  max = lowPassFilterIR;
 
 
                  printf("LowPassFilterIR max %f \r\n",lowPassFilterIR);
 
                  printf("Max timestamp IRRED= %u \r\n\n",period[i]);
 
                  float heartbeat = 60000 / period[0] -period[1];
 
                  printf ("Heart beat : %f \r\n",heartbeat);
 
               }
 
 

with hal_getsystick(), I get the value, but I got negative on the heartbeat,

How can I capture maximum value time ? I don't understand.

thanks

You understand C comes with qsort(), right?

You need to relate the time with the samples you have. None of your code seems to account for time.

You could perhaps look at the zero crossing, Or min/max for a sinewave 1/2 frequency.

Perhaps review some texts on signal processing.

Surely App Notes and code examples exist for the MAX30100 parts?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..