//使用限幅消抖 //
//vesion1.0 //
//2021.12.03 //
#define n_OPTIMIZE_OFFSET 1//优化偏差
#define n_OPTIMIZE_COMPARE_TIME 10 //比较的次数
typedef volatile unsigned char BYTE;
void TSK_DEAL();//主任务
BYTE RUNNING_TARGET_OPTIMIZE();
void CLEAR_OPTIMIZE();
BYTE D_input;
BYTE D_target;
BYTE D_optimizeLessCnt;
BYTE D_optimizeMoreCnt;
void TSK_DEAL()//主任务
{
if(RUNNING_TARGET_OPTIMIZE())
{
D_target = D_input;
CLEAR_OPTIMIZE();
}
}
BYTE RUNNING_TARGET_OPTIMIZE()
{
BYTE f=0;
if(D_target > D_input)//目标值大于输入
{
if(D_target > (D_input+n_OPTIMIZE_OFFSET))
{
if(D_optimizeMoreCnt < n_OPTIMIZE_COMPARE_TIME)D_optimizeMoreCnt++;
else f=1;
}
D_optimizeLessCnt=0;
}
else if(D_input < D_target)//目标值小于于输入
{
if((D_input+n_OPTIMIZE_OFFSET) < D_target))
{
if(D_optimizeLessCnt < n_OPTIMIZE_COMPARE_TIME)D_optimizeLessCnt++;
else f=1;
}
D_optimizeMoreCnt=0;
}
else
{
D_optimizeLessCnt=0;
D_optimizeMoreCnt=0;
}
return f;
}
void CLEAR_OPTIMIZE()
{
D_optimizeLessCnt=0;
D_optimizeMoreCnt=0;
}
滤波-限幅消抖
最新推荐文章于 2024-04-25 17:11:03 发布