校准PH传感器

This commit is contained in:
xiaozhou233 committed 2026-07-16 17:55:43 +08:00
1 parent eef608b0d0
commit 86396545bd
1 file changed
+13 -10
+13 -10
View File
@@ -7,35 +7,38 @@
#include "ph.h"
#include <stddef.h>
static const float PH7_MV = 1810.0f;
static const float PH_SLOPE = 177.43f;
static const float PH_K = -0.005710f;
static const float PH_B = 14.0446f;
static const float ADC_VREF = 3.3f;
static const float ADC_MAX = 4096.0f;
static const float ADC_MAX = 4096.0f;
void PH_Init(void)
{
}
static float ph_offset = -1.2f;
void PH_Calc(uint16_t adc, PH_Data_t *out)
{
if(out == NULL) return;
float voltage = adc * (ADC_VREF / ADC_MAX);
out->voltage = voltage;
float mv = voltage * 1000.0f;
out->mv = mv;
float ph = 7.0f + (PH7_MV - mv) / PH_SLOPE;
ph += ph_offset;
float ph = PH_K * mv + PH_B;
if(ph < 0.0f)
ph = 0.0f;
if(ph > 14.0f)
ph = 14.0f;
if(ph < 0.0f) ph = 0.0f;
if(ph > 14.0f) ph = 14.0f;
out->ph = ph;
}