cancel
Showing results for 
Search instead for 
Did you mean: 

LPTIM works at an irregular time delay

ZHANGHN
Associate II

I found that LPTIM works at an irregular time delay, it often takes 30-40 seconds

to start counting. Also, when l read the current counter, sometimes the LPTIM drops

(or l think the counter seems to be restarted) before it reaches the counter period(as shown in the

the figure, when reaching the period should print "Hello World!", but in the figure,

the number sometimes drops (or restarts) before printing).

5c7ea546019783c9b6c8302a9270556.png

The core code is shown in the following:

int _write(int file, char *ptr, int len){

HAL_UART_Transmit(&huart2,(uint8_t*)ptr,len,HAL_MAX_DELAY);

return len;

}

/* USER CODE END 0 */

 

/**

* @brief The application entry point.

* @retval int

*/

int main(void)

{

/* USER CODE BEGIN 1 */

int timerValue;

int a=0;

/* USER CODE END 1 */

 

/* MCU Configuration--------------------------------------------------------*/

 

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

 

/* USER CODE BEGIN Init */

 

/* USER CODE END Init */

 

/* Configure the system clock */

SystemClock_Config();

 

/* USER CODE BEGIN SysInit */

 

/* USER CODE END SysInit */

 

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_USART2_UART_Init();

MX_LPTIM2_Init();

MX_LPUART1_UART_Init();

/* USER CODE BEGIN 2 */

HAL_LPTIM_TimeOut_Start_IT(&hlptim2, Period, Timeout);

HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON,PWR_STOPENTRY_WFI);

/* USER CODE END 2 */

 

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */

 

/* USER CODE BEGIN 3 */

timerValue = HAL_LPTIM_ReadCounter(&hlptim2);

printf("Current: %d\r\n",timerValue);

HAL_Delay(500);

}

/* USER CODE END 3 */

}

 

2 REPLIES 2
TDK
Guru

Please include your chip number in the post.

> HAL_PWR_EnterSTOPMode

Wonder if this is having an effect.

Probably some other code is messing with the timer somewhere.

If you feel a post has answered your question, please click "Accept as Solution".

Thanks for your reply. My chip number is nucleo-G071RB. Even if l delete HAL_PWR_EnterSTOPMode, the LPTIM still doesn't work.