新手入门
- 积分
- 12
- 金钱
- 12
- 注册时间
- 2022-6-29
- 在线时间
- 3 小时
|
1金钱
过零检测理论上只要检测非导通相的过零即可,但示例代码却同时检测3相的过零信号,导通相高端是PWM信号,用比较器比较中性点应该不是稳定电平,如何时刻都会有两项导通,那程序怎么能跑到速度计算这里?uint8_t hallless_sw(void)
{
u8 i;
static uint8_t edge_flag = 0; /* 过零信号稳定标志 */
count_j++; /* 运行过程时间计数 18K的中断频率为单位 */
/* 过零信号滤波 */
g_hallless_three.Queue_Status[0] = g_hallless_three.Queue_Status[0] << 1;
g_hallless_three.Queue_Status[1] = g_hallless_three.Queue_Status[1] << 1;
g_hallless_three.Queue_Status[2] = g_hallless_three.Queue_Status[2] << 1;
/* 检测过零点 */
g_hallless_three.Queue_Status[0] |= HAL_GPIO_ReadPin(HALL1_TIM_CH1_GPIO, HALL1_TIM_CH1_PIN); /* U相过零点 */
g_hallless_three.Queue_Status[1] |= HAL_GPIO_ReadPin(HALL1_TIM_CH2_GPIO, HALL1_TIM_CH2_PIN); /* V相过零点 */
g_hallless_three.Queue_Status[2] |= HAL_GPIO_ReadPin(HALL1_TIM_CH3_GPIO, HALL1_TIM_CH3_PIN); /* W相过零点 */
/* 过零信号U */
g_hallless_three.Filter_Math = g_hallless_three.Queue_Status[0] & FILTER_LONG;
if (g_hallless_three.Filter_Math == FILTER_LONG) /* 稳定获取到过零信号都是1,代表实际过零信号就为1 */
{
g_hallless_three.QFilter_Status[0] = 1;
}
else if (g_hallless_three.Filter_Math == 0x00) /* 稳定获取到过零信号都是0,代表实际过零信号就为0 */
{
g_hallless_three.QFilter_Status[0] = 0;
}
else
{
g_hallless_three.Filter_Count++;
return 0; //
}
/* 过零信号V */
g_hallless_three.Filter_Math = g_hallless_three.Queue_Status[1] & FILTER_LONG;
if (g_hallless_three.Filter_Math == FILTER_LONG)
{
g_hallless_three.QFilter_Status[1] = 1;
}
else if (g_hallless_three.Filter_Math == 0x00)
{
g_hallless_three.QFilter_Status[1] = 0;
}
else
{
g_hallless_three.Filter_Count++;
return 0;
}
/* 过零信号W */
g_hallless_three.Filter_Math = g_hallless_three.Queue_Status[2] & FILTER_LONG;
if (g_hallless_three.Filter_Math == FILTER_LONG)
{
g_hallless_three.QFilter_Status[2] = 1;
}
else if (g_hallless_three.Filter_Math == 0x00)
{
g_hallless_three.QFilter_Status[2] = 0;
}
else
{
g_hallless_three.Filter_Count++;
return 0;
}
/************************************** 速度计算 ***************************************/
g_hallless_three.Filter_Edge = uemf_edge(g_hallless_three.QFilter_Status[0]);
if (g_hallless_three.Filter_Edge == 0) /* 统计过零信号的高电平时间 */
{
/* 延迟30°换相,因为硬件上低通滤波器和软件延迟的原因,实际延迟角度需小于30° */
if (count_i >= 4) /* 稳定检测到过零信号才对速度进行测量 */
{
if (g_bldc_motor1.dir == CCW)
g_hallless_three.Speed_RPM = ((uint32_t)SPEED_COEFF / count_j);
else
g_hallless_three.Speed_RPM = -((uint32_t)SPEED_COEFF / count_j);
FirstOrderRC_LPF(g_bldc_motor1.speed, g_hallless_three.Speed_RPM, 0.2379);
}
g_hallless_three.Filter_Delay = count_j / 6; /* 30°所需时间,理论值,实际应小于30° */
g_hallless_three.Filter_Count = 0;
count_j = 0; /* 清空时间,以便下一次计算速度 */
count_i++; /* 捕捉过零点,累计次数 */
}
if (g_hallless_three.Filter_Edge == 1)
{
g_hallless_three.Filter_Count = 0;
count_j = 0;
}
if (g_hallless_three.Filter_Edge == 2) /* 过零信号没变化 */
{
g_hallless_three.Filter_Count++; /* 不换相时间累计 超时则判定速度为0 */
if (g_hallless_three.Filter_Count > 15000)
{
g_hallless_three.Filter_Count = 0;
g_hallless_three.Speed_RPMF = 0; /* 超时换向 判定为停止 速度为0 */
}
}
/************************************** 过零控制 ***************************************/
|
-
|