Skip to content

Commit

Permalink
Fixup esp32 test counter
Browse files Browse the repository at this point in the history
  • Loading branch information
steadramon committed Apr 30, 2023
1 parent 48cfd88 commit e82abaa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
13 changes: 5 additions & 8 deletions ESPGeiger/src/Counter/Counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,8 @@ void Counter::begin() {
timer1_enable(TIM_DIV16, TIM_EDGE, TIM_LOOP);
timer1_write(600);
#else
hw_timer_t * timer = NULL;
timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &count, true);
timerAlarmWrite(timer, 600, true);
timerAlarmEnable(timer);
hwtimer = timerBegin(0, 80, true);
timerAlarmEnable(hwtimer);
#endif
#elif GEIGER_TYPE == GEIGER_TYPE_TESTPULSE
Log::console(PSTR("Counter: Setting up test pulse geiger ..."));
Expand Down Expand Up @@ -139,15 +136,15 @@ void Counter::handleSerial(char* input)
#endif
Log::debug(PSTR("Counter loop - %d"), _scpm);
#ifdef ESP32
portENTER_CRITICAL(&timerMux);
portENTER_CRITICAL(&timerMux);
#endif
#if GEIGER_SERIAL_TYPE == GEIGER_SERIAL_CPM
eventCounter = (float)_scpm/(float)60;
#else
eventCounter = (float)_scpm;
#endif
#ifdef ESP32
portEXIT_CRITICAL(&timerMux);
portEXIT_CRITICAL(&timerMux);
#endif
}
}
Expand Down Expand Up @@ -176,7 +173,7 @@ void Counter::loop() {
_serial_idx = 0;
}

if (_serial_idx > 42) {
if (_serial_idx > 52) {
_serial_idx = 0;
}
}
Expand Down
7 changes: 6 additions & 1 deletion ESPGeiger/src/Counter/Counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ static bool _handlesecond = false;

#ifdef ESP32
static portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
static hw_timer_t * hwtimer = NULL;

static void IRAM_ATTR count() {
unsigned long cycles = ESP.getCycleCount();
Expand All @@ -229,13 +230,17 @@ static void IRAM_ATTR count() {
};

static void IRAM_ATTR handleSecondTick() {
_handlesecond = true;
portENTER_CRITICAL_ISR(&timerMux);
_handlesecond = true;
#ifdef USE_PCNT
int16_t pulseCount;
pcnt_get_counter_value(PCNT_UNIT, &pulseCount);
pcnt_counter_clear(PCNT_UNIT);
eventCounter = pulseCount;
#endif
#if GEIGER_TYPE == GEIGER_TYPE_TEST && ESP32
eventCounter = timerRead(hwtimer)/600;
timerRestart(hwtimer);
#endif
status.geigerTicks.add(eventCounter);
eventCounter = 0;
Expand Down

0 comments on commit e82abaa

Please sign in to comment.