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

Activating filtering prevents frequency detection #51

Open
mathieucarbou opened this issue Jan 30, 2024 · 0 comments
Open

Activating filtering prevents frequency detection #51

mathieucarbou opened this issue Jan 30, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@mathieucarbou
Copy link

mathieucarbou commented Jan 30, 2024

  • I'd like to use frequency detection
  • I am using a Robodyn and ESP32 (so not a nice pulse), so I set semiPeriodShrinkMargin == 400

When using freq detection + filtering, semiPeriodLength == 0 so this code always makes the function return because the comparison leads to true because there is a comparison with an unsigned and signed value.

#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 - Thyristor::semiPeriodShrinkMargin) { return; }
#endif

This code could be fixed like that, but the problem is that wrong "diff" could end up in the queue, so I don't really know how to fix that.

#ifdef FILTER_INT_PERIOD
    // Filters out spurious interrupts. The effectiveness of this simple
    // filter could vary depending on noise on electrical networ.
    if (semiPeriodLength && diff < semiPeriodLength - Thyristor::semiPeriodShrinkMargin) { return; }
#endif

With this fix, I can see the "wrong" detected frequencies.

It seems to me that filtering is quite linked to DimmableLightLinearized::setFrequency(), meaning as soon as we need filtering, we also need to set a frequency value we with it is good for where we are, so that filtering can work properly.

#if defined(ESP32) && defined (FILTER_INT_PERIOD)
  // https://github.com/fabianoriccardi/dimmable-light/wiki/Notes-about-specific-architectures#interrupt-issue
  Thyristor::semiPeriodShrinkMargin = 400;
#endif
  
  DimmableLightLinearized::setFrequency(ZCDConfig.getGridFrequency());
  DimmableLightLinearized::frequencyMonitorAlwaysOn(true);
  DimmableLightLinearized::setSyncPin(_pin);
  DimmableLightLinearized::begin();
@mathieucarbou mathieucarbou added the bug Something isn't working label Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant