Skip to main content
Visitor II
June 6, 2019
Question

How to use HAL_GetTick ?

  • June 6, 2019
  • 2 replies
  • 32418 views

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);
				
 }

    This topic has been closed for replies.

    2 replies

    Visitor II
    June 6, 2019

    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.

    Visitor II
    June 19, 2019

    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

    }

    Graduate II
    June 19, 2019

    "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

    }

    Graduate II
    November 10, 2024

    Doğru olanı yazıyor musun?

     

    Translated to English using Google:   Are you writing the right thing?