I'm working on a Nucleo board - F446RE version - and using VisualGDB with Visual Studio.
I'm confused about clocks, recall reading up on this a year or so ago and never really managed to fully grasp it with "sys clocks" and "sys tick" and so on.
Anyway I often see code like this:
Note the hard coded "90" there on line 3, but why? isn't it better practice to write this as:
In my case the HAL_RCC_GetSysClockFreq() function returns 16,000,000 so the code I have can't assume a 90 MHz clock.
I'm confused about clocks, recall reading up on this a year or so ago and never really managed to fully grasp it with "sys clocks" and "sys tick" and so on.
Anyway I often see code like this:
C:
// Configure TIM2 in One-Pulse Mode
htim2.Instance = TIM2;
htim2.Init.Prescaler = 90 - 1; // 1 MHz timer clock (assuming 90 MHz system clock)
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.Period = 10 - 1; // Pulse duration: 10 µs
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
Code:
// Configure TIM2 in One-Pulse Mode
htim2.Instance = TIM2;
htim2.Init.Prescaler = (HAL_RCC_GetSysClockFreq() / 1000000) - 1; // 1 MHz timer clock (based on actual system clock)
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.Period = 10 - 1; // Pulse duration: 10 µs
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
