Skip to content

Commit

Permalink
firmware: add experimental software debounce.
Browse files Browse the repository at this point in the history
Suspected EMI transients have been observed spuriously triggering the
external interrupt lines on some systems.  Likely this is better solved
in hardware, however this is not as convenient as a software fix.

When enabled, ISRs first delay by a fixed about (~1.2ms currently) and
then inspects the active-low interrupting pin.  The delay amount
was selected somewhat empirically (with a non-SF800 sensor) and
likely requires tuning to account for differences in sensors.
  • Loading branch information
mik3y committed Apr 30, 2013
1 parent d164ac5 commit 3e63e62
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
37 changes: 24 additions & 13 deletions arduino/kegboard/kegboard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include <util/crc16.h>
#include <util/delay.h>


#include "kegboard.h"
#include "kegboard_config.h"
#include "ds1820.h"
Expand Down Expand Up @@ -197,43 +196,55 @@ static unsigned long gLastWiegandInterruptMillis = 0;
// ISRs
//

#if KB_ENABLE_SOFT_DEBOUNCE
#define CHECK_METER(pin, meter_index) \
do { \
delayMicroseconds(KB_SOFT_DEBOUNCE_MICROS); \
if (digitalRead(pin) == 0) \
gMeters[meter_index] += 1; \
} while(0)
#else
#define CHECK_METER(pin, meter_index) \
gMeters[meter_index] += 1
#endif

void meterInterruptA()
{
gMeters[0] += 1;
CHECK_METER(KB_PIN_METER_A, 0);
}

#ifdef KB_PIN_METER_B
void meterInterruptB()
{
gMeters[1] += 1;
CHECK_METER(KB_PIN_METER_B, 1);
}
#endif

#ifdef KB_PIN_METER_C
void meterInterruptC()
{
gMeters[2] += 1;
CHECK_METER(KB_PIN_METER_C, 2);
}
#endif

#ifdef KB_PIN_METER_D
void meterInterruptD()
{
gMeters[3] += 1;
CHECK_METER(KB_PIN_METER_D, 3);
}
#endif

#ifdef KB_PIN_METER_E
void meterInterruptE()
{
gMeters[4] += 1;
CHECK_METER(KB_PIN_METER_E, 4);
}
#endif

#ifdef KB_PIN_METER_F
void meterInterruptF()
{
gMeters[5] += 1;
CHECK_METER(KB_PIN_METER_F, 1);
}
#endif

Expand Down Expand Up @@ -386,36 +397,36 @@ void setup()
// from ticking away.
pinMode(KB_PIN_METER_A, INPUT);
digitalWrite(KB_PIN_METER_A, HIGH);
attachInterrupt(0, meterInterruptA, RISING);
attachInterrupt(0, meterInterruptA, FALLING);

#ifdef KB_PIN_METER_B
pinMode(KB_PIN_METER_B, INPUT);
digitalWrite(KB_PIN_METER_B, HIGH);
attachInterrupt(1, meterInterruptB, RISING);
attachInterrupt(1, meterInterruptB, FALLING);
#endif

#ifdef KB_PIN_METER_C
pinMode(KB_PIN_METER_C, INPUT);
digitalWrite(KB_PIN_METER_C, HIGH);
attachInterrupt(2, meterInterruptC, RISING);
attachInterrupt(2, meterInterruptC, FALLING);
#endif

#ifdef KB_PIN_METER_D
pinMode(KB_PIN_METER_D, INPUT);
digitalWrite(KB_PIN_METER_D, HIGH);
attachInterrupt(3, meterInterruptD, RISING);
attachInterrupt(3, meterInterruptD, FALLING);
#endif

#ifdef KB_PIN_METER_E
pinMode(KB_PIN_METER_E, INPUT);
digitalWrite(KB_PIN_METER_E, HIGH);
attachInterrupt(4, meterInterruptE, RISING);
attachInterrupt(4, meterInterruptE, FALLING);
#endif

#ifdef KB_PIN_METER_F
pinMode(KB_PIN_METER_F, INPUT);
digitalWrite(KB_PIN_METER_F, HIGH);
attachInterrupt(5, meterInterruptF, RISING);
attachInterrupt(5, meterInterruptF, FALLING);
#endif

pinMode(KB_PIN_RELAY_A, OUTPUT);
Expand Down
8 changes: 8 additions & 0 deletions arduino/kegboard/kegboard_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
// Note: Must set KB_ENABLE_ID12_RFID to 0 if enabling this.
#define KB_ENABLE_WIEGAND_RFID 0

// Enable software debounce? EXPERIMENTAL. Enabling this feature may negatively
// affect pour accuracy. In particular, a delay is added to each flow meter
// ISR, disabling all other interrupts during this time.
#define KB_ENABLE_SOFT_DEBOUNCE 0

// Approximate minimum pulse width required for incoming external interrupts.
#define KB_SOFT_DEBOUNCE_MICROS 1200

//
// Pin configuration - KEGBOARD VERSION
//
Expand Down
5 changes: 5 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Changelog
Arduino Firmware
-----------------

Current Version (in development)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* Flow LEDs are now toggled on system startup and during pours.
* Experimental debounce feature.

v13 (2012-10-28)
^^^^^^^^^^^^^^^^
* Adds support for Wiegand RFID readers (HID ProxPro and similar).
Expand Down

0 comments on commit 3e63e62

Please sign in to comment.