From 86396545bd76950052cd4bd311eec13b949aa7d3 Mon Sep 17 00:00:00 2001 From: xiaozhou233 Date: Thu, 16 Jul 2026 17:55:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=A1=E5=87=86PH=E4=BC=A0=E6=84=9F=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stm32f103c8t6/Core/Drivers/PH/ph.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/stm32f103c8t6/Core/Drivers/PH/ph.c b/stm32f103c8t6/Core/Drivers/PH/ph.c index 2ca5d0e..b22a3b7 100644 --- a/stm32f103c8t6/Core/Drivers/PH/ph.c +++ b/stm32f103c8t6/Core/Drivers/PH/ph.c @@ -7,35 +7,38 @@ #include "ph.h" #include -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; }