cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F7xx is a 216 MHz ARM MCU But I Can Not Generate Even 0.5 microsecond Timer Interrupt?

MSERT
Associate II

Hi,

//In my project i want to use 0.5 us (500 nanosecond) timer interrupt counter. 

//The MCUs max speed is 216 MHz. To get 200 MHz clock frequency, My OSC and CLOCK Settings are 

void SystemClock_Config(void)

{

RCC_OscInitTypeDef RCC_OscInitStruct;

RCC_ClkInitTypeDef RCC_ClkInitStruct;

HAL_StatusTypeDef ret = HAL_OK;

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

RCC_OscInitStruct.HSEState = RCC_HSE_ON;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

RCC_OscInitStruct.PLL.PLLM = 4;

RCC_OscInitStruct.PLL.PLLN = 192;

RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

RCC_OscInitStruct.PLL.PLLQ = 8;

ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);

if(ret != HAL_OK)

{

while(1){;}

}

ret = HAL_PWREx_EnableOverDrive();

if(ret != HAL_OK)

{

while(1){;}

}

RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK |    RCC_CLOCKTYPE_PCLK1 |         RCC_CLOCKTYPE_PCLK2);

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;

RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7);

if(ret != HAL_OK)

{

while(1){;}

}

}

//and 

//TIMER Settings for 5 us interrupt output 

 TIM_HandleTypeDef htim2 = {

.Instance = TIM2};

__HAL_RCC_TIM2_CLK_ENABLE();

htim9.Init.Prescaler = 99;

htim9.Init.CounterMode = TIM_COUNTERMODE_UP;

htim9.Init.Period = 9;

htim9.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

htim9.Init.RepetitionCounter = 0x00;

HAL_TIM_Base_Init(&htim2);

HAL_TIM_Base_Start_IT(&htim2);

HAL_NVIC_SetPriority(TIM2_IRQn, 0x00, 0x00);

HAL_NVIC_EnableIRQ(TIM2_IRQn);

//then for 1 second LED blink using 100.000 counter variable in following function;

void TIM2_IRQHandler()

{

second++;

HAL_TIM_IRQHandler(&htim2);

}

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)

{

if(second == 90.000)

{

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_SET);

}

if(second == 100.000)

{

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_RESET);

second = 0;

}

}

Led blinks 1 time in one second. Ok. 

//***But if I decrease the division factor to get 0.5 us -500 nanosecond- changing counter variable = 1.000.000 to get 1 second LED blink***

htim9.Init.Prescaler = 9;

htim9.Init.CounterMode = TIM_COUNTERMODE_UP;

htim9.Init.Period = 9;

//It slows down that around 2 sec/blink!!! and even if i continue to decrease Prescaler = under 9 or Period = under 9 the speed of LED blinking doesnt chance!!!

//I wisited hundreds of web pages and i read toushands of pages of documents but couldnt find any useful description or solution! I just found a trick in a document DM00224583 (RCC dedicated clocks configuration register (RCC_DCKCFGRx)) about APB1 and APB2 that their division must be 1 to conduct high speed frequency, but my setings are already same with that division 1!!! Since we will never be able to use it, why it is so fast this much 216 MHz?

//Could you help me how to generate 0.5 us interrupt with 216 MHz High speed MCU STM32F7xx????

17 REPLIES 17
AvaTar
Lead

> STM32F7xx is a 216 MHz ARM MCU But I Can Not Generate Even 0.5 microsecond Timer Interrupt!!!

Sorry, but the idea to have a 500ns interrupts speaks of your shallow understanding of this MCU, and embedded design.

> //I wisited hundreds of web pages and i read toushands of pages of documents but couldnt find any useful ...

Look for a webpage that describes the costs of an interrupt entry and exit (in clock cycles), and then calculate how much time your application spends in your questionable interrupt handler. And check the costs (time) of RMW access to a peripheral register, and a plain memory (RAM) cell.

Do high-frequency task in hardware, i.e. with approriate the peripherals - that's what they are designed for.

> void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)

> {

> if(second == 100.000)

> ...

> if(second == 200.000)

> ...

Divide your interrupt frequency by 100.000.

Consider why you can't get the TIM hardware to do the signalling at high rates.

Then do a disassembly of what you have the processor executing, and see why you've got it eating hundreds of cycles looping back and forth into the HAL libraries and callbacks. Perhaps look to code something a lot tighter on the IRQ Handler side.

Generally I'd keep the prescaler the smaller of the two terms, for short periods the prescaler of zero (DIV1) is recommended.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

AvaTar.. I appreciate your critisizm and explanations!

But your answer doesnt help me unfortinately!

////Look for a webpage that describes...... Divide your interrupt frequency by 100.000!

This means another thousands of pages and divide the prescalers by many various values of numbers from 0 to Infinity!..

thanks

S.Ma
Principal

https://en.wikipedia.org/wiki/ARM_Cortex-M

For basic info about interrupts and timings.

Live long and prosper

LMI2
Lead

"STM32F7xx is a 216 MHz ARM MCU" really means that there is maybe one flipflop toggling at that speed somewhere on the chip. Well, perhaps not really, but those CPUs are not really that fast.

MSERT
Associate II

It was so easy to generate microsecond or nanosecond in PICs even 8bit/16bit with robust working!!!

I'll move back to the poor PICs...

thank you

I m researching to fix them..

MSERT
Associate II

thanks KIC.

text indicates 12 instruction cycle latency at every overflow of TIM interrupt of cortex7, however i think it doesnt affect my code this much at its critical point that increase the cycle duration instead decrease two times; prescaler from 99 to 9!!! Right?