Hello iRob,
I do see some inconsistencies in your test code that could possibly account for the ovserved erratic operation. Let's examine the first section -
if ((PLUS==CLOSE) && (MINUS==CLOSE) && (MODE==CLOSE)) {
plus_flag = 1;
minus_flag = 1;
mode_flag = 1;
while ((PLUS==CLOSE) && (MINUS==CLOSE) && (MODE==CLOSE)) { // wait for release
__RESET_WATCHDOG();
}
}
Firstly, I am assuming that each of your three tests appropriately generates a logical true result when the associated switch is closed, but otherwise a false condition. This is not evident from the posted code. This would then imply that you require the closure of all three switches for the following code to execute, but the release of only one of the switches to exit from the wait loop. I might have expected that you would require all three switches to be released before exiting the loop, and would need the following modification.
/* Wait for release of all switches */
while ((PLUS==CLOSE) || (MINUS==CLOSE) || (MODE==CLOSE))
__RESET_WATCHDOG();
Incidently, if you were to do this, the next section of code could rarely execute since it also seems to require that all switches be closed, and it immediately follows a state where all switches are released.
However, as the code stands, if the last of the three switches to be activated should bounce, the first wait loop will exit, the next section of code will probably be skipped because the bounce period will usually exceed the few cycles for the next test, and the tests for individual switches would then occur. One of the individual switches would register, but because of its associated wait loop, whether or not any other of the switches register a closure during the current passage of the code would depend on the switch release sequence.
With the existing code it remains doubtful that the second section of code would ever execute. To achieve multiple tests for the same switch state, I might suggest the following modified test code should achieve more predictable results.
if ((PLUS==CLOSE) && (MINUS==CLOSE) && (MODE==CLOSE)) {
plus_flag = 1;
minus_flag = 1;
mode_flag = 1;
active_flag = 1;
}
if ((PLUS==CLOSE) & (MINUS==CLOSE) & (MODE==CLOSE)) {
plus_flag = 1;
minus_flag = 1;
mode_flag = 1;
active_flag = 1;
}
if (PLUS==CLOSE) {
plus_flag = 1;
minus_flag = 0;
mode_flag = 0;
active_flag = 1;
}
if (MINUS==CLOSE) {
plus_flag = 0;
minus_flag = 1;
mode_flag = 0;
active_flag = 1;
}
if (MODE==CLOSE) {
plus_flag = 0;
minus_flag = 0;
mode_flag = 1;
active_flag = 1;
}
if (active_flag) {
/* Implement de-bounce delay here */
}
/* Wait for release of all switches */
while ((PLUS==CLOSE)||(MINUS==CLOSE)||(MODE==CLOSE))
__RESET_WATCHDOG();
if (active_flag) {
/* Implement de-bounce delay here */
active_flag = 0;
}
Regards,
Mac
Message Edited by bigmac on
2007-08-23 10:43 AM