第一次修复

This commit is contained in:
刘正航
2026-04-16 17:17:53 +08:00
parent 609eb878d1
commit b39da5ed41
2 changed files with 12 additions and 2 deletions

View File

@@ -31,6 +31,7 @@ typedef struct
int64_t pv_pulse; // 当前的脉冲值 int64_t pv_pulse; // 当前的脉冲值
int64_t sv_pulse; // 电脑端的设定脉冲值 int64_t sv_pulse; // 电脑端的设定脉冲值
int64_t prev_pv_pulse;// 上一次脉冲值,用于检测过零点 int64_t prev_pv_pulse;// 上一次脉冲值,用于检测过零点
int32_t zero_counter; // 过零点步数计数器,每走一步+1或-1到STEP_PER_LAP翻转PA6
} MOTO_T; } MOTO_T;
extern MOTO_T g_tMoto; extern MOTO_T g_tMoto;

View File

@@ -55,6 +55,7 @@ void bsp_InitStepMoto(void)
g_tMoto.pv_pulse = 0; g_tMoto.pv_pulse = 0;
g_tMoto.sv_pulse = 0; g_tMoto.sv_pulse = 0;
g_tMoto.prev_pv_pulse = 0; g_tMoto.prev_pv_pulse = 0;
g_tMoto.zero_counter = 0;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -116,6 +117,7 @@ void MOTO_ZorePos(void)
g_tMoto.sv_pulse = 0; g_tMoto.sv_pulse = 0;
g_tMoto.pv_pulse = 0; g_tMoto.pv_pulse = 0;
g_tMoto.prev_pv_pulse = 0; g_tMoto.prev_pv_pulse = 0;
g_tMoto.zero_counter = 0;
GPIO_PORT_ZERO_SIG->BRR = GPIO_PIN_ZERO_SIG; // 归零时 PA6 输出低 GPIO_PORT_ZERO_SIG->BRR = GPIO_PIN_ZERO_SIG; // 归零时 PA6 输出低
BEEP_Start(1500, 5, 5, 3); BEEP_Start(1500, 5, 5, 3);
} }
@@ -199,14 +201,21 @@ void MOTO_ISR(void)
if (g_tMoto.pv_pulse < g_tMoto.sv_pulse) if (g_tMoto.pv_pulse < g_tMoto.sv_pulse)
{ {
g_tMoto.pv_pulse++; g_tMoto.pv_pulse++;
g_tMoto.zero_counter++;
} }
else if (g_tMoto.pv_pulse > g_tMoto.sv_pulse) else if (g_tMoto.pv_pulse > g_tMoto.sv_pulse)
{ {
g_tMoto.pv_pulse--; g_tMoto.pv_pulse--;
g_tMoto.zero_counter--;
} }
// 检测过零点pv_pulse 每跨越一个 STEP_PER_LAP即每转一圈翻转PA6 if (g_tMoto.zero_counter >= STEP_PER_LAP)
if ((g_tMoto.prev_pv_pulse / STEP_PER_LAP) != (g_tMoto.pv_pulse / STEP_PER_LAP))
{ {
g_tMoto.zero_counter -= STEP_PER_LAP;
ZERO_SIG_TOGGLE();
}
else if (g_tMoto.zero_counter <= -STEP_PER_LAP)
{
g_tMoto.zero_counter += STEP_PER_LAP;
ZERO_SIG_TOGGLE(); ZERO_SIG_TOGGLE();
} }
break; break;