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
+19
View File
@@ -89,3 +89,22 @@ float ntc_read_temperature(void) {
float t_k = 1.0f / (1.0f / NTC_T25 + logf(r_ntc / NTC_R25) / (float)NTC_B_VALUE);
return t_k - 273.15f;
}
/******************************************************************************/
/* 后台采样 + 全局最新值:各消费者(debug 打印 / M1 / M2 上报)共享一次采样 */
/******************************************************************************/
static float s_ntc_last_temp = -273.15f; /* 最新温度(初值 = 开路标记) */
static uint16_t s_ntc_sample_divider = 0; /* 主循环 10ms 圈分频计数 */
void ntc_sample_task(void) {
/* 主循环周期 10ms:按 NTC_SAMPLE_PERIOD_MS 分频触发一次采样 */
if (++s_ntc_sample_divider >= (NTC_SAMPLE_PERIOD_MS / 10U)) {
s_ntc_sample_divider = 0;
s_ntc_last_temp = ntc_read_temperature();
}
}
float ntc_get_temperature(void) {
return s_ntc_last_temp;
}