0
0
VHDLprogramming~5 mins

Boolean type in VHDL

Choose your learning style9 modes available
Introduction

The Boolean type helps us represent simple true or false values in VHDL. It is useful to make decisions in hardware design.

When you want to check if a signal is ON or OFF.
When you need to control a process based on a condition being true or false.
When you want to create flags that indicate if something has happened or not.
When you want to write simple if-else decisions in your hardware code.
Syntax
VHDL
variable variable_name : boolean := true;  -- or false

Boolean values can only be true or false.

Use Boolean type for simple yes/no or on/off conditions.

Examples
This creates a signal named flag that starts as false.
VHDL
signal flag : boolean := false;
This creates a variable is_ready set to true initially.
VHDL
variable is_ready : boolean := true;
This checks if enable is true before running code.
VHDL
if enable = true then
  -- do something
end if;
Sample Program

This VHDL program sets a Boolean signal flag to true, waits 10 nanoseconds, then checks the flag. It reports a message depending on the flag's value.

VHDL
library ieee;
use ieee.std_logic_1164.all;

entity boolean_example is
end boolean_example;

architecture behavior of boolean_example is
  signal flag : boolean := false;
begin
  process
  begin
    flag <= true;
    wait for 10 ns;
    if flag = true then
      report "Flag is true!";
    else
      report "Flag is false!";
    end if;
    wait;
  end process;
end behavior;
OutputSuccess
Important Notes

Boolean type is different from std_logic, which can have more values like 'Z' or 'X'.

Use Boolean for simple true/false logic, but use std_logic for signals connected to hardware pins.

Summary

Boolean type holds only true or false values.

It is useful for simple decision making in VHDL code.

Use Boolean for internal logic flags and conditions.