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

Clean up, simplify, and correct some energy meter code #810

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

toofishes
Copy link
Contributor

Much of this code was copied from the low-level firmware side, where we don't have floating point available, and had to use some tricks to ensure we didn't lose precision. (I should know- I wrote it!) Since this doesn't apply in our ESP32 code, we can just multiply the three values (volts, amps, milliseconds) together to get milliwatt-seconds.

Additionally, we should store elapsed as a floating point value, not an integer number of seconds. As we're going through the pool loop, which repeats every 1000 ms, we might not hit that value exactly. Imagine we are closer to 1020 ms instead due to the work we need to do each iteration. That would allow our elapsed second counter, which stores a truncated value (1020ms gets rounded to integer 1 second), to drift by 1 second every 50 seconds.

Much of this code was copied from the low-level firmware side, where we don't
have floating point available, and had to use some tricks to ensure we didn't
lose precision. (I should know- I wrote it!) Since this doesn't apply in our
ESP32 code, we can just multiply the three values (volts, amps, milliseconds)
together to get milliwatt-seconds.

Additionally, we should store elapsed as a floating point value, not an integer
number of seconds. As we're going through the pool loop, which repeats every
1000 ms, we might not hit that value exactly. Imagine we are closer to 1020 ms
instead due to the work we need to do each iteration. That would allow our
elapsed second counter, which stores a truncated value (1020ms gets rounded to
integer 1 second), to drift by 1 second every 50 seconds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant