uint16_t g_RotateEncoderOutput;
/***************************************************************************
*函数描述:两位增量式相对旋转编码器状态处理函数
*输入变量:uint8_t state,滤波后的编码器信号
*输出变量:g_RtoteEncoderOutput
***************************************************************************/
void RotateEncoder_StateProcess(uint8_t state)
{
static uint8_t prev_state = 0;
if(prev_state == 0)
{
if(state == 1)
{
g_RotateEncoderOutput++;
}
else if(state == 2)
{
g_RotateEncoderOutput--;
}
}
else if(prev_state == 1)
{
if(state == 3)
{
g_RotateEncoderOutput++;
}
else if(state == 0)
{
g_RotateEncoderOutput--;
}
}
else if(prev_state == 3)
{
if(state == 2)
{
g_RotateEncoderOutput++;
}
else if(state == 1)
{
g_RotateEncoderOutput--;
}
}
else if(prev_state == 2)
{
if(state == 0)
{
g_RotateEncoderOutput++;
}
else if(state == 3)
{
g_RotateEncoderOutput--;
}
}
prev_state = state;
}
作者: Qeecoda, 来源:面包板社区
链接: https://mbb.eet-china.com/blog/uid-me-1099225.html
版权声明:本文为博主原创,未经本人允许,禁止转载!
文章评论(0条评论)
登录后参与讨论