+ All Categories
Home > Documents > Introduction to VHDL

Introduction to VHDL

Date post: 15-Mar-2016
Category:
Upload: stephen-navarro
View: 18 times
Download: 1 times
Share this document with a friend
Description:
Introduction to VHDL. Joseph Collins, 3A Software Eng. with files from Dr. W.D. Bishop, P.Eng Email: [email protected]. What is VHDL?. Very High-Speed Integrated Circuit Hardware Description Language A popular tool for designing digital hardware. Important Concepts. Entity - PowerPoint PPT Presentation
25
Introduction to VHDL Introduction to VHDL Joseph Collins, 3A Software Joseph Collins, 3A Software Eng. Eng. with files from Dr. W.D. with files from Dr. W.D. Bishop, P.Eng Bishop, P.Eng Email: Email: [email protected] [email protected]
Transcript
Page 1: Introduction to VHDL

Introduction to VHDLIntroduction to VHDLJoseph Collins, 3A Software Eng.Joseph Collins, 3A Software Eng.with files from Dr. W.D. Bishop, with files from Dr. W.D. Bishop, P.EngP.EngEmail: Email: [email protected]@engmail.uwaterloo.ca

Page 2: Introduction to VHDL

What is VHDL?What is VHDL? Very High-Speed Integrated CircuitVery High-Speed Integrated Circuit HardwareHardware DescriptionDescription LanguageLanguage

A popular tool for designing digital A popular tool for designing digital hardwarehardware

Page 3: Introduction to VHDL

Important ConceptsImportant Concepts EntityEntity

– What the hardware looks like to the What the hardware looks like to the outside worldoutside world

– Defines inputs and outputsDefines inputs and outputs

ENTITY lab1 IS PORT ( r1, r0 : in std_logic; x, y, z : in std_logic; a, d0, d1 : out std_logic );END lab1;

Page 4: Introduction to VHDL

Important ConceptsImportant Concepts ArchitectureArchitecture

– This is the implementation of your This is the implementation of your entity.entity.

– This is where you put your gates and This is where you put your gates and stuff.stuff.

ARCHITECTURE main OF lab1 ISSIGNAL temp : std_logic;

BEGINa <= r0 AND r1;temp <= y OR z;d0 <= x AND temp;d1 <= (r0 AND x) OR temp;

END main;

Page 5: Introduction to VHDL

VHDL Data TypesVHDL Data Types std_logicstd_logic

– A wireA wire– Can be set to ‘1’ or ‘0’ (among other Can be set to ‘1’ or ‘0’ (among other

things)things)– SIGNAL a : std_logic;SIGNAL a : std_logic;– use ieee.std_logic_1164.alluse ieee.std_logic_1164.all

Page 6: Introduction to VHDL

VHDL Data TypesVHDL Data Types std_logic_vectorstd_logic_vector

– A group of wires with a similar purposeA group of wires with a similar purpose– SIGNAL v : std_logic_vector (3 DOWNTO 0);SIGNAL v : std_logic_vector (3 DOWNTO 0);

– Wires can be assigned:Wires can be assigned: individually: individually: v(3) <= ‘0’;v(3) <= ‘0’; in groups: in groups: v(1 DOWNTO 0) <= v(3 DOWNTO 2);v(1 DOWNTO 0) <= v(3 DOWNTO 2); all at once: all at once: v <= “1001”;v <= “1001”;

– use ieee.std_logic_1164.alluse ieee.std_logic_1164.all

Page 7: Introduction to VHDL

VHDL Data TypesVHDL Data Types signed/unsignedsigned/unsigned

– Used to represent signed and Used to represent signed and unsigned numbersunsigned numbers

– SIGNAL num : signed (2 downto 0);SIGNAL num : signed (2 downto 0);– Assignment similar to Assignment similar to std_logic_vectorstd_logic_vectorss

– Can do arithmetic on theseCan do arithmetic on these This includes, addition, subtraction, This includes, addition, subtraction,

multiplication, and comparisonsmultiplication, and comparisons– use ieee.numeric_std.alluse ieee.numeric_std.all

Page 8: Introduction to VHDL

Converting Between Converting Between Data TypesData Types One can convert between signed, One can convert between signed,

unsigned and std_logic_vector unsigned and std_logic_vector explicitlyexplicitly– SIGNAL x : std_logic;SIGNAL x : std_logic;– SIGNAL num : unsigned (3 DOWNTO 0);SIGNAL num : unsigned (3 DOWNTO 0);– SIGNAL v : std_logic_vector (3 SIGNAL v : std_logic_vector (3 DOWNTO 0);DOWNTO 0);

– ……– num <= unsigned(v);num <= unsigned(v);– v <= std_logic_vector(num);v <= std_logic_vector(num);– x <= v(1);x <= v(1);

Page 9: Introduction to VHDL

Combinational Combinational CircuitryCircuitry Statements that may be helpfulStatements that may be helpful

– When-else statementsWhen-else statements

– Case statementsCase statements

--a is std_logic, b is std_logic_vector (3 DOWNTO 0)--x and s are unsigned (3 DOWNTO 0)s <= x – 10;b <= “0000” WHEN a = ‘1’ ELSE std_logic_vector(x) WHEN x < 10 ELSE std_logic_vector(s);

s <= x – 10;WITH x(3 DOWNTO 1) SELECTb <= std_logic_vector(s) WHEN “101” | “110” | “111”, std_logic_vector(x) WHEN OTHERS;

Page 10: Introduction to VHDL

What questions do What questions do you have so far?you have so far?

Page 11: Introduction to VHDL

ProcessesProcesses So far, we’ve covered basic So far, we’ve covered basic

combinational circuitrycombinational circuitry Processes allow for much more Processes allow for much more

human-readable designshuman-readable designs Processes can be combinational or Processes can be combinational or

sequentialsequential– Will not cover combinational because Will not cover combinational because

they are frowned upon by SE141 TAsthey are frowned upon by SE141 TAs

Page 12: Introduction to VHDL

Sequential ProcessesSequential Processes Sequential processes run on a Sequential processes run on a

clock signalclock signal– Usually involve one or more flip-flopsUsually involve one or more flip-flops

They are NOT sequential in the They are NOT sequential in the sense that the hardware will sense that the hardware will execute one step at a timeexecute one step at a time– Hardware runs in parallelHardware runs in parallel– You can make things run You can make things run

sequentially by separating tasks into sequentially by separating tasks into multiple clock cycles.multiple clock cycles.

Page 13: Introduction to VHDL

D Flip-Flop with Chip D Flip-Flop with Chip EnableEnable Probably the second-simplest Probably the second-simplest

sequential process you will ever sequential process you will ever run intorun into

PROCESSBEGIN

WAIT UNTIL RISING_EDGE(clock);IF (ce = ‘1’) THEN

q <= d;END IF;

END PROCESS;

Page 14: Introduction to VHDL

State MachinesState Machines Flip Flops that represent a state in Flip Flops that represent a state in

your systemyour system Multiple encoding typesMultiple encoding types

– One-hotOne-hot– GrayGray– BinaryBinary

Usually used in sequential Usually used in sequential processesprocesses

Page 15: Introduction to VHDL

What questions do What questions do you have?you have?

Page 16: Introduction to VHDL

Hardware InterfacingHardware Interfacing You can easily use a provided piece You can easily use a provided piece

of hardware as part of a larger circuitof hardware as part of a larger circuit– Make sure you understand the specsMake sure you understand the specs– You needn’t know the VHDL code You needn’t know the VHDL code

behind this piece of hardwarebehind this piece of hardware This allows you to work This allows you to work

independently on separate parts of independently on separate parts of your labyour lab

Page 17: Introduction to VHDL

Interfacing a Block of Interfacing a Block of MemoryMemory We wish to integrate a piece of We wish to integrate a piece of

256x256 memory into our circuit256x256 memory into our circuitARCHITECTURE main OF circ IS

COMPONENT mem ISPORT (

i_add : in std_logic_vector (7 DOWNTO 0);i_wren : in std_logic;i_clock : in std_logic;i_data : in std_logic_vector (7 DOWNTO 0);o_q : out std_logic_vector (7 DOWNTO 0)

);END COMPONENT mem;SIGNAL address, data, q : std_logic_vector (7 DOWNTO 0);SIGNAL wren, clk : std_logic;

BEGIN…

mem1: mem PORT MAP (address, wren, clk, data, q);…END main

Page 18: Introduction to VHDL

SimulationSimulation We have covered hardware that We have covered hardware that

you can synthesize nicely for use you can synthesize nicely for use on an FPGA boardon an FPGA board

VHDL can be used to simulate VHDL can be used to simulate these circuitsthese circuits– Note: we will be using non-Note: we will be using non-

synthesizable VHDL for doing synthesizable VHDL for doing simulationssimulations

Page 19: Introduction to VHDL

How to SimulateHow to Simulate Develop your simulation planDevelop your simulation plan Prepare a new entity and do a Prepare a new entity and do a

port mapport map Use wait statements to assignUse wait statements to assign

your inputsyour inputsclock_proc: PROCESS BEGIN -- 50 MHz clockclock_proc: PROCESS BEGIN -- 50 MHz clockclk <= ‘0’;clk <= ‘0’;wait for 10 ns;wait for 10 ns;clk <= ‘1’;clk <= ‘1’;wait for 10 ns;wait for 10 ns;

END PROCESSEND PROCESS

Page 20: Introduction to VHDL

Simulation ExampleSimulation ExampleENTITY tb_lab1 ISENTITY tb_lab1 ISEND tb_lab1END tb_lab1

ARCHITECTURE main OF tb_lab1 ISARCHITECTURE main OF tb_lab1 ISCOMPONENT lab1 ISCOMPONENT lab1 IS

PORT (PORT (r0, r1, x, y, z : in std_logic;r0, r1, x, y, z : in std_logic;a, d0, d1 : out std_logica, d0, d1 : out std_logic

););END COMPONENT lab1;END COMPONENT lab1;SIGNAL r0, r1, x, y, z, a, d0, d1 : std_logic;SIGNAL r0, r1, x, y, z, a, d0, d1 : std_logic;

BEGINBEGINlab1_inst : lab1 PORT MAP (r0, r1, x, y, z, a, d0, d1);lab1_inst : lab1 PORT MAP (r0, r1, x, y, z, a, d0, d1);

r0_proc : PROCESS BEGINr0_proc : PROCESS BEGINr0 <= ‘0’;r0 <= ‘0’;wait for 10 ns;wait for 10 ns;r0 <= ‘1’;r0 <= ‘1’;wait for 10 ns;wait for 10 ns;

END PROCESS;END PROCESS;

r1_proc : PROCESS BEGINr1_proc : PROCESS BEGINr1 <= ‘0’;r1 <= ‘0’;wait for 20 ns;wait for 20 ns;r1 <= ‘1’;r1 <= ‘1’;wait for 20 ns;wait for 20 ns;

END PROCESS;END PROCESS;--etc.--etc.

END main;END main;

Page 21: Introduction to VHDL

What questions do What questions do you have?you have?

Page 22: Introduction to VHDL

Common PitfallsCommon Pitfalls Multiple Signal DriversMultiple Signal Drivers

– When you assign to a signal in When you assign to a signal in multiple locations (without multiple locations (without appropriate ifs)appropriate ifs)

Usually in multiple processesUsually in multiple processes– Best preventative measure: avoid Best preventative measure: avoid

assigning to more than one signal in a assigning to more than one signal in a given processgiven process

Processes run parallel to each otherProcesses run parallel to each other

Page 23: Introduction to VHDL

Common PitfallsCommon Pitfalls Invalid State = Undefined Invalid State = Undefined

BehaviourBehaviour– If your state machine enters an If your state machine enters an

invalid state, it should return to a invalid state, it should return to a pre-defined “reset” statepre-defined “reset” state

– This can happen by programmer This can happen by programmer error or due to environmental error or due to environmental factorsfactors

Page 24: Introduction to VHDL

What questions do What questions do you have?you have?This is about all I have.This is about all I have.

Page 25: Introduction to VHDL

Do not hesitate to Do not hesitate to contact me!contact me!- Email: - Email: [email protected]@engmail.uwaterloo.ca- I often hang out in SE lounge/lab - I often hang out in SE lounge/lab and/or MathSoc (MC 3038)and/or MathSoc (MC 3038)- Have a good Pi Day tomorrow- Have a good Pi Day tomorrow


Recommended