summaryrefslogtreecommitdiffstats
path: root/pressure_control/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'pressure_control/firmware')
-rw-r--r--pressure_control/firmware/main.c27
-rw-r--r--pressure_control/firmware/main.h6
-rw-r--r--pressure_control/firmware/sensor.c6
-rw-r--r--pressure_control/firmware/sensor.h1
4 files changed, 30 insertions, 10 deletions
diff --git a/pressure_control/firmware/main.c b/pressure_control/firmware/main.c
index 9f6cdd9..d39008d 100644
--- a/pressure_control/firmware/main.c
+++ b/pressure_control/firmware/main.c
@@ -60,6 +60,10 @@ static DEFINE_SENSOR(xy_control_sensor, (1<<MUX0), 245, 4400, 10000);
#define Z_MAX_PRESSURE 1500
#define Z_MAX_HYSTERESIS 300
+/* Report hysteresis (in mBar).
+ * Don't report changes lower than this (With some exceptions). */
+#define REPORT_HYSTERESIS 25
+
/* EEPROM contents */
@@ -142,11 +146,17 @@ void get_pressure_state(struct pressure_state *ret)
* Called in IRQ context. */
void sensor_result(struct sensor *s, uint16_t mbar)
{
- /* Defer processing of the value to the mainloop, so we can do it with
- * interrupts enabled. */
- state.measured_mbar = mbar;
- mb();
- state.needs_checking = 1;
+ state.measured_mbar += mbar;
+
+ if (++state.nr_adc_measurements >= 8) {
+ state.nr_adc_measurements = 0;
+ state.measured_mbar /= 8;
+ mb();
+ /* Defer processing of the value to the mainloop, so we can
+ * do it with interrupts enabled. */
+ state.needs_checking = 1;
+ } else
+ sensor_retrigger();
}
jiffies_t get_jiffies(void)
@@ -206,7 +216,7 @@ static void do_check_pressure(struct valves *valves,
* keep on doing this to reach the desired center value
* more closely. */
} else {
- /* We're within half the hysteresis.
+ /* We're within quarter of the hysteresis.
* The pressure is OK. Make sure the valves are
* all idle. */
report_change = (cur_state != VALVES_IDLE);
@@ -222,7 +232,7 @@ static void do_check_pressure(struct valves *valves,
valves_disarm_auto_idle(valves);
}
}
- if (abs((int32_t)mbar - (int32_t)(*reported_mbar)) >= 40)
+ if (abs((int32_t)mbar - (int32_t)(*reported_mbar)) >= REPORT_HYSTERESIS)
report_change = 1;
if (report_change) {
remote_pressure_change_notification(state.measured_mbar_xy,
@@ -334,7 +344,7 @@ int main(void)
if (++sensor_cycle == __NR_SENSOR_CYCLE)
sensor_cycle = 0;
state.needs_checking = 0;
- next_sensor_trigger = now + msec_to_jiffies(20);
+ next_sensor_trigger = now + msec_to_jiffies(5);
mb();
need_sensor_trigger = 1;
}
@@ -343,6 +353,7 @@ int main(void)
/* It's time for triggering another
* sensor measurement. */
need_sensor_trigger = 0;
+ state.measured_mbar = 0;
switch (sensor_cycle) {
case SENSOR_CYCLE_XY:
sensor_trigger_read(&xy_control_sensor);
diff --git a/pressure_control/firmware/main.h b/pressure_control/firmware/main.h
index b229ade..915e66e 100644
--- a/pressure_control/firmware/main.h
+++ b/pressure_control/firmware/main.h
@@ -44,10 +44,10 @@ struct pressure_config {
struct pressure_state {
/* Sensing and adjustment logic enabled? */
bool device_enabled;
- /* The last measured pressure (in mBar).
+ /* The sum of the last measured pressures (in mBar).
* It depends on sensor_cycle which valves this
* value belongs to. */
- uint16_t measured_mbar;
+ uint32_t measured_mbar;
/* The current pressure for the individual valves */
uint16_t measured_mbar_xy;
uint16_t measured_mbar_z;
@@ -57,6 +57,8 @@ struct pressure_state {
/* True, if the current pressure value needs checking against
* the desired pressure config. */
bool needs_checking;
+ /* The current count of lowlevel ADC measurements. */
+ uint8_t nr_adc_measurements;
};
void get_pressure_config(struct pressure_config *xy,
diff --git a/pressure_control/firmware/sensor.c b/pressure_control/firmware/sensor.c
index 08eca77..6e59bb1 100644
--- a/pressure_control/firmware/sensor.c
+++ b/pressure_control/firmware/sensor.c
@@ -72,6 +72,12 @@ void sensor_trigger_read(struct sensor *s)
adc_trigger(s->adc_mux, 1);
}
+void sensor_retrigger(void)
+{
+ /* Retrigger an ADC conversion on the currently active sensor. */
+ adc_trigger(active_sensor->adc_mux, 1);
+}
+
void sensor_init(struct sensor *s)
{
mdelay(20); /* Warm-up time */
diff --git a/pressure_control/firmware/sensor.h b/pressure_control/firmware/sensor.h
index 8f3c4e5..73b0835 100644
--- a/pressure_control/firmware/sensor.h
+++ b/pressure_control/firmware/sensor.h
@@ -27,6 +27,7 @@ struct sensor {
}
void sensor_trigger_read(struct sensor *s);
+void sensor_retrigger(void);
void sensor_init(struct sensor *s);
/* Callback for sensor value reporting. */
bues.ch cgit interface