Learn

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

Practice

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

PortDirectionTypeDescription
temp_iin8-bit signedCargo temperature, °C
batt_iin7-bit unsigned (0–100)Battery charge, percent (0 to 100)
too_cold_oout1 bitTemperature below −30 °C
too_warm_oout1 bitTemperature above −18 °C
temp_ok_oout1 bitTemperature within −30 to −18, inclusive
batt_low_oout1 bitBattery 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_o is '1' when temp_i is below −30; −30 itself is in spec
  • too_warm_o is '1' when temp_i is above −18; −18 itself is in spec. Note that 0 °C and every positive reading count as too warm
  • temp_ok_o is '1' exactly when neither temperature flag is up
  • batt_low_o is '1' when batt_i is 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 constant values named in ALL_CAPS. Pick each type deliberately: the temperature limits need integer; the battery limit fits a natural.

  • The comparison recipe from the lesson is all you need: '1' when ... else '0'.

  • For temp_ok_o you may compare against both limits directly, or combine your own flag outputs with gates. Reading your own out ports is fine; see the note in Port Directions.

Loading editor...

Click Run to execute your code. Output will appear here.