一:增加了纹波滤波,当纹波板有电阻时打开辅助继电器应该为3帧过冲,使用五次过滤可以消除异常纹波
二、修改了负载启动的顺序,先开启辅助继电器使地相通,再开启D+D-继电器 feat: 发布V1.1.23版本,优化负载初始化继电器时序 - 更新所有头文件版本号至V1.1.21~V1.1.23,协议板固件版本更新为0x0127 - 新增纹波滤波相关宏定义与函数,实现继电器闭合后纹波过滤 - 调整负载初始化流程:先下发辅助继电器,等待回码后延迟30ms再打开北向继电器 - 优化D+/D-寄存器上位机显示单位,适配0.001V解析格式 - 补充YMODEM升级文档说明,完善传输校验与重发规则 - 清理冗余调试打印与Allegro工程日志文件
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_eload.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
当前版本号 : V1.1.22
|
||||
主要功能 : 源载命令数据解析,封装,读写请求。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
@@ -20,6 +20,14 @@
|
||||
#include "chrg_south.h"
|
||||
|
||||
#define ELOAD_VALID_VOLTAGE_MIN_MV 2000U
|
||||
#define DPDM_HOST_READ_SCALE 10U
|
||||
|
||||
static rt_uint16_t chrg_eload_dpdm_host_value(rt_uint16_t value)
|
||||
{
|
||||
rt_uint32_t scaled_value = (rt_uint32_t)value * DPDM_HOST_READ_SCALE;
|
||||
|
||||
return (scaled_value > 0xFFFFU) ? 0xFFFFU : (rt_uint16_t)scaled_value;
|
||||
}
|
||||
|
||||
extern void LCD_SHOW(rt_uint8_t idx, struct eload_p1_t *pP1, struct chrg_eload_t *pLOAD, struct chrg_switch_t *pSW, rt_uint8_t online);
|
||||
|
||||
@@ -41,9 +49,104 @@ rt_uint32_t chrg_eload_get_sample_seq(rt_uint8_t idx)
|
||||
}
|
||||
return g_eload_sample_seq[idx];
|
||||
}
|
||||
static rt_uint16_t ripple_base[TOTAL_SOU_CHS] = {0};
|
||||
static rt_uint8_t ripple_cal_flag[TOTAL_SOU_CHS] = {0};
|
||||
rt_uint16_t real_ripple[TOTAL_SOU_CHS] = {0};
|
||||
typedef struct {
|
||||
rt_uint16_t samples[RIPPLE_MEDIAN_WINDOW_SIZE];
|
||||
rt_uint16_t filtered_value;
|
||||
rt_uint8_t sample_count;
|
||||
rt_uint8_t sample_next;
|
||||
rt_uint8_t ignore_count;
|
||||
rt_uint8_t ignore_total;
|
||||
rt_tick_t relay_start_tick;
|
||||
rt_uint32_t frame_count;
|
||||
rt_bool_t relay_started;
|
||||
} chrg_ripple_filter_t;
|
||||
|
||||
static chrg_ripple_filter_t g_ripple_filter[TOTAL_SOU_CHS] = {0};
|
||||
|
||||
static rt_uint16_t chrg_eload_ripple_median(rt_uint16_t value0,
|
||||
rt_uint16_t value1, rt_uint16_t value2)
|
||||
{
|
||||
if (value0 > value1) {
|
||||
rt_uint16_t temp = value0;
|
||||
value0 = value1;
|
||||
value1 = temp;
|
||||
}
|
||||
if (value1 > value2) {
|
||||
rt_uint16_t temp = value1;
|
||||
value1 = value2;
|
||||
value2 = temp;
|
||||
}
|
||||
if (value0 > value1) {
|
||||
value1 = value0;
|
||||
}
|
||||
return value1;
|
||||
}
|
||||
|
||||
static rt_uint16_t chrg_eload_ripple_filter_update(rt_uint8_t idx,
|
||||
rt_uint16_t raw_value)
|
||||
{
|
||||
chrg_ripple_filter_t *pFilter = &g_ripple_filter[idx];
|
||||
|
||||
pFilter->frame_count++;
|
||||
|
||||
if (pFilter->ignore_count > 0U) {
|
||||
pFilter->ignore_count--;
|
||||
return pFilter->filtered_value;
|
||||
}
|
||||
pFilter->samples[pFilter->sample_next] = raw_value;
|
||||
pFilter->sample_next = (pFilter->sample_next + 1U) % RIPPLE_MEDIAN_WINDOW_SIZE;
|
||||
if (pFilter->sample_count < RIPPLE_MEDIAN_WINDOW_SIZE) {
|
||||
pFilter->sample_count++;
|
||||
}
|
||||
if (pFilter->sample_count < RIPPLE_MEDIAN_WINDOW_SIZE) {
|
||||
pFilter->filtered_value = raw_value;
|
||||
} else {
|
||||
pFilter->filtered_value = chrg_eload_ripple_median(
|
||||
pFilter->samples[0], pFilter->samples[1], pFilter->samples[2]);
|
||||
}
|
||||
return pFilter->filtered_value;
|
||||
}
|
||||
|
||||
void chrg_eload_ripple_filter_reset(rt_uint8_t idx)
|
||||
{
|
||||
chrg_ripple_filter_t *pFilter;
|
||||
|
||||
if (idx >= TOTAL_SOU_CHS) {
|
||||
return;
|
||||
}
|
||||
pFilter = &g_ripple_filter[idx];
|
||||
pFilter->sample_count = 0U;
|
||||
pFilter->sample_next = 0U;
|
||||
pFilter->ignore_count = (rt_uint8_t)RIPPLE_RELAY_IGNORE_P1_COUNT;
|
||||
pFilter->ignore_total = pFilter->ignore_count;
|
||||
}
|
||||
|
||||
void chrg_eload_ripple_filter_relay_start(rt_uint8_t idx)
|
||||
{
|
||||
chrg_ripple_filter_t *pFilter;
|
||||
|
||||
if (idx >= TOTAL_SOU_CHS) {
|
||||
return;
|
||||
}
|
||||
pFilter = &g_ripple_filter[idx];
|
||||
chrg_eload_ripple_filter_reset(idx);
|
||||
pFilter->relay_start_tick = rt_tick_get();
|
||||
pFilter->frame_count = 0U;
|
||||
pFilter->relay_started = RT_TRUE;
|
||||
}
|
||||
|
||||
void chrg_eload_ripple_filter_relay_stop(rt_uint8_t idx)
|
||||
{
|
||||
chrg_ripple_filter_t *pFilter;
|
||||
|
||||
if (idx >= TOTAL_SOU_CHS) {
|
||||
return;
|
||||
}
|
||||
pFilter = &g_ripple_filter[idx];
|
||||
pFilter->relay_started = RT_FALSE;
|
||||
pFilter->relay_start_tick = 0U;
|
||||
pFilter->frame_count = 0U;
|
||||
}
|
||||
|
||||
/* ======================== Ymodem 升级应答缓存 ======================== */
|
||||
static rt_uint8_t g_eload_ymodem_resp = 0; // 南向返回的ymodem应答字节(0=无应答)
|
||||
@@ -360,7 +463,8 @@ int chrg_eload_parse (rt_uint8_t idx, rt_uint8_t pt, rt_uint8_t *data, rt_uint16
|
||||
pLOAD->vpkp = swap_u16(pP1->Vpkp);
|
||||
pLOAD->vpkn = swap_u16(pP1->Vpkn);
|
||||
pLOAD->vpp = swap_u16(pP1->Vpp);
|
||||
pLOAD->Ripple = swap_u16(pP1->Ripple);
|
||||
pLOAD->Ripple = chrg_eload_ripple_filter_update(idx,
|
||||
swap_u16(pP1->Ripple));
|
||||
/* 保留功率板返回的真实电流,供卸载保护判断使用。 */
|
||||
pSW->Now_current = pLOAD->current;
|
||||
/*
|
||||
@@ -374,6 +478,7 @@ int chrg_eload_parse (rt_uint8_t idx, rt_uint8_t pt, rt_uint8_t *data, rt_uint16
|
||||
pLOAD->vpkn = 0;
|
||||
pLOAD->vpp = 0;
|
||||
pLOAD->Ripple = 0;
|
||||
chrg_eload_ripple_filter_reset(idx);
|
||||
pSW->VZ = 0;
|
||||
pSW->VF = 0;
|
||||
}
|
||||
@@ -415,8 +520,11 @@ int chrg_eload_parse (rt_uint8_t idx, rt_uint8_t pt, rt_uint8_t *data, rt_uint16
|
||||
usRegHoldBuf[HOLD_REG_CH0_VPKN+idx*TOTAL_HOLD_CH_REGS] = pLOAD->vpkn;
|
||||
usRegHoldBuf[HOLD_REG_CH0_VPP+idx*TOTAL_HOLD_CH_REGS] = pLOAD->vpp;
|
||||
usRegHoldBuf[HOLD_REG_CH0_Ripple+idx*TOTAL_HOLD_CH_REGS] = pLOAD->Ripple;
|
||||
usRegHoldBuf[HOLD_REG_CH0_VZ+idx*TOTAL_HOLD_CH_REGS] = pSW->VZ;
|
||||
usRegHoldBuf[HOLD_REG_CH0_VF+idx*TOTAL_HOLD_CH_REGS] = pSW->VF;
|
||||
/* 上位机D+/D-寄存器按0.001V解释,内部/LCD仍保持0.01V原始值。 */
|
||||
usRegHoldBuf[HOLD_REG_CH0_VZ+idx*TOTAL_HOLD_CH_REGS] =
|
||||
chrg_eload_dpdm_host_value(pSW->VZ);
|
||||
usRegHoldBuf[HOLD_REG_CH0_VF+idx*TOTAL_HOLD_CH_REGS] =
|
||||
chrg_eload_dpdm_host_value(pSW->VF);
|
||||
// rt_kprintf("---------NOW VOLT END = %d\n----------",pSW->Now_voltage);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user