cancel
Showing results for 
Search instead for 
Did you mean: 

HRTIM update using LL is too slow

MYAQO.1
Associate II

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?

1 ACCEPTED SOLUTION

Accepted Solutions
MYAQO.1
Associate II

Solved:

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

Thank you so much!

View solution in original post

7 REPLIES 7
TDK
Guru

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".
Piranha
Chief II
(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.

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.

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
Associate II

Solved:

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

Thank you so much!

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".

It's not exact but gives a good idea. I toggle the pin at the start and end of the ISR and check the pin on the scope.