2019-06-09 04:53 AM
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
2019-06-09 08:32 AM
Get a TIMer example from a STM32 Cube Nucleo board project.
It's called Timer Input Capture for the generic way of doing it.
Connect the pulse source to the timer channel 1 for example.
Setup input capture on falling edge
The timer for example runs at 1MHz, count up to 65536 and overflows back to 0 forever.
If you use interrupt on falling edge of the input capture, save the value and substract it from the previous occuring interrupt.
Capture n=5 : read 0x0500
Capture n=6 : read 0x0680
Capture n=7 : read 0x800
Period is 0x680-0x500 = 0x180
Or 0x800 - 0x680 = 0x180
Works even with overflow... nothing to worry.
0x180 = 384 = 384 usec (1MHz timer) = 2.6 kHz
Lowest HW measureable frequency it the timer period.
Measuring the hgih and low time is possible, just select rise/fall edge for high level.
2019-06-09 08:50 AM
Configure TIM in External Count mode?
Configure the TIM in free-count mode, and time-stamp events, delta the CCRx samples.
2019-06-09 07:33 PM
I'm thinking with Hal_GetSystick ?
2019-06-09 07:50 PM
I got output like this :
Period After RED data= 129435
Samples recorded 6
LowPassFilterIR max 161.856598
Data 6 Output MAX30100,0x09 register (FIFO DATA) IR : 694
DC filterIR = 660.994995
MeanDiff filterIR = 660.000000
LowPass filterIR = 161.856598
Period After IRRED data= 129643
Data 6 Output MAX30100,0x09 register (FIFO DATA) RED : 694
DC filterRed = 660.994995
MeanDiff filterRed = 660.000000
LowPass filterRed = 161.856598
Period After RED data= 129643
Samples recorded 7
LowPassFilterIR max 161.856598
Data 7 Output MAX30100,0x09 register (FIFO DATA) IR : 696
DC filterIR = 662.950317
MeanDiff filterIR = 660.000000
LowPass filterIR = 161.856598
Period After IRRED data= 129837
Data 7 Output MAX30100,0x09 register (FIFO DATA) RED : 696
DC filterRed = 662.950317
MeanDiff filterRed = 660.000000
LowPass filterRed = 161.856598
Period After RED data= 129837
Samples recorded 8
LowPassFilterIR max 161.856598
Data 8 Output MAX30100,0x09 register (FIFO DATA) IR : 694
DC filterIR = 660.852417
MeanDiff filterIR = 660.000000
LowPass filterIR = 161.856598
Period After IRRED data= 130032
Data 8 Output MAX30100,0x09 register (FIFO DATA) RED : 694
DC filterRed = 660.852417
MeanDiff filterRed = 660.000000
LowPass filterRed = 161.856598
Period After RED data= 130032
Samples recorded 9
LowPassFilterIR max 161.856598
Data 9 Output MAX30100,0x09 register (FIFO DATA) IR : 34835
DC filterIR = 34801.957031
MeanDiff filterIR = 660.000000
LowPass filterIR = 161.856598
Period After IRRED data= 130239
Data 9 Output MAX30100,0x09 register (FIFO DATA) RED : 34835
DC filterRed = 34801.957031
MeanDiff filterRed = 660.000000
LowPass filterRed = 161.856598
Period After RED data= 130239
Samples recorded 10
LowPassFilterIR max 161.856598
How can I take the maximum output as my starting period (1) and end period (2) ?
I have LowPassFilterIR max and LowPassFilterRed max values ...
Thanks
2019-06-09 07:53 PM
I have
max = 0;
if ( lowPassFilterIR>max)
{
max = lowPassFilterIR;
printf("LowPassFilterIR max %f \r\n",lowPassFilterIR);
}
How can I take timestamp of that value ?
2019-06-09 08:21 PM
Keep track of when you take each sample, or understand the sample rate.
2019-06-09 08:37 PM
probably ascending bubble sort can help me ?
2019-06-09 08:39 PM
2019-06-10 03:50 AM
How can I connect the timer input ? the output of the sensor is in the code ?