summaryrefslogtreecommitdiffstats
path: root/stm32/app/pressure.c
diff options
context:
space:
mode:
Diffstat (limited to 'stm32/app/pressure.c')
-rw-r--r--stm32/app/pressure.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/stm32/app/pressure.c b/stm32/app/pressure.c
new file mode 100644
index 0000000..6b90d93
--- /dev/null
+++ b/stm32/app/pressure.c
@@ -0,0 +1,79 @@
+#include "project.h"
+
+#define PRESSURE GPIO0
+#define PRESSURE_PORT GPIOA
+#define PRESSURE_CHANNEL ADC_CHANNEL0
+#define VREF_CHANNEL ADC_CHANNEL17
+
+static unsigned poke;
+
+static int pressure;
+
+uint16_t pressure_ch (void)
+{
+ return pressure;
+}
+
+
+
+
+void pressure_tick (void)
+{
+ static unsigned ticker;
+
+ ticker++;
+
+ if (ticker < MS_TO_TICKS (2500))
+ return;
+
+ ticker = 0;
+ poke = 1;
+
+}
+
+
+
+
+void pressure_dispatch (void)
+{
+ int v, r;
+
+ if (!poke) return;
+
+ poke = 0;
+
+ if (adc_calibrate()) {
+ pressure = 0;
+ return;
+ }
+
+ v = adc_convert (PRESSURE_CHANNEL);
+ r = adc_convert (VREF_CHANNEL);
+
+
+ /* r is 1.25 volts, transducer is 0.5V -> 0 psi 4.5V -> 100psi */
+ /* 100psi is 6.8947573 bar, and we want 256ths of bar */
+
+ if (!r) {
+ pressure = 0;
+ return;
+ }
+
+ pressure = ((v * 552) / r) - 221;
+
+ if (pressure < 0) pressure = 0;
+
+ printf ("QP: %d %d %d\r\n", v, r, (pressure * 100) / 256);
+
+}
+
+
+
+void pressure_init (void)
+{
+ MAP_ANALOG (PRESSURE);
+}
+
+
+
+