2019-06-05 09:00 PM
Dear Members,
How can I use HAL_GetTick for time stamp ?
Is this right ?
or I need something else ?
Thanks
case PULSE_TRACE_UP:
if(sensor_value > prev_sensor_value)
{
printf("PULSE TRACE_UP\r\n");
currentBeat = HAL_GetTick();
lastBeatThreshold = sensor_value;
printf("Sensor value PULSE_TRACE_UP %f\r\n",sensor_value);
}
2019-06-06 07:59 AM
currentBeat will be a uint32_t type number which is in msec unit and incremented in the background by 1 msec interrupt.
make the currentBeat a global variable (and volatile if needed). Rename it as TimeStamp_ms to be more intuitive.
In your extract code, the variable is not used.
2019-06-19 03:10 PM
HAL_GetTick will give you a 32 bit value from the internal tick cell which will be milliseconds since last reset or boot. The tick word is incremented each millisecond via the SysTick interrupt which is independant of your application code. You can call HAL GetTick at any time in your program. If you want to do something 1340 ticks from now you would use something like:
future_tick_time = HAL_GetTick() + 1340;
Then in your code loop you would use something like:
if(HAL_GetTick() > future_tick_time)
{
// do something now
}
2019-06-19 03:48 PM
"future_tick_time = HAL_GetTick() + 1340;
Then in your code loop you would use something like:
if(HAL_GetTick() > future_tick_time)
{
// do something now
}"
That code is profoundly broken, it will behave incorrectly at the roll-over point, every ~49.5 days
What you want is something that uses the unsigned math to contain the wrapping condition
uint32_t start = HAL_GetTick();
if ( (HAL_GetTick() - start) > 1340)
{
// do something
}