altos: Compute igniter good/bad thresholds using 3.5V value
authorKeith Packard <keithp@keithp.com>
Sat, 22 Jul 2023 06:19:06 +0000 (23:19 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 22 Jul 2023 06:19:06 +0000 (23:19 -0700)
Instead of requiring each product to set the ADC values for good/bad
igniters, compute them based upon a 3.5V value using the ADC
characteristics already present in ao_pins.h.

This changes the threshold used on LPC parts from 400 (0.189V) to
7388.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/kernel/ao.h
src/kernel/ao_convert_volt.c

index b3f780f5c7609797c15c895e90b0fa965dcf1a44..edfbbb871de6416bdd0303bbe994b2215b39fd5d 100644 (file)
@@ -982,4 +982,26 @@ void ao_ms5607_init(void);
 
 #include <ao_arch_funcs.h>
 
+/*
+ * dv = (sensor * (p+m) * ref_dv)/ (max * m)
+ * value * (max * m) = (sensor * (p+m) * ref)
+ * value * (max * m) / ((p+m) * ref) = sensor
+ */
+
+#define AO_DV_MUL(p,m) ((int32_t) AO_ADC_MAX * (m))
+#define AO_DV_DIV(p,m) ((int32_t) AO_ADC_REFERENCE_DV * ((p) + (m)))
+#define AO_DV_ADD(p,m) (AO_DV_DIV(p,m) / 2)
+
+#define ao_decivolt_to_adc(dv, p, m) \
+       ((int16_t) (((int32_t) (dv) * AO_DV_MUL(p,m) + AO_DV_ADD(p,m)) / AO_DV_DIV(p,m)))
+
+#define AO_IGNITER_CLOSED_DV   35
+#define AO_IGNITER_OPEN_DV     10
+
+#undef AO_IGNITER_OPEN
+#undef AO_IGNITER_CLOSED
+
+#define AO_IGNITER_OPEN ao_decivolt_to_adc(AO_IGNITER_OPEN_DV, AO_IGNITE_DIV_PLUS, AO_IGNITE_DIV_MINUS)
+#define AO_IGNITER_CLOSED ao_decivolt_to_adc(AO_IGNITER_CLOSED_DV, AO_IGNITE_DIV_PLUS, AO_IGNITE_DIV_MINUS)
+
 #endif /* _AO_H_ */
index c5dfd22d0d6bcf6da48744fdee3e1a19c7b4bc38..1f04df64a98f174a14e193a1931d94041e979fba 100644 (file)
@@ -19,8 +19,8 @@
 #include "ao.h"
 
 #define MUL(p,m)       ((int32_t) AO_ADC_REFERENCE_DV * ((p) + (m)))
-#define ADD(p,m)       (MUL(p,m)/2)
 #define DIV(p,m)       ((int32_t) AO_ADC_MAX * (m))
+#define ADD(p,m)       (DIV(p,m) / 2)
 #define scale(v,p,m)   (((int32_t) (v) * MUL(p,m) + ADD(p,m)) / DIV(p,m))
 
 #if HAS_APRS || HAS_BATTERY_REPORT