From 75a29d4d986e32bd82bc6468bba11567932a5349 Mon Sep 17 00:00:00 2001 From: Michael Buesch Date: Fri, 10 Apr 2009 16:56:51 +0200 Subject: pressure_control: Fix automatic pressure control Signed-off-by: Michael Buesch --- pressure_control/firmware/valves.c | 39 +++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'pressure_control/firmware/valves.c') diff --git a/pressure_control/firmware/valves.c b/pressure_control/firmware/valves.c index 70a2b6a..ec15518 100644 --- a/pressure_control/firmware/valves.c +++ b/pressure_control/firmware/valves.c @@ -2,7 +2,7 @@ * Pneumatic pressure controller. * Valve control. * - * Copyright (C) 2008 Michael Buesch + * Copyright (C) 2008-2009 Michael Buesch * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,6 +19,7 @@ */ #include "valves.h" +#include "util.h" #include @@ -26,10 +27,13 @@ /*** Valve interface definitions ***/ #define VALVE_DDR DDRD #define VALVE_PORT PORTD -#define VALVE0_14 4 /* Pin for valve-0 position 14 */ -#define VALVE0_12 5 /* Pin for valve-0 position 12 */ -#define VALVE1_14 6 /* Pin for valve-1 position 14 */ -#define VALVE1_12 7 /* Pin for valve-1 position 12 */ +#define VALVE0_14 6 /* Pin for valve-0 position 14 */ +#define VALVE0_12 7 /* Pin for valve-0 position 12 */ +#define VALVE1_14 4 /* Pin for valve-1 position 14 */ +#define VALVE1_12 5 /* Pin for valve-1 position 12 */ + + +static uint8_t current_global_state = 0xFF; void valve0_switch(uint8_t state) @@ -37,7 +41,7 @@ void valve0_switch(uint8_t state) VALVE_PORT &= ~((1 << VALVE0_12) | (1 << VALVE0_14)); if (state == VALVE_STATE_12) VALVE_PORT |= (1 << VALVE0_12); - else + else if (state == VALVE_STATE_14) VALVE_PORT |= (1 << VALVE0_14); } @@ -46,28 +50,41 @@ void valve1_switch(uint8_t state) VALVE_PORT &= ~((1 << VALVE1_12) | (1 << VALVE1_14)); if (state == VALVE_STATE_12) VALVE_PORT |= (1 << VALVE1_12); - else + else if (state == VALVE_STATE_14) VALVE_PORT |= (1 << VALVE1_14); } void valves_global_switch(uint8_t state) { + + if (state == current_global_state) + return; + current_global_state = state; + switch (state) { case VALVES_IDLE: valve0_switch(VALVE_STATE_12); valve1_switch(VALVE_STATE_12); + valve_wait_toggle(); + valve0_switch(VALVE_STATE_IDLE); + valve1_switch(VALVE_STATE_IDLE); break; case VALVES_FLOW_IN: - valve0_switch(VALVE_STATE_12); - valve1_switch(VALVE_STATE_14); - break; - case VALVES_FLOW_OUT: valve1_switch(VALVE_STATE_12); valve0_switch(VALVE_STATE_14); break; + case VALVES_FLOW_OUT: + valve0_switch(VALVE_STATE_12); + valve1_switch(VALVE_STATE_14); + break; } } +uint8_t valves_get_global_state(void) +{ + return current_global_state; +} + void valves_init(void) { VALVE_DDR |= (1 << VALVE0_12) | (1 << VALVE0_14) | -- cgit v1.2.3