ADC已完成

This commit is contained in:
cbb
2025-10-02 02:52:07 +08:00
parent 6f89355a8a
commit 20fbb30067
19 changed files with 424 additions and 258 deletions
+6 -4
View File
@@ -1,4 +1,5 @@
#include "adc.h"
#include <cstdio>
#include <stdint.h>
#include "math.h"
@@ -11,10 +12,11 @@ constexpr float MAX_TEMP = 150.0f;
constexpr float MIN_TEMP = -40.0f;
constexpr float MAX_CURRENT = 50.0f;
constexpr float MIN_CURRENT = -0.1f;
constexpr float MAX_VCC = 40.0f;
constexpr float MIN_VCC = 0.0f;
constexpr float MAX_VCC = 65.0f;
constexpr float MIN_VCC = -0.1f;
extern const u16 adc_value[7];
u16 adc_value[7] = {0}; // 显式初始化数组元素为0
/**
* @brief 获取MCU温度
@@ -103,7 +105,7 @@ float get_vbus_voltage() {
vcc_latest = adc_value[6] * ADC_SCALE * VCC_FACTOR;
// 检查电压读数是否在有效范围内
if (vcc_latest > MAX_VCC || vcc_latest < MAX_VCC) {
if (vcc_latest > MAX_VCC || vcc_latest < MIN_VCC) {
return ERROR_ADC_VAL;
}
}