Battery Charge Controller
A lithium battery pack charges in stages. A deeply discharged pack must be brought up gently. A mid-range pack takes the full fast-charge current, and a nearly full pack is held with a small float current. One thing outranks them all: if the pack's temperature sensor reports a fault, charging stops, at any voltage. Build the rate selector as one conditional assignment chain.
Interface
| Port | Direction | Type | Description |
|---|---|---|---|
volts_i | in | 5-bit unsigned | Pack voltage in volts, 0 to 31 |
fault_i | in | 1 bit | Temperature fault |
rate_o | out | 2-bit vector | Charging rate code |
Behavior
fault_i = '1'→rate_o = "00"(off), regardless of voltage- Otherwise, below 10 V →
"01"(trickle) - Otherwise, below 14 V →
"10"(fast) - Otherwise, 14 V and up →
"11"(float) - Boundaries are exact and tested: 9 V still trickles, 10 V charges fast, 13 V still charges fast, 14 V floats
Constraints
STRUCTURE: one
when/elseconditional assignment chain; no processes.
- The voltage conditions overlap by design: every voltage below 10 is also below 14. The order of your chain has to resolve that; the testbench checks a 5 V pack both with and without a fault
Loading editor...
Click Run to execute your code. Output will appear here.