From 2067eed91adc2e3b7f66154e7886fba56b787e42 Mon Sep 17 00:00:00 2001 From: Michael Buesch Date: Fri, 29 May 2009 21:55:22 +0200 Subject: pressure_control: Cycle the sensors Signed-off-by: Michael Buesch --- pressure_control/firmware/main.c | 66 +++++++++++++++++++++++++++---------- pressure_control/firmware/main.h | 9 +++-- pressure_control/firmware/remote.c | 3 +- pressure_control/remote/pctl-remote | 2 +- 4 files changed, 59 insertions(+), 21 deletions(-) (limited to 'pressure_control') diff --git a/pressure_control/firmware/main.c b/pressure_control/firmware/main.c index ec2335d..c306212 100644 --- a/pressure_control/firmware/main.c +++ b/pressure_control/firmware/main.c @@ -48,6 +48,8 @@ DEFINE_VALVE(z_control_valves, C, 2, 3, 4, 5); static DEFINE_SENSOR(xy_control_sensor, 0, 245, 4400, 10000); static DEFINE_SENSOR(z_control_sensor, (1<= 0); - cur_state = valves_get_global_state(&xy_control_valves); + cur_state = valves_get_global_state(valves); if (abs_offset > cfg.hysteresis) { /* Adjust the pressure */ report_change = (cur_state == VALVES_IDLE); if (is_too_big) - valves_global_switch(&xy_control_valves, VALVES_FLOW_OUT); + valves_global_switch(valves, VALVES_FLOW_OUT); else - valves_global_switch(&xy_control_valves, VALVES_FLOW_IN); + valves_global_switch(valves, VALVES_FLOW_IN); } else if (abs_offset > cfg.hysteresis / 4) { /* If we're idle, stay idle. * If we're increasing or decreasing pressure, @@ -172,23 +174,37 @@ static void check_pressure(void) * The pressure is OK. Make sure the valves are * all idle. */ report_change = (cur_state != VALVES_IDLE); - valves_global_switch(&xy_control_valves, VALVES_IDLE); + valves_global_switch(valves, VALVES_IDLE); } - if (state.mbar < 800) { + if (mbar < 800) { /* If the pressure in the reservoir is low, * the feedforward of the pneumatic valve for * flow-out might not work correctly. So force poke * the valves again until we reach a good pressure. */ - __valves_global_switch(&xy_control_valves, - valves_get_global_state(&xy_control_valves)); - valves_disarm_auto_idle(&xy_control_valves); + __valves_global_switch(valves, + valves_get_global_state(valves)); + valves_disarm_auto_idle(valves); } } - if (abs((int32_t)state.mbar - (int32_t)state.reported_mbar) >= 100) + if (abs((int32_t)mbar - (int32_t)state.reported_mbar) >= 100) report_change = 1; if (report_change) { - remote_pressure_change_notification(state.mbar); - state.reported_mbar = state.mbar; + remote_pressure_change_notification(mbar); + state.reported_mbar = mbar; + } +} + +static void check_pressure(void) +{ + switch (sensor_cycle) { + case SENSOR_CYCLE_XY: + do_check_pressure(&xy_control_valves, state.measured_mbar); + break; + case SENSOR_CYCLE_Z: + do_check_pressure(&z_control_valves, state.measured_mbar); + break; + default: + BUG_ON(1); } } @@ -227,6 +243,7 @@ int main(void) if (mcucsr & (1 << BORF)) { /* If we have a brownout, try to enter valve emergency state. */ valves_emergency_state(&xy_control_valves); + valves_emergency_state(&z_control_valves); mdelay(500); /* This wasn't a real brownout, if we're still alife. * Go on with initialization. */ @@ -243,7 +260,9 @@ int main(void) print("WATCHDOG RESET!\n"); valves_init(&xy_control_valves); + valves_init(&z_control_valves); sensor_init(&xy_control_sensor); + sensor_init(&z_control_sensor); eeprom_load_config(); system_timer_init(); @@ -252,6 +271,7 @@ int main(void) print("Monitoring...\n"); remote_work(); remote_notify_restart(); + sensor_cycle = SENSOR_CYCLE_XY; sensor_trigger_read(&xy_control_sensor); while (1) { static jiffies_t next_sensor_trigger; @@ -265,8 +285,10 @@ int main(void) check_pressure(); /* Trigger another measurement in * a few milliseconds. */ + if (++sensor_cycle == __NR_SENSOR_CYCLE) + sensor_cycle = 0; state.needs_checking = 0; - next_sensor_trigger = now + msec_to_jiffies(35); + next_sensor_trigger = now + msec_to_jiffies(20); mb(); need_sensor_trigger = 1; } @@ -275,10 +297,20 @@ int main(void) /* It's time for triggering another * sensor measurement. */ need_sensor_trigger = 0; - sensor_trigger_read(&xy_control_sensor); + switch (sensor_cycle) { + case SENSOR_CYCLE_XY: + sensor_trigger_read(&xy_control_sensor); + break; + case SENSOR_CYCLE_Z: + sensor_trigger_read(&z_control_sensor); + break; + default: + BUG_ON(1); + } } remote_work(); valves_work(&xy_control_valves); + valves_work(&z_control_valves); wdt_reset(); } } diff --git a/pressure_control/firmware/main.h b/pressure_control/firmware/main.h index 7a9dbf2..279b7e0 100644 --- a/pressure_control/firmware/main.h +++ b/pressure_control/firmware/main.h @@ -26,6 +26,11 @@ typedef int16_t s_jiffies_t; jiffies_t get_jiffies(void); +enum { + SENSOR_CYCLE_XY = 0, + SENSOR_CYCLE_Z, + __NR_SENSOR_CYCLE, +}; struct pressure_config { /* Desired pressure in mBar */ @@ -39,8 +44,8 @@ struct pressure_config { struct pressure_state { /* Sensing and adjustment logic enabled? */ bool device_enabled; - /* Current pressure in the tank (in mBar) */ - uint16_t mbar; + /* The last measured pressure (in mBar) */ + uint16_t measured_mbar; /* Reported pressure via RS232 */ uint16_t reported_mbar; /* True, if the current pressure value needs checking against diff --git a/pressure_control/firmware/remote.c b/pressure_control/firmware/remote.c index c640067..8fd104e 100644 --- a/pressure_control/firmware/remote.c +++ b/pressure_control/firmware/remote.c @@ -119,9 +119,10 @@ static void handle_received_message(void) case MSG_GET_CURRENT_PRESSURE: { struct pressure_state state; +//FIXME get_pressure_state(&state); reply.id = MSG_CURRENT_PRESSURE; - reply.pressure.mbar = state.mbar; + reply.pressure.mbar = state.measured_mbar; send_message(&reply); break; } diff --git a/pressure_control/remote/pctl-remote b/pressure_control/remote/pctl-remote index 489a9df..0f34ba9 100755 --- a/pressure_control/remote/pctl-remote +++ b/pressure_control/remote/pctl-remote @@ -320,7 +320,7 @@ class MainWidget(QWidget): self.hystSpin = QDoubleSpinBox(self) self.hystSpin.setMinimum(0.1) self.hystSpin.setMaximum(8) - self.hystSpin.setSingleStep(0.1) + self.hystSpin.setSingleStep(0.05) self.hystSpin.setSuffix(self.tr(" Bar")) self.connect(self.hystSpin, SIGNAL("valueChanged(double)"), self.desiredHysteresisChanged) -- cgit v1.2.3