Cold-Chain Monitor
A refrigerated truck carries frozen goods that must ride between −30 °C and −18 °C, and the monitoring unit itself runs from a battery. You're building the alarm logic: a signed temperature reading and an unsigned battery percentage come in, four status flags go out.
All three limits must be named constants from the integer family.
Two of them are negative, so a natural cannot hold those values.
Interface
| Port | Direction | Type | Description |
|---|---|---|---|
temp_i | in | 8-bit signed | Cargo temperature, °C |
batt_i | in | 7-bit unsigned (0–100) | Battery charge, percent (0 to 100) |
too_cold_o | out | 1 bit | Temperature below −30 °C |
too_warm_o | out | 1 bit | Temperature above −18 °C |
temp_ok_o | out | 1 bit | Temperature within −30 to −18, inclusive |
batt_low_o | out | 1 bit | Battery below 25 % |
Declare temp_i as signed(7 downto 0), batt_i as unsigned(6 downto 0), and the flags as std_logic.
Behavior
too_cold_ois '1' whentemp_iis below −30; −30 itself is in spectoo_warm_ois '1' whentemp_iis above −18; −18 itself is in spec. Note that 0 °C and every positive reading count as too warmtemp_ok_ois '1' exactly when neither temperature flag is upbatt_low_ois '1' whenbatt_iis below 25; 25 itself is fine- Boundaries are tested on both sides: −31/−30 and −18/−17 for temperature, 24/25 for battery
Constraints
CONSTANTS: declare the three limits as
constantvalues named inALL_CAPS. Pick each type deliberately: the temperature limits needinteger; the battery limit fits anatural.
-
The comparison recipe from the lesson is all you need:
'1' when ... else '0'. -
For
temp_ok_oyou may compare against both limits directly, or combine your own flag outputs with gates. Reading your ownoutports is fine; see the note in Port Directions.
Click Run to execute your code. Output will appear here.