On a STM32F767zi I'm experimenting with GPT by starting/stopping a timer and querying the time it has passed ever since it started in milliseconds. My endgame is to start the timer when a certain event occurs (button press, signal edge, etc), but for now I wrote the simpler example bellow to experiment with:
Code: Select all
static const GPTConfig gpt5cfg = {
1000000, /* 1MHz timer clock.*/
nullptr, /* Timer callback.*/
0,
0
};
// (...)
halInit();
chSysInit();
gptStart(&GPTD5, &gpt5cfg);
while (!chThdShouldTerminateX())
{
// configure so we get a trigger every millisecond
gptStartContinuous(&GPTD5, 1000);
chThdSleepMilliseconds(250);
log_print("%u\r\n", gptGetCounterX(&GPTD5));
chThdSleepMilliseconds(250);
log_print("%u\r\n", gptGetCounterX(&GPTD5));
chThdSleepMilliseconds(250);
log_print("%u\r\n", gptGetCounterX(&GPTD5));
chThdSleepMilliseconds(250);
log_print"%u\r\n\n", gptGetCounterX(&GPTD5));
gptStopTimer(&GPTD5);
}
I was expecting to see ~250, 500, 750 and then 1000. But I get 982 on all prints. I'm either configuring something wrong or misinterpreting the timers and their APIs?
As a followup question if I want to do the same thing but in microseconds how could I setup TIM5 as 32bit timer?