0
0
VhdlHow-ToBeginner · 4 min read

How to Use Record in VHDL: Syntax and Examples

In VHDL, a record groups multiple related signals or variables into one composite type. You define a record type with named fields, then declare signals or variables of that type to organize data cleanly and access fields with dot notation.
📐

Syntax

A record type is defined using the type keyword followed by the record name and its fields inside record ... end record;. Each field has a name and a type. After defining the type, you declare signals or variables of that record type.

Example parts:

  • type: declares a new record type
  • record ... end record;: groups fields
  • field_name : type;: defines each field
  • signal/variable: declares an instance of the record
  • dot notation: access fields like record_instance.field_name
vhdl
type MyRecord is record
    field1 : std_logic;
    field2 : integer;
end record;

signal rec_signal : MyRecord;
💻

Example

This example shows how to define a record type, declare a signal of that type, assign values to its fields, and use them in a process.

vhdl
library ieee;
use ieee.std_logic_1164.all;

entity record_example is
    port(
        clk : in std_logic;
        out_signal : out std_logic
    );
end entity;

architecture Behavioral of record_example is
    type StatusRecord is record
        ready : std_logic;
        count : integer;
    end record;

    signal status : StatusRecord := (ready => '0', count => 0);
begin
    process(clk)
    begin
        if rising_edge(clk) then
            status.ready <= '1';
            status.count <= status.count + 1;
            out_signal <= status.ready;
        end if;
    end process;
end Behavioral;
⚠️

Common Pitfalls

Common mistakes when using records in VHDL include:

  • Forgetting to define the record type before declaring signals or variables.
  • Trying to assign a whole record at once without matching all fields.
  • Using incorrect dot notation or misspelling field names.
  • Not initializing record fields, which can cause simulation warnings.

Always initialize records and use correct field names to avoid errors.

vhdl
type MyRecord is record
    a : std_logic;
    b : integer;
end record;

-- Wrong: missing type definition before signal declaration
-- signal rec : UndefinedRecord;

-- Wrong: assigning incomplete record
-- rec.a <= '1';
-- rec.b <= 5;
-- rec <= (a => '1'); -- Missing field b

-- Right:
signal rec : MyRecord := (a => '0', b => 0);
📊

Quick Reference

ConceptDescriptionExample
Define Record TypeCreate a new record type with named fieldstype MyRec is record a: std_logic; b: integer; end record;
Declare Signal/VariableUse the record type to declare signals or variablessignal rec_sig : MyRec;
Assign FieldsAssign values to individual fields using dot notationrec_sig.a <= '1'; rec_sig.b <= 10;
Initialize RecordSet initial values when declaringsignal rec_sig : MyRec := (a => '0', b => 0);
Access FieldsUse dot notation to read or write fieldsx <= rec_sig.a;

Key Takeaways

Define a record type before declaring signals or variables of that type.
Use dot notation to access or assign individual fields in a record.
Always initialize record fields to avoid simulation warnings.
Records help organize related signals into one grouped data structure.
Check field names carefully to avoid syntax errors.