Files
Motor_v2/Robot_V2/device/adc.h
T
cbb 76f7987238 feat(FOC): 实现电角度零位自动校准并修复ADC采样干扰问题
- 新增FlashEEPROM用于保存零位校准角,掉电不丢失
- 实现安全的零位校准算法:运行中禁止校准、对齐后重新采样、保存到Flash
- 重构ADC架构:分离ADC0(PWM同步电流采样)和ADC1(VBUS/DRV温度轮询)
- 解决ADC采样冲突:移除ADC0的regular连续扫描,避免与注入组抢占资源
- 修复VBUS电压读取错误:从DMA缓冲区改为直接ADC1单次转换
- 修正开环控制Uq幅值限幅逻辑,保留符号避免反转时抖动
- 更新CAN协议:电流数据改为有符号16位打包,支持负电流传输
- 调整版本号至v26.8.16.7
2026-08-16 02:13:37 +08:00

111 lines
2.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @file device/adc.h
* @brief 底层设备驱动与外设封装源文件
* @note 本文件仅补充 Doxygen 文档注释,不改变代码逻辑。
*/
#ifndef _ADC_H
#define _ADC_H
#ifdef __cplusplus
extern "C" {
#endif
#include "config.h"
/**
* @brief sampler 类或结构体
*/
class sampler {
private:
float vbus_samples[ADC_FILTER_SIZE];
float currU_samples[ADC_FILTER_SIZE];
float currV_samples[ADC_FILTER_SIZE];
float currW_samples[ADC_FILTER_SIZE];
float mcu_temp_samples[ADC_FILTER_SIZE];
float drv_temp_samples[ADC_FILTER_SIZE];
u8 current_sample_head;
u8 temp_vbus_head; // 环形缓冲区 head
u8 mcu_temp_head;
u8 drv_temp_head;
float tempora_sample;
float cached_mcu_temp; // getter 缓存
float cached_drv_temp;
float cached_vbus;
public:
/**
* @brief 初始化对象或模块
* @return u8 返回值
*/
u8 init(void);
/**
* @brief 更新 mcu_temp 相关状态
* @return void
*/
void update_mcu_temp(void);
/**
* @brief 更新 drv_temp 相关状态
* @return void
*/
void update_drv_temp(void);
/**
* @brief 更新 vbus_voltage 相关状态
* @return void
*/
void update_vbus_voltage(void);
/**
* @brief 更新 current 相关状态
* @return void
*/
void update_current(void);
/**
* @brief 获取 get_mcu_temp 对应的数据或状态
* @return float 返回值
*/
float get_mcu_temp(void);
/**
* @brief 获取 get_drv_temp 对应的数据或状态
* @return float 返回值
*/
float get_drv_temp(void);
/**
* @brief 获取 get_vbus_voltage 对应的数据或状态
* @return float 返回值
*/
float get_vbus_voltage(void);
/**
* @brief 获取 get_current 对应的数据或状态
* @param[in] char 参数
* @return float 返回值
*/
float get_current(char);
};
/**
* @brief ADC0_1_IRQHandler 中断处理函数
* @return void
*/
void ADC0_1_IRQHandler(void);
/**
* @brief ADC1 初始化(VBUS / DRV温度 专用,单通道单次软件触发)
* @return void
*/
void adc1_config(void);
/**
* @brief ADC1 单次软件触发转换并等待完成(仅主循环任务上下文调用)
* @param[in] channel ADC 通道号(ADC_CHANNEL_6 / ADC_CHANNEL_9)
* @return u16 转换原始值
*/
u16 adc1_read_raw(u8 channel);
#ifdef __cplusplus
}
#endif
#endif