Learn

0/8
0/6
0/6
0/6

Practice

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

PortDirectionTypeDescription
voltsin5-bit unsignedPack voltage in volts, 0 to 31
faultin1 bitTemperature fault
rateout2-bit vectorCharging rate code

Behavior

  • fault = '1'rate = "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 conditional assignment chain (when/else in VHDL, a ?: chain in SystemVerilog); no processes or always blocks.

  • 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.