vhdl tutorial 3 - university of waterloosshahir/ · outline • vhdl quick look • entity •...

21
VHDL Tutorial By:Shahed Shahir Email: [email protected]

Upload: phamhanh

Post on 20-Sep-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

VHDL Tutorial

�������

������

By:Shahed ShahirEmail: [email protected]

Page 2: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

Outline• VHDL Quick Look• Entity• Architecture• Component• HalfAdder• FullAdd• Generate if Statement• Selected Signal Assignment• Generics• How to develop VHDL code using Xilinx Project

Navigator

Page 3: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

VHDL Quick Look

�� Entity�� Architecture

All the available signal types and functions can be imported by adding :

Library ieee;��������������� �������

In C:

#include <stdio.h>

Page 4: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

Entityentity < entity_identifier>is

Port(<signal identifier> : <mode> <type>;<signal identifier> : <mode> <type>;

…<signal identifier> : <mode> <type>);

end < entity_identifier >;

Example:

entity QuarterAdder is

port(

i_a : in std_logic;

i_b : in std_logic;

o_s : out std_logic);

end QuarterAdder ;

buffer

Inout

Out

In

mode

character

String

Integer

Boolean

Std_logic

type

Z (High impedance)

H (Weak High)

�������

L (Week Low)

������

- (Don’t Care)

X(Unknown)

U(Uninitialized)

W(Week Unknown)

STD_logicBoolean

Page 5: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

Architecturearchitecture <architecture_name> of <entity_identifier> is

[ architecture_declarative_part]begin

<architecture_statement> ;<architecture_statement> ;…<architecture_statement> ;

end <architecture_name>;

Example:architecture main of QuarterAdder is

begino_s <= i_a xor i_b;

end main;

Concurrent statements

Int main (void)

{

Printf(“Hello World”);

}

Page 6: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

ComponentComponent < entity_identifier>

Port(<signal identifier> : <mode> <type>;<signal identifier> : <mode> <type>;

…<signal identifier> : <mode> <type>);

end Component;

Page 7: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

VHDL Code For HalfAdderentity HalfAdder is

port(

i_a : in std_logic;

i_b : in std_logic;

o_s : out std_logic;

o_c : out std_logic);

end HalfAdder ;

architecture main of HalfAdder is

component QuarterAdder port(

i_a : in std_logic;

i_b : in std_logic;

o_s : out std_logic);

end component;

begino_c <= i_a and i_b;

�� �QuarterAdder port map( i_a, i_b, o_s);end main;

Page 8: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

FullAddLibrary iieee;Use ieee�����������������Entity FullAdd is

port (i_a, i_b,i_c : in std_logic;o_s,o_c : out std_logic);

End FullAdd;

Architecture main of FullAdd isBeging

o_s<=i_c xor i_a xor i_b;o_c<=(i_c and ( i_a or i_b)) or (i_a and i_b);

End main;

Page 9: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

Generate-If StatementLibrary ieee;Use ieee�����������������Entity adder is

Port ( ������� !���������"#���$����downto ����� ��%����������"#���$����downto ��o_c: out std_logic);

End adder;Architecture main of adder is

Component fulladdPort(

i_a, i_b, i_c : in std_logic;o_s,o_c : out std_logic);

End component;Component halfadd

Port(i_a,i_b :in std_logic;o_s,o_c : out std_logic);

End component;

&!�����$$' ���������"#���$����downto �:=“ ”;

&!����������� ���������"#���$����downto ):=“ ”; Signal initialization

Page 10: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

Generate-If Statement (con’t)Begin

(�$��!����downto �#!#$��#�)� *�+ �#!#$��#

���*��� � �halfadd --Label,�$��-�.��� ����� ����� �����$$'� ���

End generate;)�� �*�+���#!#$��#

(%�������� �fulladd,�$��-�.�����������������$$'������������������

End generate;)�� �*�/+ ��!��/+���#!#$��#

Fulladdi : fulladdPort map(a(i), b(i), carry(i-����������$$'����

End generate;End generate;

a<=i_a;o_s<=s;

End main;

Generate with if

Concurrent statements

Page 11: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

��

Selected Signal AssignmentWith <expression> select

<target> <= <waveform> when <choice>; < waveform > when <choice>;< waveform > when others;

Example:Library ieee;0�#�###������������������

Entity muxone is,�$��� ����������� �!���������

�� �!���������"#���$����downto ��o_q:out std_logic);

End muxone;Architecture main of muxone isBeginWith i_c select

��1�2+�� ���#!�“ ”;�����#!�“ �”;�����#!�“� ”;�����#!����#$��

End main;

Page 12: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

��

Generics

345657�$#��6&

��������������� ��������� �������� �!������!��� ��

port(clk,r: IN std_logic;� 64���������"#���$�� ����width - ��);1 805���������"#���$�� ����width - �));#!��$#��

9:;�653;50:3�!*#$��*�$#��6&

...*��$�+<�<����#!�12+��others => ‘’);…End infer

Page 13: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

��

LIBRARY IEEE;

������������� �����������

����������������

port(clk,r: IN std_logic;

��������� ��������� downto !"�

#��$������� ��������� downto !""�

�%��������

�&'(���'��&����������)����������

��*+�%�%���� �

generic(width:positive;

reset_value : positive);

port(

clk,r: IN std_logic;

d:IN std_logic_vector(width-� downto !"�

q:OUT std_logic_vector(width-� downto !"

);

end component;

begin

,���� ��generic map (reset_value -.���/�width -.�"�+����*,+

(clk/�/�/#�"�

�%��������

Page 14: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

��

How To Develop VHDL Code Using Xilinx Project Navigator

Page 15: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

��

• This brief tutorial will help you on how to start a VHDL project on Xilinx ,$�=#���4�"���$�������#.��'���#.�

Page 16: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

��

• new project• Select a Name for the project• Select Schematic as the project type • Click Next

Page 17: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

��

• Select the device properties• Click Next

Page 18: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

��

• Click on New Source • Select a name for your VHDL code• Choose VHDL module• Click Next and click next• Click finish

Page 19: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

��

• Click next• Click next• Click finish

Page 20: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

Page 21: VHDL Tutorial 3 - University of Waterloosshahir/ · Outline • VHDL Quick Look • Entity • Architecture • Component • HalfAdder • FullAdd • Generate if Statement • Selected

��

Any question or Comment?