AnsweredAssumed Answered

Microsecond timer using Tim3

Question asked by Matthieu Tanguay on Jun 24, 2017
Latest reply on Jun 26, 2017 by Clive One

I think variation of this question has been asked a couple of time, but i'm trying to understand why what I am writing is not working. 

Because I want to get some experience with the HAL librairies I got myself a NucleoF446RE and an accessory shield with a P9813 LED Driver.


I also found this code that I am modifying to use HAL :


I think my problems come from my micro seconds delay function. I used the Cube to generate the base code but here is what pertain to Timer3 : 




static void MX_TIM3_Init(void)
TIM_ClockConfigTypeDef sClockSourceConfig;
TIM_MasterConfigTypeDef sMasterConfig;
htim3.Instance = TIM3;
htim3.Init.Prescaler = 84;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 0xffff;//Full 16bit
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)

//Function for micro seconds Delay
void microseconds_Delay(int Delay){
uint32_t initTime = __HAL_TIM_GET_COUNTER(&htim3);
while((__HAL_TIM_GET_COUNTER(&htim3)-initTime) < Delay){


Thank you in advance.