Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow semiPeriodShrinkMargin and semiPeriodExpandMargin to be set #49

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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