Skip to main content
victagayun
Senior III
May 10, 2020
Solved

HAL_HRTIM_IRQHandler duration is very long

  • May 10, 2020
  • 12 replies
  • 3411 views

Hello I have NUCLEO-G474RE running at 170Mhz (24Mhz HSE [div 6] [mul 85] [div 2]) .

I am using Master and TimA $ TimC hrtimer as PWM for SMPS running at 100kHz (10uS).

I want to check how much available time for me if I interrupt every period and update the duty cycle using compare unit.

I add an IO to check the duration, it took around 7.44uS??

So that means I have only left around 2.65 uS for my code?

void HRTIM1_Master_IRQHandler(void)
{
 /* USER CODE BEGIN HRTIM1_Master_IRQn 0 */
 
 GPIOC->BSRR = (1<<10); // up
 
 /* USER CODE END HRTIM1_Master_IRQn 0 */
 HAL_HRTIM_IRQHandler(&hhrtim1,HRTIM_TIMERINDEX_MASTER);
 /* USER CODE BEGIN HRTIM1_Master_IRQn 1 */
 
 GPIOC->BSRR = (1<<26); // down +16
 
 /* USER CODE END HRTIM1_Master_IRQn 1 */
}

This topic has been closed for replies.
Best answer by berendi

> While CH3 (dark pink) is 7.64uS

> CH4 (dark blue) is 3.7uS

So the overhead is about 4 μs. Merge the second function into HRTIM1_Master_IRQHandler(), remove the call to HAL_HRTIM_IRQHandler(), clear the interrupt flag in HRTIM->MICR, and replace the call to __HAL_HRTIM_SETCOMPARE() with a direct write to the register (see the macro definition in the header). Now all references to &hhrtim1 should be gone from the interrupt handler. Repeat the measurement.

Untested code:

void HRTIM1_Master_IRQHandler(void)
{
 /* USER CODE BEGIN HRTIM1_Master_IRQn 0 */
 GPIOC->BSRR = (1<<10); // up
#if 0 
 /* USER CODE END HRTIM1_Master_IRQn 0 */
 HAL_HRTIM_IRQHandler(&hhrtim1,HRTIM_TIMERINDEX_MASTER);
 /* USER CODE BEGIN HRTIM1_Master_IRQn 1 */
#endif
 int32_t misr;
 misr = HRTIM1->sMasterRegs.MISR; // read interrupt status
 HRTIM1->sMasterRegs.MICR = misr; // clear all active interrupts
 if(misr & HRTIM_MISR_MREP) {
 int phase; // is the type correct?
 GPIOC->BSRR = (1<<11); // up
 phase = my_PID_Controller();
 CurrentPhase = phase;
 GPIOC->BSRR = (1<<27); // down +16
 HRTIM1->sMasterRegs.MCMP1R = phase; // don't access the (hopefully) volatile global variable again 
 }
 GPIOC->BSRR = (1<<26); // down +16
 /* USER CODE END HRTIM1_Master_IRQn 1 */
}

12 replies

berendi
Principal
May 29, 2020

Check the source of HAL_HRTIM_RepetitionEventCallback() in the HAL sources. What is in there?