Skip to main content
Nmo.1
Associate III
February 24, 2022
Question

Incorrect interrupt time

  • February 24, 2022
  • 1 reply
  • 1982 views

Hi everyone,

I'm using Nucleo H723 board. I have used 8 timers in encoder mode to read the encoders. I have also activated another timer to make an interrupt every 4ms to send the data via Usart.

everything work good but when I use sprint code to put the data in Usart, the interrupt time has been changed and it's not 4ms.

Part of my code inside interrupt:

/* USER CODE BEGIN 4 */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
 
 	timer2 = __HAL_TIM_GET_COUNTER(&htim2);
 	timer5 = __HAL_TIM_GET_COUNTER(&htim5);
 	timer23 = __HAL_TIM_GET_COUNTER(&htim23);
 	timer24 = __HAL_TIM_GET_COUNTER(&htim24);
 	timer1 = __HAL_TIM_GET_COUNTER(&htim1);
 	timer3 = __HAL_TIM_GET_COUNTER(&htim3);
 	timer4 = __HAL_TIM_GET_COUNTER(&htim4);
 	timer8 = __HAL_TIM_GET_COUNTER(&htim8);
 
	 count_FL_1=timer1/4;
	 count_FR_1=timer3/4;
	 count_RR_1=timer5/4;
	 count_RL_1=timer23/4;
 
	 count_FL_2=timer2/4;
	 count_FR_2=timer4/4;
	 count_RR_2=timer8/4;
	 count_RL_2=timer24/4;
 
 
 sprintf(buffer_FL_1, "FL_1: %ld\n", count_FL_1);
	 sprintf(buffer_FR_1, "FR_1: %ld\n", count_FR_1);
	 sprintf(buffer_RR_1, "RR_1: %ld\n", count_RR_1);
	 sprintf(buffer_RL_1, "RL_1: %ld\n", count_RL_1);
	 sprintf(buffer_FL_2, "FL_2: %ld\n", count_FL_2);
	 sprintf(buffer_FR_2, "FR_2: %ld\n", count_FR_2);
	 sprintf(buffer_RR_2, "RR_2: %ld\n", count_RR_2);
	 sprintf(buffer_RL_2, "RL_2: %ld\n", count_RL_2);
 
 
	 HAL_UART_Transmit(&huart3, (uint8_t *) buffer_i,strlen(buffer_i), 100);
 
	 HAL_UART_Transmit(&huart3, (uint8_t *) buffer_FL_1,strlen(buffer_FL_1), 100);
	 HAL_UART_Transmit(&huart3, (uint8_t *) buffer_FR_1,strlen(buffer_FR_1), 100);
	 HAL_UART_Transmit(&huart3, (uint8_t *) buffer_RR_1,strlen(buffer_RR_1), 100);
	 HAL_UART_Transmit(&huart3, (uint8_t *) buffer_RL_1,strlen(buffer_RL_1), 100);
	 HAL_UART_Transmit(&huart3, (uint8_t *) buffer_FL_2,strlen(buffer_FL_2), 100);
	 HAL_UART_Transmit(&huart3, (uint8_t *) buffer_FR_2,strlen(buffer_FR_2), 100);
	 HAL_UART_Transmit(&huart3, (uint8_t *) buffer_RR_2,strlen(buffer_RR_2), 100);
	 HAL_UART_Transmit(&huart3, (uint8_t *) buffer_RL_2,strlen(buffer_RL_2), 100);
 
 
 i++;
 j=i/1000;
 
 
 
 
}

Hier is my timer configuration.

0693W00000KaQ7ZQAV.pngwhen I delete the sprint codes the timer 4ms runs again correctly.

I appreciate it if you help me.

This topic has been closed for replies.

1 reply

Peter BENSCH
Technical Moderator
February 24, 2022

sprintf consumes a lot of memory and takes a lot of time.

What about your heap size?

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Nmo.1
Nmo.1Author
Associate III
February 24, 2022

O.K. Thank you so much. I'm a beginner and didn't know that. So I need to try another way to sent data to PC.

How can I find heap size?

Peter BENSCH
Technical Moderator
February 24, 2022

It looks like you create your skeleton program using STM32CubeMX or the STM32CubeIDE: just open your project > Project Manager, where you can set the heap size and the stack size.

Alternatively you can change it in the file ***_FLASH_ld, but that would be under the level of CubeMX, because it doesn't know about it and overwrites it again when the code is regenerated. The default value there is:

_Min_Heap_Size = 0x200 ; /* required amount of heap */
_Min_Stack_Size = 0x400 ; /* required amount of stack */

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.