feat(ADC): 重构ADC采样系统以支持同步电流采集
- 将ADC缓冲区从6通道减少到3通道,专门用于MCU温度、DRV温度和VBUS监测 - 实现了注入组ADC同步采样,通过TIMER1 TRGO触发三相电流同时采样 - 添加了PWM中心对齐模式以提供更好的采样窗口 - 在FOC控制器中增加了ADC错误检查和三相公共模偏置消除 - 优化了电流采样更新机制,使用中断驱动的数据搬运 - 调整了ADC通道配置,规则组用于后台温度/VBUS采样,注入组用于PWM同步电流采样
This commit is contained in:
@@ -17,7 +17,7 @@ extern angle_sensor KTH7823;
|
||||
extern CAN_transmiter CAN0_transmiter;
|
||||
extern EncoderVelocityKalman Vel_kalman; // 速度滤波
|
||||
extern CurrentKalman Current_kalman;
|
||||
extern u16 adc_value[6]; // ADC DMA缓冲区,用于快速电压检测
|
||||
extern u16 adc_value[3]; // regular DMA缓冲区:MCU温度 / DRV温度 / VBUS
|
||||
|
||||
// 初始变量及函数定义
|
||||
#define _constrain(amt, low, high) \
|
||||
@@ -52,6 +52,17 @@ void calibrate_zero_position(void) {
|
||||
// 通过Ia,Ib,Ic计算Iq,Id(目前仅输出Iq)
|
||||
inline float FOC_Controller::cal_Iq_Id(float current_a, float current_b,
|
||||
float current_c) {
|
||||
if (current_a == ERROR_ADC_VAL || current_b == ERROR_ADC_VAL ||
|
||||
current_c == ERROR_ADC_VAL) {
|
||||
return Current_kalman.getCurrent();
|
||||
}
|
||||
|
||||
// 去除三相公共模偏置,使 Ia + Ib + Ic 更接近 0
|
||||
const float current_avg = (current_a + current_b + current_c) / 3.0f;
|
||||
current_a -= current_avg;
|
||||
current_b -= current_avg;
|
||||
current_c -= current_avg;
|
||||
|
||||
// 计算电气角度
|
||||
float angle_el = fmod(shaft_angle * PP - KTH7823.calibration_angle, 360.0f);
|
||||
|
||||
@@ -351,8 +362,8 @@ void FOC_Controller::update_power(float voltage) {
|
||||
* - VBUS_DEBOUNCE_COUNT: 防抖计数 (默认5次)
|
||||
*/
|
||||
void FOC_Controller::fast_voltage_check(void) {
|
||||
// 直接从DMA缓冲区读取最新ADC值(通道5是Vbus)
|
||||
float current_vbus = adc_value[5] * (3.3f / 4096.0f) * 11.0f;
|
||||
// 直接从DMA缓冲区读取最新ADC值(regular rank2 是 VBUS)
|
||||
float current_vbus = adc_value[2] * (3.3f / 4096.0f) * 11.0f;
|
||||
|
||||
// 更新基准电压(峰值检测)
|
||||
// 电压上升时,基准电压跟随;电压下跌时,基准电压保持
|
||||
|
||||
Reference in New Issue
Block a user