AnsweredAssumed Answered

delay function with timer interrupt

Question asked by Benjamin Brammer on Apr 25, 2018
Latest reply on May 1, 2018 by Benjamin Brammer

Hey Guys,

I don't know what I am doing wrong here and really would appreciate some help:

 

I created a function called 

void DELAY_1_5us(uint16_t period)
{
     delay = true;
     __HAL_TIM_SET_AUTORELOAD(&htim7, period);
     LCD_CS_LOW;
     HAL_TIM_Base_Start_IT(&htim7);
     while(delay);
}

this function uses TIM7 of the STM32F429ZI-DISC1 discovery board as a simple programmable timer for approx. x time 1,5µs delay. with the 16-Bit ARR value I get maximum 2^16 x 1,5µs delays because of the following init routine (84MHz/128 = 656,250kHz = 1,5238 µs counter tick):

void MX_TIM7_Init(void)
{
  TIM_MasterConfigTypeDef sMasterConfig;

  htim7.Instance = TIM7;
  htim7.Init.Prescaler = 128;
  htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim7.Init.Period = 1;
  if (HAL_TIM_Base_Init(&htim7) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim7, &sMasterConfig) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

}

In the ISR I just set the delay value so the while loop in the dely function is interrupted. The LCD_CS pin is just to measure the elapsed time on an oscilloscope.

void TIM7_IRQHandler(void)
{
  /* USER CODE BEGIN TIM7_IRQn 0 */
     HAL_TIM_Base_Stop_IT(&htim7);
     LCD_CS_HIGH;
     delay = false;
  /* USER CODE END TIM7_IRQn 0 */
  HAL_TIM_IRQHandler(&htim7);
  /* USER CODE BEGIN TIM7_IRQn 1 */

  /* USER CODE END TIM7_IRQn 1 */
}

The problem now is, that the function -regardless which value for the delay period of the DELAY_1_5_us functionI choose - the timer shows only approx. 1µs delay on the oscilloscope. I checked the register entry for TIM7_ARR and it changes with each function call. I also thought this might have to do something with the UG bit to generate an UE so that the timer loads the new ARR value.

But even with htim7.instance->EGR = 0x1 nothing is happening. Also when I try to activate the preload buffer with htim7.instance->CR1 |= 0x0080; nothing is changing in the appropriate reigisters.

 

I would really appreciate if someone could help me. I tried the code with ATOLLIC TrueStudio and SW4STM32 all set with optimize for debug.

 

best regads

 

Benjamin

Outcomes