Repository navigation
fix(firmware): take the control snapshot per reading, not per pass - #85
Merged
Merged
Conversation
relayControlLogic() opened four masked windows on every loop pass, often enough to delay the TWI interrupt and cut GET_STATE replies short (#81). It now snapshots, runs the PIDs and publishes the on-times on a new reading or every RLHT_SNAPSHOT_INTERVAL_MS (10), and drives the relays from that snapshot in between. The e-stop, watchdog and fault hold is still checked every pass, unmasked. Adds test_mask_rate; noInterrupts() in the host stubs now counts. Closes #81
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #81, the GET_STATE replies cut short on the gen2 Nano.
The 2026-11-01 bisect (#84) traced the cut-short replies to how often the loop masks interrupts. With
main.cpp's masked windows removed, or with the loop slowed by 300 us a pass, the bad-reply rate went from 187 in 300 s to 0.relayControlLogic()opened four masked windows on every pass: three snapshots and the on-time commit.What changes:
relayControlLogic()takes its snapshot, runs the PIDs and publishes the on-times only on a new thermocouple reading, or onceRLHT_SNAPSHOT_INTERVAL_MS(default 10, a-Doverride) has passed. In between,actuateRelay()drives from the last snapshot.I rejected a per-command "changed" flag set by every handler: a handler that missed setting it would leave a stale setpoint or mode. A fixed interval can't miss anything.
Test
test_mask_ratecountsnoInterrupts()calls through the host stub over 3 s of closed-loop heating:relayControlLogic()It also checks that a duty change reaches relay 1 within the interval (10 ms) and that the e-stop drops relay 1 on the next pass.
make -C test/host: 732 ok, 0 failed, across the four envs. That's main's 696 plustest_mask_rate's 36.pio run, 0 warnings:gen1_nanogen2_nanogen1_nanoeverygen2_nanoeveryBench
gen2 Nano on the backplane, Pi 4 at 50 kHz,
replylog.py 19 1 300with retries off:a251158(2026-11-01, two captures)The one bad frame went to 0xFF at the CRC byte and was caught. That's the rate Slice_DCMT's gen2 Nano showed on the same bus on 2026-10-31 (1 / 2555).
Not run on the board: the heaters under closed-loop control on this build. The host tests cover the control paths.