cancel
Showing results for 
Search instead for 
Did you mean: 

Black Pill: Timer interrupt every 1 second problem

Sansan141267
Associate

Hi,

Am using blackpill with F411 mcu at 100MHz, with Timer1 configuration:

Clock source: internal clock

Prescaler: 9999

Counter period: 9999

So Timer1 ticks every 1 second (1Hz)

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  secEllapsed++;   // volatile uint16_t variable
}


In main body

while (1)
{
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
  sprintf(strLCD, "%6d seconds", secEllapsed);
  i2c_lcd_SetCursor(0, 0);
  i2c_lcd_PrintStr(strLCD);
}

But the result is about 24 seconds less every 10 minutes.

 

So what is the problem?


Edited to apply source code formatting - please see How to insert source code for future reference.

3 REPLIES 3
mfgkw
Senior III

24 s / 10 min is just 4%. That's ok for internal clock...

But could be better. Maybe your I2C delays the Timer 1 interrupts

Andrew Neil
Super User

welcome to the forum

Please see How to write your question to maximize your chances to find a solution for best results.

 

Note that Black (and other coloured) Pill boards are not ST products, and likely do not contain a genuine STM32.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
mfgkw
Senior III

BTW your black pill board has an LSE crystal with 32768 Hz as well as an HSE crystal with 25MHz.

These are much more accurate than an internal oscillator.

You should give them a try...