Skip to main content
MYAQO.1
Associate II
January 3, 2021
Solved

HRTIM update using LL is too slow

  • January 3, 2021
  • 3 replies
  • 1942 views

Hi Everyone,

I am trying to run HRTIM Master unit with repetition interrupt and the repetition counter is 1. Now, when I am in interrupt I have to update compare and period registers and using LL to do so. But, within interrupt merely updating registers using

 LL_HRTIM_TIM_SetPeriod(HRTIM1, LL_HRTIM_TIMER_MASTER, PRD);

LL_HRTIM_TIM_SetCompare1(HRTIM1, LL_HRTIM_TIMER_MASTER, (0.5)*PRD);

takes around 2usec, which is a lot for my application. Any way to do it quicker?

This topic has been closed for replies.
Best answer by MYAQO.1

Solved:

Simply changing 0.5 to 1/2 reduced calc time to 1/4th.

Thank you so much!

3 replies

TDK
Super User
January 3, 2021

The fastest way is always going to be modifying the registers directly.

 HRTIM1->sMasterRegs->MPER = PRD;
 HRTIM1->sMasterRegs->MCMP1R = PRD / 2;

I'd be surprised if it's actually taking 2us though, if your clock speed is typical. If you have optimizations enabled, the LL commands may reduce to the direct register commands.

"If you feel a post has answered your question, please click ""Accept as Solution""."
MYAQO.1
MYAQO.1Author
Associate II
January 3, 2021

Thank you , I will try direct reg, but I am also surprised at LL being that slow. There must be something that I am missing. The clock is 172 MHz and I am using STM32G474 with FPU. I have just been migrated to STM32 and still trying to figure things out.

TDK
Super User
January 3, 2021
How exactly are you measuring how long it takes? Best way is with an access to DWT->CYCCNT before and after, but it needs enabled first.
"If you feel a post has answered your question, please click ""Accept as Solution""."
Piranha
Principal III
January 3, 2021
(0.5)*PRD

This is a multiplication of double type. Not even a single precision float! Therefore, if the CPU has no hardware support for double type or it is not turned on, the calculation will be done with integer math in software, which will make it very slow.

MYAQO.1
MYAQO.1Author
Associate II
January 3, 2021

I am using STM32G474 and turned FPU ON. I have another equation with division and multiplication in IR which goes pretty past (relatively).

0693W000006HLLcQAO.png

MYAQO.1
MYAQO.1AuthorAnswer
Associate II
January 3, 2021

Solved:

Simply changing 0.5 to 1/2 reduced calc time to 1/4th.

Thank you so much!