2025-09-01 10:53 AM
I did not understand the significance of the number 65536 in the below code
pHandle->OvfFreq = (uint16_t)(pHandle->TIMClockFreq / 65536U);
/* Set fixed to 150 ms */
pHandle->HallTimeout = 150U;
/* Compute the prescaler to the closet value of the TimeOut (in mS )*/
pHandle->HALLMaxRatio = (pHandle->HallTimeout * pHandle->OvfFreq) / 1000U ;
/* Align MaxPeriod to a multiple of Overflow.*/
pHandle->MaxPeriod = pHandle->HALLMaxRatio * 65536UL;
My main confusion is how the OvfFreq with division of 65536 help the code to reduce the calculations. According to my understanding if TIMClockFreq = 170MHz then the time is T = 1/170Mhz i get overflow after 65535, so if the number of overflows are OverflowCnt then the total time elapsed will be 65535*1/170MHz*OverflowCnt + Input capture timer registers.