stm8低速时钟校准问题 stm8L10x标准库例程里的这个时钟校准函数一直不理解,求详解啊,一直不理解例程里的低速时钟校准 函数如下: /** * @brief Update APR register with the measured LSI frequency. * @note AWU must be disabled to avoid unwanted interrupts. * @note Prescaler calculation: * A is the integer part of LSIFreqkHz/4 and x the decimal part. * x <= A/(1+2A) is equivalent to A >= x(1+2A) * and also to 4A >= 4x(1+2A) [F1] * but we know that A + x = LSIFreqkHz/4 ==> 4x = LSIFreqkHz-4A * so [F1] can be written : * 4A >= (LSIFreqkHz-4A)(1+2A) * @param LSIFreqHz Low Speed RC frequency measured by timer (in Hz). * @retval None */ void AWU_LSICalibrationConfig(uint32_t LSIFreqHz) { uint16_t lsifreqkhz = 0x0; uint16_t A = 0x0; /* Check parameter */ assert_param(IS_LSI_FREQUENCY(LSIFreqHz)); lsifreqkhz = (uint16_t)(LSIFreqHz / 1000); /* Converts value in kHz */ /* Calculation of AWU calibration value */ A = (uint16_t)(lsifreqkhz >> 2U); /* Division by 4, keep integer part only */ if ((4U * A) >= ((lsifreqkhz - (4U * A)) *(1U + (2U * A)))) { AWU->APR = (uint8_t)(A - 2U); } else { AWU->APR = (uint8_t)(A - 1U); } } |
好吧~我想搞清楚
现在理解了?能说一下吗