General info on Clock and Timers
Hi!
I am new to Microcontrollers so the question could be not really exciting but I think it could help me to understand how clock and timers work.
I want to toggle the LD2 every 1 sec through a TIMER.
I have set up the SysClock at 2MHz and a TIMER running at 1KHz counting 1 sec, through pre-scaler(2000) and the Auto-reloded register (1000).
I have started the timer before the while(1) loop and I want to toggle the LED2 every 1 sec in the loop so I have used the following code lines. It seems to not working correctly. Why ? Maybe because the while condition is not performed at every clock tick, right ?
-------------------------- CODE------------------
HAL_TIM_Base_Start(&htim2);
while (1)
{
while(__HAL_TIM_GET_COUNTER(&htim2) == 0 ) HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
-------------------------------------------------------
Every suggestion will be appreciated!
Thank a lot.
