summaryrefslogtreecommitdiffstats
path: root/pressure_control/firmware/valves.c
diff options
context:
space:
mode:
authorMichael Buesch <mb@bu3sch.de>2009-04-10 16:56:51 +0200
committerMichael Buesch <mb@bu3sch.de>2009-04-10 16:56:51 +0200
commit75a29d4d986e32bd82bc6468bba11567932a5349 (patch)
treec0a426aa40bf7f44bf87353460d9230326f77fac /pressure_control/firmware/valves.c
parente54d84019bac17f0a7ac49e9147471ff5df85a02 (diff)
downloadcnc-75a29d4d986e32bd82bc6468bba11567932a5349.tar.xz
cnc-75a29d4d986e32bd82bc6468bba11567932a5349.zip
pressure_control: Fix automatic pressure control
Signed-off-by: Michael Buesch <mb@bu3sch.de>
Diffstat (limited to 'pressure_control/firmware/valves.c')
-rw-r--r--pressure_control/firmware/valves.c39
1 files changed, 28 insertions, 11 deletions
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 <mb@bu3sch.de>
+ * Copyright (C) 2008-2009 Michael Buesch <mb@bu3sch.de>
*
* 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 <avr/io.h>
@@ -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) |
bues.ch cgit interface