Skip to content

Commit

Permalink
Adding documentation on edge detection. Use rising edge for noise pin…
Browse files Browse the repository at this point in the history
… (as it is low by default, high on noise)
  • Loading branch information
MonsieurV committed Feb 19, 2020
1 parent e13af2a commit 2a92970
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/RadiationWatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ RadiationWatch::RadiationWatch(byte signPin, byte noisePin):

void RadiationWatch::setup()
{
// Enable the ~20kΩ pull-up resistor for radiation and noise
// pins.
// For pullup resistors on Arduino, see https://www.arduino.cc/en/Tutorial/DigitalPins
pinMode(_signPin, INPUT_PULLUP);
// The noise signal is low by default (no noise), so we could install a pull-down resistor.
// However this is not available on Arduino platform, so we goes with a pull-up resistor.
// As the PocketGeiger board pull down the noise signal to low if working, this is not an issue.
pinMode(_noisePin, INPUT_PULLUP);
// Initialize _countHistory[].
for(int i = 0; i < HISTORY_LENGTH; i++)
Expand Down
14 changes: 12 additions & 2 deletions src/RadiationWatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#endif
// Duration of each history array cell (seconds).
#define HISTORY_UNIT 6
// Main loop processing period. In milliseconds.
#define PROCESS_PERIOD 160
#include "Arduino.h"

Expand Down Expand Up @@ -94,6 +95,15 @@ class RadiationWatch
static void _onNoiseHandler();
};

/* Notes on the PocketGeiger pulse listening.
* Raw data of Radiation Pulse: Not-detected -> High, Detected -> Low.
* --> We listen on falling edges.
* Raw data of Noise Pulse: Not-detected -> Low, Detected -> High.
* --> We listen on rising edges.
* Source:
* https://cdn.sparkfun.com/assets/learn_tutorials/1/4/3/GeigerCounterType5_connect_with_microcomputer.pdf
*/

/* Secure that the setupInterrupt() is only defined and compiled once.
* To be able to change the setupInterrupt() during compile time, the
* function must be define in the header file. Every include from
Expand All @@ -108,7 +118,7 @@ class RadiationWatch
* support. */
void RadiationWatch::setupInterrupt() {
enableInterrupt(_signPin, _onRadiationHandler, FALLING);
enableInterrupt(_noisePin, _onNoiseHandler, FALLING);
enableInterrupt(_noisePin, _onNoiseHandler, RISING);
}
#else
/* Default: Use external interrupts utilizing the attachInterrupt()
Expand All @@ -117,7 +127,7 @@ void RadiationWatch::setupInterrupt() {
* Arduino UNO. */
void RadiationWatch::setupInterrupt() {
attachInterrupt(digitalPinToInterrupt(_signPin), _onRadiationHandler, FALLING);
attachInterrupt(digitalPinToInterrupt(_noisePin), _onNoiseHandler, FALLING);
attachInterrupt(digitalPinToInterrupt(_noisePin), _onNoiseHandler, RISING);
}
#endif
#endif // LIBCALL_RADIATIONWATCH
Expand Down

0 comments on commit 2a92970

Please sign in to comment.