#include <MyProject.h>


/**
    @brief        对变量取32位的绝对值
    @param[in]    value
    @return       绝对值
    @date         2022-07-13
*/
uint32_t Abs_F32(int32_t value)
{
    if (value < 0)
    { return (-value); }
    else
    { return (value); }
}


Input_Capture_t xdata inputCapture;

/**
    @function     Input_Capture_Calc
    @brief        输入捕获计算 频率与占空比
    @date         2025-11-21
*/
void Input_Capture_Calc(void)
{
    if (inputCapture.UpdateFlag)
    {
        if ((Abs_F32(inputCapture.TimerDROld - inputCapture.TimerDR) < 0xFF) &&
            (Abs_F32(inputCapture.TimerARROld - inputCapture.TimerARR) < 0xFF))
        {
            inputCapture.OutFreq = DivQ_L_MDU(0x0478, 0x68C0, inputCapture.TimerARR);
            inputCapture.OutDuty = (float)1000 * inputCapture.TimerDR / inputCapture.TimerARR;
        }
        
        inputCapture.UpdateFlag = 0;
        inputCapture.TimerDROld = inputCapture.TimerDR;
        inputCapture.TimerARROld = inputCapture.TimerARR;
    }
}