Timer, Delay and Last_ticks
the clock on your robot
Timer
uint32_t HAL_GetTick(void);Delay
void HAL_Delay(uint32_t Delay);Last Ticks
Fundamental Program Structure Example: Do something every XXX ms
int main(void)
{
// Initialize Everything Here, this is like setup() in Arduino
HAL_Init();
SystemClock_Config();
MX_GPIO_Init(); //Initialize most GPIOs on board
MX_DMA_Init(); //Initialize DMA
// the following is like loop() in Arduino also
//Run code in an infinite loop: this is like loop() in Arduino
while (1) {
static uint32_t last_ticks = 0; //This variable keeps its stored value through every iteration
//Everything inside this if-statements gets called every 100ms
if((HAL_GetTick() - last_ticks) >= 100){
// do something every 100 ms
last_ticks = HAL_GetTick();
}
static uint32_t last_ticks2 = 0; //This variable keeps its stored value through every iteration
//Everything inside this if-statements gets called every 60ms
if((HAL_GetTick() - last_ticks2) >= 60){
// do another thing every 60 ms
last_ticks2 = HAL_GetTick();
}
}
}Last updated