2021-01-03 04:24 AM
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?
Solved! Go to Solution.
2021-01-03 09:22 AM
Solved:
Simply changing 0.5 to 1/2 reduced calc time to 1/4th.
Thank you so much!
2021-01-03 07:22 AM
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.
2021-01-03 07:36 AM
(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.
2021-01-03 07:44 AM
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.
2021-01-03 07:47 AM
I am using STM32G474 and turned FPU ON. I have another equation with division and multiplication in IR which goes pretty past (relatively).
2021-01-03 09:22 AM
Solved:
Simply changing 0.5 to 1/2 reduced calc time to 1/4th.
Thank you so much!
2021-01-03 09:47 AM
2021-01-03 09:49 AM
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.