Skip to content

Commit

Permalink
Allow semiPeriodShrinkMargin and semiPeriodExpandMargin to be set
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Feb 16, 2024
1 parent 44cbab0 commit 174a43d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/thyristor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ void activate_thyristors() {

#ifdef FILTER_INT_PERIOD
// In microsecond
const static int semiPeriodShrinkMargin = 50;
const static int semiPeriodExpandMargin = 50;
int Thyristor::semiPeriodShrinkMargin = 50;
int Thyristor::semiPeriodExpandMargin = 50;
#endif

#if defined(FILTER_INT_PERIOD) || defined(MONITOR_FREQUENCY)
Expand Down Expand Up @@ -299,14 +299,14 @@ void zero_cross_int() {
uint32_t diff = now - lastTime;

#ifdef PRINT_INT_PERIOD
if (diff < semiPeriodLength - semiPeriodShrinkMargin) {
if (diff < semiPeriodLength - Thyristor::semiPeriodShrinkMargin) {
#ifdef ARDUINO_ARCH_ESP32
ets_printf("B%d\n", diff);
#else
Serial.println(String('B') + diff);
#endif
}
if (diff > semiPeriodLength + semiPeriodExpandMargin) {
if (diff > semiPeriodLength + Thyristor::semiPeriodExpandMargin) {
#ifdef ARDUINO_ARCH_ESP32
ets_printf("A%d\n", diff);
#else
Expand All @@ -318,7 +318,7 @@ void zero_cross_int() {
#ifdef FILTER_INT_PERIOD
// Filters out spurious interrupts. The effectiveness of this simple
// filter could vary depending on noise on electrical networ.
if (diff < semiPeriodLength - semiPeriodShrinkMargin) { return; }
if (diff < semiPeriodLength - Thyristor::semiPeriodShrinkMargin) { return; }
#endif

#endif
Expand Down
6 changes: 6 additions & 0 deletions src/thyristor.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ class Thyristor {
friend void activate_thyristors();
friend void zero_cross_int();
friend void turn_off_gates_int();

public:
#ifdef FILTER_INT_PERIOD
static int semiPeriodShrinkMargin;
static int semiPeriodExpandMargin;
#endif
};

#endif // END THYRISTOR_H

0 comments on commit 174a43d

Please sign in to comment.