Shared NTC sampling + M2 continuous temperature report

This commit is contained in:
2026-10-09 23:56:58 +08:00
parent bae56ad6cb
commit 6d9f1f54a8
5 changed files with 112 additions and 9 deletions
+6
View File
@@ -61,6 +61,12 @@
*/
void command_process(void);
/**
* @brief M2 连续温度上报任务(在主循环中周期调用,主循环周期 10ms)。
* @details M2 使能后按设定间隔向 RS485 发送温度帧(格式同 M1 响应)。
*/
void command_report_task(void);
/**
* @brief 解析并处理完整的命令帧。
* @param frame 指向完整命令帧的缓冲区(从包头0xD5开始)。
+14 -5
View File
@@ -4,17 +4,26 @@
#include "gd32f4xx.h"
#include "board_config.h"
/* 后台采样周期(主循环 10ms 一圈的分频基准) */
#define NTC_SAMPLE_PERIOD_MS 100U
/**
* @brief 初始化 NTC 测温(PC5 模拟输入 + ADC0 常规通道,软件触发单次转换)。
*/
void ntc_init(void);
/**
* @brief 读取一次 NTC 温度(多次采样均值 + B 值公式换算)。
* @details 分压关系:V = VREF * R_ntc / (R_PULL + R_ntc)(硬件上拉在 VREF 侧,
* NTC 接 GND 侧),再由 B 值公式换算温度,单位摄氏度。
* @return 温度值(摄氏度,float)
* @brief NTC 后台采样任务:每 NTC_SAMPLE_PERIOD_MS 采样一次并更新全局最新温度。
* @details 在主循环中周期调用(主循环周期 10ms),内部按分频触发采样。
* 采样结果(含开路 -273.15 / 短路 -274.15 标记值)存入内部全局,
* 供 ntc_get_temperature() 读取——各消费者共享同一次采样,互不重复触发 ADC。
*/
float ntc_read_temperature(void);
void ntc_sample_task(void);
/**
* @brief 获取最新的 NTC 温度(后台采样值,非现场采样)。
* @return 温度值(摄氏度);-273.15 = 开路,-274.15 = 短路;上电未采样前初值为 -273.15。
*/
float ntc_get_temperature(void);
#endif // NTC_H