SlideShare a Scribd company logo
1 of 19
Enumerated Types
The first style is used most often to define cases or states
for a state machine
type CAR_STATE is (back, stop, slow, medium, fast);
VHDL also allows users to create subtypes of a type
   The values in the subtype must be a contiguous range of values
   of the base type from start to end
   Subtype GO_KART is CAR_STATE range stop to medium;
VHDL has two predefined integer subtypes
   Subtype natural is integer range 0 to highest integer;
   Subtype positive is integer range 1 to highest integer;


                                                                    1
Enumerated Types
BIT – can be ‘0’ or ‘1’ (note single quotes)
STD_LOGIC            IEEE std_logic_1164 package

   Has NINE legal values:
   ‘U’, ‘X’, ‘0’, ‘1’, ‘Z’, ‘W’, ‘L’, ‘H’, ‘-’
Example Subtype Declarations
   Subtype twoval_logic is std_logic range ‘0’ to ‘1’;
   Subtype fourval_logic is std_logic range ‘X’ to ‘Z’;
   Subtype negint is integer range -2147483647 to -1;
   Subtype bitnum is integer range 31 downto 0;

                                                          2
Constants
They contribute to readability, maintainability and
portability of programs in any language
The syntax is as shown
constant BUS_SIZE: integer := 32; --
  width of component
constant MSB: integer := BUS_SIZE - 1; --
  bit number of MSB
constant Z: character := ‘Z’; -- synonym
  for Hi-Z value
  The value of a constant can be a simple expression
  Constants can be used anywhere the corresponding value
  can be used and they can be put to good use in type
  definitions

                                                           3
Arrays
Another very important category of user-defined types
Ordered set of elements of the same type, where each element is
selected by an array index
Syntax for VHDL array definitions
type type-name is array     (start to end) of element-type;
type type-name is array     (start downto end) of element-
  type;
type type-name is array     (range-type) of element-type;
type type-name is array     (range-type range start to end)
  of element-type;
type type-name is array     (range-type range start downto
  end) of element-type;



                                                             4
Array declarations
type monthly_count is array (1 to 12) of integer;
type byte is array (7 downto 0) of STD_LOGIC;

constant WORD_LEN: integer := 32;
type word is array (WORD_LEN - 1 downto 0) of STD_LOGIC;

constant NUM_REGS: integer := 8;
type reg_file is array ( 1 to NUM_REGS ) of word;

type traffic_light_state is (reset, stop, wait, go);
type statecount is array (traffic_light_state) of integer;
  Array elements are considered to be ordered from left to right in
  the same direction as index range
                                                                5
Array declarations
type monthly_count is array (1 to 12) of integer; 1
type byte is array (7 downto 0) of STD_LOGIC; 7

Constant WORD_LEN: integer := 32;
type word is array (WORD_LEN - 1 downto 0) of STD_LOGIC; 31

Constant NUM_REGS: integer := 8;
type reg_file is array ( 1 to NUM_REGS ) of word; 1

Type traffic_light_state is (reset, stop, wait, go);
type statecount is array (traffic_light_state) of integer;
                                                        reset
  Left most elements of arrays are shown in blue
                                                        6
Array elements and literals
Within VHDL program statements, individual array elements
are accessed using the array name and the element’s index in
parentheses.
If M, B, W, R, and S are signals of variables of the five array
types defined in the previous slides then M(11), B(5),
W(WORD_LEN – 5), R(0,0), R(0) and S(reset) are all valid
elements.
Array literals can be specified by listing the element values in
parentheses. The byte variable B could be set to all ones by the
statement
B := (‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’);

                                                            7
Array elements and literals
VHDL also has a shorthand notation that allows you to specify
values by index.
To set word variable W to all ones except for zeroes in the LSB
of each byte
W := (0 => ‘0’, 8 => ‘0’, 16 => ‘0’, 24 => ‘0’, others => 1);
The methods work for arrays with any element type, but the
easiest way to write a literal of type STD_LOGIC is to use a
“string”
VHDL string is an array of ISO characters enclosed in double
quotes such as “Hello”
                                                                8
String
A string is just an array of characters.
A STD_LOGIC array of a given length can be
assigned the value of a string of the same length, as
long as the characters in the string are taken from the
set of nine characters defined as the possible values of
the STD_LOGIC elements like ‘0’, ‘1’, ‘U’
 The two previous examples can be rewritten as
B := “11111111”;
W := “11111110111111101111111011111110”;
                                                   9
Example: LogicFcn
                  ports



     A
     B
     C                                   Y




         entity           architecture
                                             10
Entity Declaration for LogicFcn
 library IEEE;
 use IEEE.std_logic_1164.all;
  entity LogicFcn is
   port (
                        A
   A: in std_logic;     B         Y
   B: in std_logic;     C

   C: in std_logic;
   Y: out std_logic
   );
 end entity LogicFcn;
                                      11
Parts of Architecture Body
architecture     ARCH_NAME      of    ENTITY_NAME        is

  <declarative section : list internal signals, variables,
   and components here. For each component used
   show the port map, (unless port map defined is in a
   “package”) >
begin

 <statement section : all concurrent statements and
  components and processes in this section execute at
  the same time, NOT sequentially>
end ARCH_NAME;

                                                              12
Architecture Body
Specifies the internal circuit of an entity, using any
   one of the following modeling styles:
1. As a set of interconnected components, as wired
   (called structural modeling)
2. As a set of concurrent signal assignment
   statements (called dataflow modeling)
3. As a set of sequential assignment statements,
   i.e., a “process” (called behavioral modeling)
4. As any combination of the above (called mixed
   modeling)

                                                         13
Architecture Body (Dataflow)

With a signal assignment statement:

    architecture dataflow of LogicFcn is
    begin
      Y <= (not A and not B) or C;
    end dataflow;




                                           14
Architecture Body (Dataflow)

With a conditional signal assignment statement:
    architecture dataflow of LogicFcn is
    begin
      Y <= '1' when (A = '0' AND B = '0') OR
                    (C = '1')
              else '0';
    end dataflow;




                                                  15
Architecture Body (Behavioral)
             architecture behavioral of LogicFcn is
“Label:”
             begin                               Sensitivity List - The Process will
                                                 be executed anytime there is an
Name of        fcn: process (A,B,C)              EVENT (change of state) on one of
process                                          these signals.
               begin
                 wait on A,B,C;                  WAIT ON statement - has same
                                                 effect as sensitivity list.
                 if (A = '0' and B = '0') then   CANNOT USE BOTH.
                                                 Processes with WAIT statements
                   Y <= '1';                     cannot have sensitivity lists !!

   process       elsif C = '1' then
                   Y <= '1';                     Statements within Processes are
                                                 executed sequentially. (This is a
                 else                            single IF statement)
                                                 The process, however, executes
                   Y <= '0';                     concurrently with other processes
                                                 and concurrent statements in the
                 end if;                         architecture.
               end process;
             end behavioral;
                                       Values are assigned to signals when process suspends
                                                                                              16
Architecture Body (Structural)
Internal signals are LOCAL to the Architecture, and cannot
be seen outside it !
                             signals

                         notA
           A                            andSignal


           B             notB


           C                                            Y




               entity            architecture
                                                             17
Architecture Body (Structural)
               architecture structural of LogicFcn is       LOCAL SIGNALS are
COMPONENT        signal notA, notB, andSignal: std_logic;   declared within the
declarations   begin                                        architecture and they
may go here      i1: inverter port map (i => A,
                                                            have no MODE (IN,
                                                            OUT, etc.)
                                       o => notA);
                 i2: inverter port map (i => B,
                                       o => notB);          These are
                 a1: and2 port map (i1 => notA,             COMPONENT
                                    i2 => notB,             INSTANTIATIONS
                                    y => andSignal);
                 o1: or2 port map (i1 => andSignal,
                                   i2 => C,
                                   y => Y);
               end structural;

                                                                          18
Components for Structural Model
   library IEEE;                       component OR2 port (
   use IEEE.std_logic_1164.all;            i1: in std_logic;
   package primitive is                    i2: in std_logic;
   component AND2 port (                   y: out std_logic
       i1: in std_logic;                   );
       i2: in std_logic;               end component;
       y: out std_logic                component INVERTER port (
       );                                  i: in std_logic;
   end component;                          o: out std_logic
                                           );
                                       end component;
                                       end primitive;



                                  these are component declarations
                                                                   19

More Related Content

What's hot

What's hot (20)

Basic concepts in Verilog HDL
Basic concepts in Verilog HDLBasic concepts in Verilog HDL
Basic concepts in Verilog HDL
 
Convolutional Codes And Their Decoding
Convolutional Codes And Their DecodingConvolutional Codes And Their Decoding
Convolutional Codes And Their Decoding
 
Vhdl introduction
Vhdl introductionVhdl introduction
Vhdl introduction
 
Verilog hdl
Verilog hdlVerilog hdl
Verilog hdl
 
VHDL CODES
VHDL CODES VHDL CODES
VHDL CODES
 
Verilog Tasks and functions
Verilog Tasks and functionsVerilog Tasks and functions
Verilog Tasks and functions
 
Modules and ports in Verilog HDL
Modules and ports in Verilog HDLModules and ports in Verilog HDL
Modules and ports in Verilog HDL
 
Pass Transistor Logic
Pass Transistor LogicPass Transistor Logic
Pass Transistor Logic
 
Logic families
Logic familiesLogic families
Logic families
 
Fet small signal model
Fet small signal modelFet small signal model
Fet small signal model
 
Introduction to VHDL - Part 1
Introduction to VHDL - Part 1Introduction to VHDL - Part 1
Introduction to VHDL - Part 1
 
Lect 7: Verilog Behavioral model for Absolute Beginners
Lect 7: Verilog Behavioral model for Absolute BeginnersLect 7: Verilog Behavioral model for Absolute Beginners
Lect 7: Verilog Behavioral model for Absolute Beginners
 
Programmable logic array
Programmable logic arrayProgrammable logic array
Programmable logic array
 
Verilog presentation final
Verilog presentation finalVerilog presentation final
Verilog presentation final
 
Master slave jk flip flop.pdf
Master slave jk flip flop.pdfMaster slave jk flip flop.pdf
Master slave jk flip flop.pdf
 
Data Flow Modeling
Data Flow ModelingData Flow Modeling
Data Flow Modeling
 
Crash course in verilog
Crash course in verilogCrash course in verilog
Crash course in verilog
 
Vhdl 1 ppg
Vhdl 1 ppgVhdl 1 ppg
Vhdl 1 ppg
 
Hybrid model for Transistor, small signal Analysis
Hybrid model for Transistor, small signal AnalysisHybrid model for Transistor, small signal Analysis
Hybrid model for Transistor, small signal Analysis
 
Slew rate, Open and closed loop configurations
Slew rate, Open and closed loop configurationsSlew rate, Open and closed loop configurations
Slew rate, Open and closed loop configurations
 

Viewers also liked

Sequential Circuits - Flip Flops
Sequential Circuits - Flip FlopsSequential Circuits - Flip Flops
Sequential Circuits - Flip Flops
Abhilash Nair
 
Designing Clocked Synchronous State Machine
Designing Clocked Synchronous State MachineDesigning Clocked Synchronous State Machine
Designing Clocked Synchronous State Machine
Abhilash Nair
 
Sequential Circuits - Flip Flops (Part 1)
Sequential Circuits - Flip Flops (Part 1)Sequential Circuits - Flip Flops (Part 1)
Sequential Circuits - Flip Flops (Part 1)
Abhilash Nair
 
State Machine Design and Synthesis
State Machine Design and SynthesisState Machine Design and Synthesis
State Machine Design and Synthesis
Abhilash Nair
 
Sequential Circuits - Flip Flops (Part 2)
Sequential Circuits - Flip Flops (Part 2)Sequential Circuits - Flip Flops (Part 2)
Sequential Circuits - Flip Flops (Part 2)
Abhilash Nair
 
Static and Dynamic Read/Write memories
Static and Dynamic Read/Write memoriesStatic and Dynamic Read/Write memories
Static and Dynamic Read/Write memories
Abhilash Nair
 
Analysis of state machines & Conversion of models
Analysis of state machines & Conversion of modelsAnalysis of state machines & Conversion of models
Analysis of state machines & Conversion of models
Abhilash Nair
 

Viewers also liked (20)

VHDL Part 4
VHDL Part 4VHDL Part 4
VHDL Part 4
 
CPLDs
CPLDsCPLDs
CPLDs
 
Sequential Circuits - Flip Flops
Sequential Circuits - Flip FlopsSequential Circuits - Flip Flops
Sequential Circuits - Flip Flops
 
MSI Shift Registers
MSI Shift RegistersMSI Shift Registers
MSI Shift Registers
 
Designing Clocked Synchronous State Machine
Designing Clocked Synchronous State MachineDesigning Clocked Synchronous State Machine
Designing Clocked Synchronous State Machine
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in C
 
FPLDs
FPLDsFPLDs
FPLDs
 
How to design Programs using VHDL
How to design Programs using VHDLHow to design Programs using VHDL
How to design Programs using VHDL
 
Synchronous design process
Synchronous design processSynchronous design process
Synchronous design process
 
CPLDs
CPLDsCPLDs
CPLDs
 
Sequential Circuits - Flip Flops (Part 1)
Sequential Circuits - Flip Flops (Part 1)Sequential Circuits - Flip Flops (Part 1)
Sequential Circuits - Flip Flops (Part 1)
 
State Machine Design and Synthesis
State Machine Design and SynthesisState Machine Design and Synthesis
State Machine Design and Synthesis
 
Basics of Vhdl
Basics of VhdlBasics of Vhdl
Basics of Vhdl
 
CPLD & FPLD
CPLD & FPLDCPLD & FPLD
CPLD & FPLD
 
Sequential Circuits - Flip Flops (Part 2)
Sequential Circuits - Flip Flops (Part 2)Sequential Circuits - Flip Flops (Part 2)
Sequential Circuits - Flip Flops (Part 2)
 
Static and Dynamic Read/Write memories
Static and Dynamic Read/Write memoriesStatic and Dynamic Read/Write memories
Static and Dynamic Read/Write memories
 
FPGA
FPGAFPGA
FPGA
 
DRAM
DRAMDRAM
DRAM
 
Analysis of state machines & Conversion of models
Analysis of state machines & Conversion of modelsAnalysis of state machines & Conversion of models
Analysis of state machines & Conversion of models
 
Analysis of state machines
Analysis of state machinesAnalysis of state machines
Analysis of state machines
 

Similar to VHDL - Enumerated Types (Part 3)

3CA949D5-0399-46AE-8A97-F01C8599B2DA.pdf
3CA949D5-0399-46AE-8A97-F01C8599B2DA.pdf3CA949D5-0399-46AE-8A97-F01C8599B2DA.pdf
3CA949D5-0399-46AE-8A97-F01C8599B2DA.pdf
SantoshDeshmukh36
 

Similar to VHDL - Enumerated Types (Part 3) (20)

Hd2
Hd2Hd2
Hd2
 
Introduction to VHDL
Introduction to VHDLIntroduction to VHDL
Introduction to VHDL
 
Basic Coding In VHDL COding
Basic Coding In VHDL COdingBasic Coding In VHDL COding
Basic Coding In VHDL COding
 
digital system design using verilog Module 5 ppt.pptx
digital system design using verilog Module 5 ppt.pptxdigital system design using verilog Module 5 ppt.pptx
digital system design using verilog Module 5 ppt.pptx
 
VHDL PROGRAMS FEW EXAMPLES
VHDL PROGRAMS FEW EXAMPLESVHDL PROGRAMS FEW EXAMPLES
VHDL PROGRAMS FEW EXAMPLES
 
3CA949D5-0399-46AE-8A97-F01C8599B2DA.pdf
3CA949D5-0399-46AE-8A97-F01C8599B2DA.pdf3CA949D5-0399-46AE-8A97-F01C8599B2DA.pdf
3CA949D5-0399-46AE-8A97-F01C8599B2DA.pdf
 
VHDL
VHDLVHDL
VHDL
 
Vhdl
VhdlVhdl
Vhdl
 
COMPILER_DESIGN_CLASS 2.ppt
COMPILER_DESIGN_CLASS 2.pptCOMPILER_DESIGN_CLASS 2.ppt
COMPILER_DESIGN_CLASS 2.ppt
 
COMPILER_DESIGN_CLASS 1.pptx
COMPILER_DESIGN_CLASS 1.pptxCOMPILER_DESIGN_CLASS 1.pptx
COMPILER_DESIGN_CLASS 1.pptx
 
Kroening et al, v2c a verilog to c translator
Kroening et al, v2c   a verilog to c translatorKroening et al, v2c   a verilog to c translator
Kroening et al, v2c a verilog to c translator
 
Spdas2 vlsibput
Spdas2 vlsibputSpdas2 vlsibput
Spdas2 vlsibput
 
Vhdl lab manual
Vhdl lab manualVhdl lab manual
Vhdl lab manual
 
the-vhsic-.pptx
the-vhsic-.pptxthe-vhsic-.pptx
the-vhsic-.pptx
 
Ddhdl 17
Ddhdl 17Ddhdl 17
Ddhdl 17
 
Verilogforlab
VerilogforlabVerilogforlab
Verilogforlab
 
Programs of VHDL
Programs of VHDLPrograms of VHDL
Programs of VHDL
 
Verilog lab manual (ECAD and VLSI Lab)
Verilog lab manual (ECAD and VLSI Lab)Verilog lab manual (ECAD and VLSI Lab)
Verilog lab manual (ECAD and VLSI Lab)
 
Digital Electronics .
Digital Electronics                                              .Digital Electronics                                              .
Digital Electronics .
 
Digital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECEDigital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECE
 

More from Abhilash Nair (12)

Feedback Sequential Circuits
Feedback Sequential CircuitsFeedback Sequential Circuits
Feedback Sequential Circuits
 
Designing State Machine
Designing State MachineDesigning State Machine
Designing State Machine
 
CPLDs
CPLDsCPLDs
CPLDs
 
Documentation Standards of an IC
Documentation Standards of an ICDocumentation Standards of an IC
Documentation Standards of an IC
 
Shift Registers
Shift RegistersShift Registers
Shift Registers
 
MSI Counters
MSI CountersMSI Counters
MSI Counters
 
EPROM, PROM & ROM
EPROM, PROM & ROMEPROM, PROM & ROM
EPROM, PROM & ROM
 
Counters
CountersCounters
Counters
 
Trends Of Televisions
Trends Of TelevisionsTrends Of Televisions
Trends Of Televisions
 
Core java slides
Core java slidesCore java slides
Core java slides
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 

VHDL - Enumerated Types (Part 3)

  • 1. Enumerated Types The first style is used most often to define cases or states for a state machine type CAR_STATE is (back, stop, slow, medium, fast); VHDL also allows users to create subtypes of a type The values in the subtype must be a contiguous range of values of the base type from start to end Subtype GO_KART is CAR_STATE range stop to medium; VHDL has two predefined integer subtypes Subtype natural is integer range 0 to highest integer; Subtype positive is integer range 1 to highest integer; 1
  • 2. Enumerated Types BIT – can be ‘0’ or ‘1’ (note single quotes) STD_LOGIC IEEE std_logic_1164 package Has NINE legal values: ‘U’, ‘X’, ‘0’, ‘1’, ‘Z’, ‘W’, ‘L’, ‘H’, ‘-’ Example Subtype Declarations Subtype twoval_logic is std_logic range ‘0’ to ‘1’; Subtype fourval_logic is std_logic range ‘X’ to ‘Z’; Subtype negint is integer range -2147483647 to -1; Subtype bitnum is integer range 31 downto 0; 2
  • 3. Constants They contribute to readability, maintainability and portability of programs in any language The syntax is as shown constant BUS_SIZE: integer := 32; -- width of component constant MSB: integer := BUS_SIZE - 1; -- bit number of MSB constant Z: character := ‘Z’; -- synonym for Hi-Z value The value of a constant can be a simple expression Constants can be used anywhere the corresponding value can be used and they can be put to good use in type definitions 3
  • 4. Arrays Another very important category of user-defined types Ordered set of elements of the same type, where each element is selected by an array index Syntax for VHDL array definitions type type-name is array (start to end) of element-type; type type-name is array (start downto end) of element- type; type type-name is array (range-type) of element-type; type type-name is array (range-type range start to end) of element-type; type type-name is array (range-type range start downto end) of element-type; 4
  • 5. Array declarations type monthly_count is array (1 to 12) of integer; type byte is array (7 downto 0) of STD_LOGIC; constant WORD_LEN: integer := 32; type word is array (WORD_LEN - 1 downto 0) of STD_LOGIC; constant NUM_REGS: integer := 8; type reg_file is array ( 1 to NUM_REGS ) of word; type traffic_light_state is (reset, stop, wait, go); type statecount is array (traffic_light_state) of integer; Array elements are considered to be ordered from left to right in the same direction as index range 5
  • 6. Array declarations type monthly_count is array (1 to 12) of integer; 1 type byte is array (7 downto 0) of STD_LOGIC; 7 Constant WORD_LEN: integer := 32; type word is array (WORD_LEN - 1 downto 0) of STD_LOGIC; 31 Constant NUM_REGS: integer := 8; type reg_file is array ( 1 to NUM_REGS ) of word; 1 Type traffic_light_state is (reset, stop, wait, go); type statecount is array (traffic_light_state) of integer; reset Left most elements of arrays are shown in blue 6
  • 7. Array elements and literals Within VHDL program statements, individual array elements are accessed using the array name and the element’s index in parentheses. If M, B, W, R, and S are signals of variables of the five array types defined in the previous slides then M(11), B(5), W(WORD_LEN – 5), R(0,0), R(0) and S(reset) are all valid elements. Array literals can be specified by listing the element values in parentheses. The byte variable B could be set to all ones by the statement B := (‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’); 7
  • 8. Array elements and literals VHDL also has a shorthand notation that allows you to specify values by index. To set word variable W to all ones except for zeroes in the LSB of each byte W := (0 => ‘0’, 8 => ‘0’, 16 => ‘0’, 24 => ‘0’, others => 1); The methods work for arrays with any element type, but the easiest way to write a literal of type STD_LOGIC is to use a “string” VHDL string is an array of ISO characters enclosed in double quotes such as “Hello” 8
  • 9. String A string is just an array of characters. A STD_LOGIC array of a given length can be assigned the value of a string of the same length, as long as the characters in the string are taken from the set of nine characters defined as the possible values of the STD_LOGIC elements like ‘0’, ‘1’, ‘U’ The two previous examples can be rewritten as B := “11111111”; W := “11111110111111101111111011111110”; 9
  • 10. Example: LogicFcn ports A B C Y entity architecture 10
  • 11. Entity Declaration for LogicFcn library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A A: in std_logic; B Y B: in std_logic; C C: in std_logic; Y: out std_logic ); end entity LogicFcn; 11
  • 12. Parts of Architecture Body architecture ARCH_NAME of ENTITY_NAME is <declarative section : list internal signals, variables, and components here. For each component used show the port map, (unless port map defined is in a “package”) > begin <statement section : all concurrent statements and components and processes in this section execute at the same time, NOT sequentially> end ARCH_NAME; 12
  • 13. Architecture Body Specifies the internal circuit of an entity, using any one of the following modeling styles: 1. As a set of interconnected components, as wired (called structural modeling) 2. As a set of concurrent signal assignment statements (called dataflow modeling) 3. As a set of sequential assignment statements, i.e., a “process” (called behavioral modeling) 4. As any combination of the above (called mixed modeling) 13
  • 14. Architecture Body (Dataflow) With a signal assignment statement: architecture dataflow of LogicFcn is begin Y <= (not A and not B) or C; end dataflow; 14
  • 15. Architecture Body (Dataflow) With a conditional signal assignment statement: architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; 15
  • 16. Architecture Body (Behavioral) architecture behavioral of LogicFcn is “Label:” begin Sensitivity List - The Process will be executed anytime there is an Name of fcn: process (A,B,C) EVENT (change of state) on one of process these signals. begin wait on A,B,C; WAIT ON statement - has same effect as sensitivity list. if (A = '0' and B = '0') then CANNOT USE BOTH. Processes with WAIT statements Y <= '1'; cannot have sensitivity lists !! process elsif C = '1' then Y <= '1'; Statements within Processes are executed sequentially. (This is a else single IF statement) The process, however, executes Y <= '0'; concurrently with other processes and concurrent statements in the end if; architecture. end process; end behavioral; Values are assigned to signals when process suspends 16
  • 17. Architecture Body (Structural) Internal signals are LOCAL to the Architecture, and cannot be seen outside it ! signals notA A andSignal B notB C Y entity architecture 17
  • 18. Architecture Body (Structural) architecture structural of LogicFcn is LOCAL SIGNALS are COMPONENT signal notA, notB, andSignal: std_logic; declared within the declarations begin architecture and they may go here i1: inverter port map (i => A, have no MODE (IN, OUT, etc.) o => notA); i2: inverter port map (i => B, o => notB); These are a1: and2 port map (i1 => notA, COMPONENT i2 => notB, INSTANTIATIONS y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; 18
  • 19. Components for Structural Model library IEEE; component OR2 port ( use IEEE.std_logic_1164.all; i1: in std_logic; package primitive is i2: in std_logic; component AND2 port ( y: out std_logic i1: in std_logic; ); i2: in std_logic; end component; y: out std_logic component INVERTER port ( ); i: in std_logic; end component; o: out std_logic ); end component; end primitive; these are component declarations 19