mirror of
https://github.com/xiaozhou233/RiverWaterQualityMonitoring.git
synced 2026-12-05 13:05:53 +08:00
校准PH传感器
This commit is contained in:
1 parent
eef608b0d0
commit
86396545bd
1 file changed
+13
-10
@@ -7,35 +7,38 @@
|
|||||||
#include "ph.h"
|
#include "ph.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
static const float PH7_MV = 1810.0f;
|
static const float PH_K = -0.005710f;
|
||||||
|
static const float PH_B = 14.0446f;
|
||||||
static const float PH_SLOPE = 177.43f;
|
|
||||||
|
|
||||||
static const float ADC_VREF = 3.3f;
|
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)
|
void PH_Init(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static float ph_offset = -1.2f;
|
|
||||||
|
|
||||||
void PH_Calc(uint16_t adc, PH_Data_t *out)
|
void PH_Calc(uint16_t adc, PH_Data_t *out)
|
||||||
{
|
{
|
||||||
if(out == NULL) return;
|
if(out == NULL) return;
|
||||||
|
|
||||||
float voltage = adc * (ADC_VREF / ADC_MAX);
|
float voltage = adc * (ADC_VREF / ADC_MAX);
|
||||||
|
|
||||||
out->voltage = voltage;
|
out->voltage = voltage;
|
||||||
|
|
||||||
float mv = voltage * 1000.0f;
|
float mv = voltage * 1000.0f;
|
||||||
|
|
||||||
out->mv = mv;
|
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;
|
out->ph = ph;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user