adding stable conditions for HVC state machine#247
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Code Review
This pull request updates the HVC state machine to ensure the shutdown circuit is closed before entering or remaining in charging states. Feedback highlights that the is_shutdown_closed() function contains stateful debouncing logic; calling it multiple times per cycle, as introduced in these changes, will incorrectly accelerate the debounce period and increase noise sensitivity. It is recommended to capture the state in a local variable at the start of the function to ensure consistency and correct debouncing.
| precharge_start_time = current_time; | ||
| current_state = HVC_STATE_PRECHARGING; | ||
| } else if (is_charge_enable_active()) { | ||
| } else if (is_shutdown_closed() && is_charge_enable_active()) { |
There was a problem hiding this comment.
The function is_shutdown_closed() contains stateful debouncing logic (lines 193-212) that increments a counter on every call if the input differs from the current state. By adding this call here, it is now called twice within the HVC_STATE_NOT_ENERGIZED case (once at line 69 and once at line 73). This causes the debounce logic to process multiple times per task cycle, effectively reducing the debounce period and making the system more susceptible to noise.
Furthermore, the logic is redundant as is_shutdown_closed() is checked in both branches. It is highly recommended to capture the result of is_shutdown_closed() into a local variable at the start of update_state_machine() and use that variable throughout the function to ensure a consistent state snapshot and correct debouncing behavior.
No description provided.