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

Remove floating point calculation from ac_dimmer ISR #3770

Merged
merged 4 commits into from
Sep 14, 2022

Conversation

Azimath
Copy link
Contributor

@Azimath Azimath commented Sep 5, 2022

What does this implement/fix?

PR#3494 added code to linearize the RMS power output of the ac_dimmer relative to the output state. Doing so introduced an acos into the ISR, which most of the time works, but some race condition exists that causes this call to throw an exception when doing stuff like OTA, setting a new value in home assistant, or sometimes it just keeps working (depending on what version of ESPHome you're running and your luck).

The RMS power linearization only needs to be computed when a new state is written, as it doesn't vary cycle to cycle. This PR moves the acos function outside the ISR into the write_state function where it shouldn't cause problems.

The original PR was considered breaking because it might change how gamma is perceived on some lights. The linearization previously applied only to leading dimmers, while now it applies to both, so it might change how gamma is perceived on trailing dimmers.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Related issue or feature (if applicable): fixes 3509

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266

Example entry for config.yaml:

output:
  - platform: ac_dimmer
    id: dimmer1
    gate_pin: 
      number: GPIO13
      inverted: true
    zero_cross_pin: GPIO12
    min_power: 0.2
    zero_means_zero: true

Checklist:

  • The code change is tested and works locally.
  • n/a Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@probot-esphome
Copy link

probot-esphome bot commented Sep 5, 2022

Hey there @glmnet, mind taking a look at this pull request as it has been labeled with an integration (ac_dimmer) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@glmnet
Copy link
Member

glmnet commented Sep 5, 2022

@josephdouce can you please review this?

@josephdouce
Copy link
Contributor

josephdouce commented Sep 5, 2022 via email

@Azimath
Copy link
Contributor Author

Azimath commented Sep 13, 2022 via email

@josephdouce
Copy link
Contributor

josephdouce commented Sep 14, 2022 via email

@jesserockz jesserockz added this to the 2022.9.0b2 milestone Sep 14, 2022
@jesserockz jesserockz merged commit 917bbc6 into esphome:dev Sep 14, 2022
@jesserockz jesserockz mentioned this pull request Sep 15, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Sep 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Upgrading from 2022.6.3 to 2022.8.0 causes WDT resets with AC dimmer
4 participants