134
hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir ر اک د و خ ی ح را ط ر اک د و خ ی ح را ط4 4 - - 1 1 ار ز ف ا ت خ س ف ي ص و ت ان" ب ر ار ز ف ا ت خ س ف ي ص و ت ان" ب رVHDL VHDL اره ه" ب رم ت85 - 84 ان- گاه کاش- ش ن داLec note 4 هارم2 چ ل ص ف

Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

Embed Size (px)

Citation preview

Page 1: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 11

زبان توصيف سخت افزارزبان توصيف سخت افزار

VHDLVHDL84-85ترم بهاره

دانشگاه کاشانLec note 4

فصل چهارم

Page 2: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 22

)تاريخچه()تاريخچه( مقدمهمقدمه

نامVHDL شامل دو بخشV وHDL به معنی

VHSIC : Very High Speed Integrated Circuits

HDL : Hardware Description Language

استانداردIEEE 1076-1987

استانداردIEEE 1076-1993

Verilog و ABEL (Advanced Boolean Equation Language )

Page 3: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 33

)ویژگی ها()ویژگی ها( مقدمهمقدمه

HDL)هستند ها ذاتا موازي )همروند نيست مهم دستورات ترتيب رخداد بر مبتني دارد نيز را ترتيبي دستورات از استفاده امكان

اهداف اساسی : استفاده تبادل، ارائه، نگهداری، سازي مستند

مجدد : ارزیابی و نتایج بررسی سازي شبيه : سازی پیاده هدف با بصورت FPGAدر سنتز ASICیا

اجرا= شبیه سازی

Page 4: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 44

)نیازمندی ها()نیازمندی ها( مقدمهمقدمه

حداقل نیازمندی ها برای یادگیری زبانVHDL

مدارات با آشنایی و بول جبر دانستنمنطقی

ابزار مناسب CADداشتن

Page 5: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 55

توصیف رفتاری و ساختاریتوصیف رفتاری و ساختاری

سه حوزه رفتاری، ساختاری و هندسی)فیزیکی( داریم

VHDL امکان توصیف طرح بصورت رفتاری : و ساختاری

Page 6: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 66

توصیف رفتاریتوصیف رفتاری

نکته: توصیف رفتاری نسبت به توصیف ساختاری از سطح انتزاع باالتری برخوردار است

: توصیف رفتاری چیست؟ سیستم رفتار خروجی و ورودی های سیگنال بین رابطه

: توصیف رفتاری یا ثبات جمالت ) Data Flowانتقال اساس بر معموال

همروند( الگوریتمی Algorithmic) ترتیبی) دستورات از استفاده با

Page 7: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 77

مثال ساده(مثال ساده(توصیف رفتاری )توصیف رفتاری )

مدار هشدار باز بودن کمربند و درب خودرو

Warning = Ignition_on AND (Door_open OR Seatbelt_off)

Ignition_onسویچ در جایش قرار گرفته : Door_openباز بودن درب خودرو : Seatbelt_offکمربند بسته نشده : Warningخروجی هشدار به سرنشین خودرو :

Page 8: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 88

توصیف ساختاریتوصیف ساختاری

: توصیف ساختاری) ها ) دروازه ها مولفه از ای مجموعه آنها بین اتصاالت و

: توصیف ساختاری شماتیک مشابه سیستم فیزیکی تحقق به نزدیک

Page 9: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 99

VHDLVHDLساختار كلي يك فايل ساختار كلي يك فايل

يك توصيفVHDL شامل Entity declaration

Architecture body

تعريفentity در حقیقت معرفی سیگنالهای ورودی و خروجی

است

architecture رابطه بین سیگنالهای ورودی و خروجی

است )عملكرد/ساختار(

Page 10: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 1010

EntityEntityبخش بخش

NAME_OF_ENTITY يك شناسه اختياري : signal_namesسيگنالهاي ورودي يا خروجي : mode یکی از موارد: (in،out ،buffer ، Inout)

Page 11: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 1111

modemode Inسيگنال ورودي: out سيگنال خروجي )فقط توسط یک : entity دیگر

قابل استفاده(buffer خروجي كه مي تواند در داخل : entity نيز

استفاده شودInout)سيگنا ل دوطرفه )ورودي / خروجي :

in

out

out

in

in Inout

buffer

Page 12: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 1212

TypeType

نوع سيگنال را مشخص مي كند ) استاندارد ياUser Defined)

Bit : باشد داشته يك يا صفر مقدار تواند ميBit_vector : است بيتي مقادير از برداريBoolean :مقدار تواند .falseيا trueمي بگيرد Integer : صحيح عددReal : حقيقي عددCharacter : چاپ قابل هركاراكترTime . رود : مي بكار زمان نمايش ی برا

Page 13: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 1313

EntityEntityمثال مثال

تعريفentity برای يك نيم جمع كننده

Page 14: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 1414

ArchitectureArchitectureبخش بخش توصیف سیستم بصورت رفتاری یا ساختاری

است قالب كلي تعريفArchitecture به شكل زير است

Page 15: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 1515

((Behavioral modelBehavioral model)) مدل رفتاري مدل رفتاري

مستقل از ساختار داخلی ارتباط بین ورودی هاو خروجی ها بصورت عملیاتی توصیف می

.شود(1مثال :)ANDدو ورودی

Page 16: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 1616

((Behavioral modelBehavioral model)) مدل رفتاري مدل رفتاري (1مثال :)XORدو ورودی

Page 17: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 1717

هم رونديهم روندي

يكي از خصوصيات زبانهاي توصيف سخت افزار ( دستورالعملهاي انتساب سيگنال=<) وقتي اجرا مي شود كه يك سيگنال در سمت

راست جمله مقدارش تغييركند تغيير در مقدار يك سيگنال را يك رخداد مي

ناميمVHDL رخداد مبتني بر يك زبان (ترتيب نوشتن جمالت مهم نيست. 2در مثال )

را بترتيب دلخواه z و y و xيعني مي توان جمالت جابجا كرد.

Page 18: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 1818

زمانبندي رخداد هازمانبندي رخداد ها

مكانيزم ايجاد تاخير در انتساب مقدار جديد به سيگنال سمت چپ

با استفاده از كلمه كليديafter

مدل كردن تاخیر های یک مدار واقعی را مدل

اين قابليت شبيه سازي مدار را به واقعيت نزدیک تر مي كند

Page 19: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 1919

((33مثال)مثال) توصيف رفتاري مدارHalf Adder

Page 20: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 2020

توصيف ساختاريتوصيف ساختاريتعریف کامل تمام مولفه ها در ابتدا الزامی استنکته:

----------------------------------------------Entity halfadder isport ( x, y : in bit; S, CO: out bit);end halfadder;----------------------------------------------architecture structural of halfadder is-- Declarations

component AND2port (in1, in2: in std_logic;

out1: out std_logic);end component;component XOR2

port (in1, in2: in std_logic; out1: out std_logic);

end component;----------------------------------------------begin -- Component instantiations statements

U0: XOR2 port map (x, y, s);U1: AND2 port map (x, y, co);

end structural;----------------------------------------------

std_logic

Page 21: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 2121

architecture structural of BUZZER is

-- Declarations

component AND2

port (in1, in2: in std_logic;

out1: out std_logic);

end component;

component OR2

port (in1, in2: in std_logic;

out1: out std_logic);

end component;

component NOT1

port (in1: in std_logic;

out1: out std_logic);

end component;

-- declaration of signals used to interconnect gates

signal DOOR_NOT, SBELT_NOT, B1, B2: std_logic;

begin

-- Component instantiations statements

U0: NOT1 port map (DOOR, DOOR_NOT);

U1: NOT1 port map (SBELT, SBELT_NOT);

U2: AND2 port map (IGNITION, DOOR_NOT, B1);

U3: AND2 port map (IGNITION, SBELT_NOT, B2);

U4: OR2 port map (B1, B2, WARNING);

end structural;

توصيف ساختاريتوصيف ساختاريentity BUZZER is port (DOOR, IGNITION, SBELT: in

std_logic; WARNING: out std_logic);

end BUZZER;

Page 22: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 2222

طراحي سلسله مراتبيطراحي سلسله مراتبي

در مدلسازي ساختاري هرEntity توصيف در مولفه يك بعنوان تواند Entityمی

رود بكار ديگر شود تكرار مختلف سطوح در تواند مي امر اين

طراحي سلسله مراتبي موجب كاهش پيچيدگي در طراحي مدارات بزرگ مي شود

معموال در طرح هايی که با تکرار قابل گسترش اند كاربرد دارد

Page 23: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 2323

جمع كننده چهار بيتيجمع كننده چهار بيتي

sum = (A B) Ccarry = AB + C(A B)

Page 24: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 2424

توصيف تمام جمع كنندهتوصيف تمام جمع كننده

-----------------------------------------------------library ieee;use ieee.std_logic_1164.all;-----------------------------------------------------entity FULLADDER is

port (a, b, c: in std_logic;sum, carry: out std_logic);

end FULLADDER;-----------------------------------------------------architecture fulladder_behav of FULLADDER is

beginsum <= (a xor b) xor c ;carry <= (a and b) or (c and (a xor b));end fulladder_behav;

-----------------------------------------------------

Page 25: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 2525

((EntityEntityجمع كننده چهار بيتي)جمع كننده چهار بيتي)

library ieee;use ieee.std_logic_1164.all;-----------------------------------------------------entity FOURBITADD is

port (a, b : in std_logic_vector(3 downto 0); Cin : in std_logic; Sum : out std_logic_vector (3 downto 0);

Cout,V : out std_logic);end FOURBITADD;

-----------------------------------------------------

Page 26: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 2626

( (ArchitectureArchitectureجمع كننده چهار بيتي) جمع كننده چهار بيتي) architecture fouradder_structure of FOURBITADD is

signal c: std_logic_vector (4 downto 0);component FULLADDER

port(a, b, c: in std_logic; sum, carry: out std_logic);

end component;begin

FA0: FULLADDERport map (a(0), b(0), Cin, sum(0), c(1));

FA1: FULLADDERport map (a(1), b(1), C(1), sum(1), c(2));

FA2: FULLADDERport map (a(2), b(2), C(2), sum(2), c(3));

FA3: FULLADDERport map (a(3), b(3), C(3), sum(3), c(4));

V <= c(3) xor c(4);Cout <= c(4);

end fouradder_structure; 

Page 27: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 2727

چند نکتهچند نکته

استفاده از نام پورت مشترک برایEntity های متداخل مجاز است

چونCout بصورت خروجی تعریف شده نمیتواند بعنوان ورودی استفاده شود

چونc)4( یک سیگنال داخلی است میتواند بعنوان ورودی استفاده شود.

میتواند بخشی از توصیف طرح ساختاری و در مثال قبل V و Coutبخشی رفتاری باشد مانند

Page 28: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 2828

و بسته ها و بسته ها كتابخانهكتابخانه

كتابخانه امكان استفاده مشترك از موارد ازپیش تعریف شده را فراهم می کند. مانند

data type

component

Function

Procedure

هر کتابخانه شامل تعدادی بسته است نوعstd_logic در بسته ieee.std_logic_1164 در

تعريف شده است ieeeكتابخانه library ieee;

use ieee.std_logic_1164.all;

Page 29: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 2929

VHDLVHDLعناصر گرامري زبان عناصر گرامري زبان

شناسه ها )كلمات كليدي )رزرو شدهاعداد ه هاي بيتيكاراكترها رشته ها و رشت

Page 30: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 3030

شناسه هاشناسه ها

كلماتي براي نام گذاري مولفه های مختلفVHDLمدل

ورودي هاي سيگنال نام خروجي های سیگنال نام نامentity نامarchitecture

Page 31: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 3131

قوانين نامگذاری شناسه های اصلیقوانين نامگذاری شناسه های اصلی نام شناسه اختياري است( فقط شامل حروف الفبا و ارقامA..Z و a..z

'_' ( و كاراكتر 9..0واولين كاراكتر حتما بايد از حروف الفبا باشد باشد'_'آخرين كاراكتر نبايد دنبال هم غير مجاز '_'دو كاراكتر به حروف بزرگ و كوچك حساس نيستAnd2) =AND2

= and2 )

يك شناسه هر طولي مي تواند داشته باشد X10 ، x_10 ، My_gate1مثال شناسه صحیح:

X10 ، my_gate@input، gate-input_ مثال شناسه غلط:

Page 32: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 3232

قوانين گسترش یافته تعریف شناسه هایقوانين گسترش یافته تعریف شناسه های

قرار می گیرند'\' بین دو عدد

به حروف بزرگ و كوچك حساس

كلمات رزرو شده و شناسه هاي اصلي در شناسه هایگسترش مجاز و بعنوان یک شناسه متفاوت در نظر

گرفته می شود

استفاده از هر كاراكتري و با هر ترتيبي '\'بين هر دو مجاز است

شناسه اي بنامBUS:\data را بايد بنويسيم \BUS:\\data\

درنسخهVHDL-93 تعريف شده است ولي درنسخهVHDL-87شناخته شده نيست

\Input، \Input\ ، \input#1\ ، \Rst\\as مثال صحیح:

Page 33: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 3333

كلمات كليدي )رزرو شده(كلمات كليدي )رزرو شده(

شناسه هاي كه بوسيله سيستم براي کارخاص استفاده می شود

مثلin، out، or، and، port، map، end و غيره

(در شناسه توسعه يافته مجاز است\end\ )

كليه كلمات رزرو 1-4مراجعه کنید به جدول( ( VHDLشدة

Page 34: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 3434

اعداداعداد : 256 10 12اعداد صحيحE3 12e+6 :3.14 256.24 1.2اعداد حقيقيE-2 وگرنه به صورت است10پيش فرض مبناي

base#number#

18مثال: معادل عدد مبناي #10010#2: 2در

مبناي #12#16:16در

مبناي #22#8: 8در

بمنظور خوانایی

2#1001_1101_1100_0010# 215_123

29 مثال: معادل عدد#11101#2:2در مبناي

#1D#16 :16در مبناي

#35#8 :8در مبناي

Page 35: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 3535

ه هاي بيتيه هاي بيتيكاراكترها رشته ها و رشتكاراكترها رشته ها و رشت

( كاراكترها )داخل يك جفت گيومه تكي'a' 'B' ',‘

رشته ) داخل يك جفت گيومه دوتايي( "This is a string“

حتی خود هر كاراكتر قابل چاپ مجاز است(" )

"This is a ""String""."

Page 36: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 3636

رشته بيتي رشته بيتي

يك رشته بيتي يك توالي از بيتها است بمنظور تمایز از رشتة كاراكتري در ابتداي آنB

می گذارند B”1001”

هم نوشته مي شود8 يا 16رشته بيتي در مبناي Binary: B”1100_1001”, b”1001011”Hexagonal: X”C9”, X”4b”Octal: O”311”, o”113”

توجه كنيد دو مقدار با طول نامساوی نامساویندb”1001011” ≠ X”4b” O”113” ≠ X”4b”

Page 37: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 3737

Data objectsData objects اشياء داده ایاشياء داده ای

(توصیف سیم های ارتباطی مدار) سيگنالها

ثابت ها

متغيرها

فایل

در توصیف رفتاری)پردازه ها، توابع و روالها(

)در سنتز مدار وجود خارجی ندارد(

Page 38: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 3838

((constantconstantثابت )ثابت )

با توجه به نوع مقدار میگیرد و در طول شبیه سازیمقدارش عوض نمی شود

constant list_of_name_of_constant: type [:=initial value];

ثابت در ابتدایarchitecture تعریف شده و در داخل آن استفاده می شود.

یک ثابت که در داخل یک پردازه تعریف می شود فقطدر همان پردازه نیز می تواند استفاده شود.

constant RISE_FALL_TME: time := 2 ns;

constant DELAY1: time := 4 ns;

constant RISE_TIME, FALL_TIME: time:= 1 ns;

constant DATA_BUS: integer:= 16;

Page 39: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 3939

تعریف ثابتتعریف ثابت

Process یا Architecture یا Entityدرهر يك از Declaring Constants

entity ent1 is

generic;(...)

port;(...)

constant loop_number:positive:=4;

begin

...

end entity ent1;

Page 40: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 4040

تعریف ثابتتعریف ثابتArchitecture ent1_arch of Ent1 isCONSTANT t_propagation:time:=10ns;Begin...End architecture ent1_arch;------------------------------------------Declaring Constantsp1:process (A,B)constant t_hold:time:=5ns;begin...end process p1;

Page 41: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 4141

  ((VariableVariableمتغير)متغير)

مقدارش می تواند با استفاده از جمالت انتساب تغییر کند

تغییر به محض اجرای دستور انتساب بدون تاخیر انجام می شود

مي شود داخل یک پردازه تعریف

variable list_of_variable_names: type [:= initial value];

variable CNTR_BIT: bit :=0;

variable VAR1: boolean :=FALSE;

variable SUM: integer range 0 to 256 :=16;

variable STS_BIT: bit_vector (7 downto 0);

دستور انتساب براي متغيرهاVariable_name := expression;

Page 42: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 4242

((SignalSignalسيگنال )سيگنال )signal list_of_signal_names: type [ := initial value];

signal SUM, CARRY: std_logic;

signal CLOCK: bit;

signal TRIGGER: integer :=0;

signal DATA_BUS: bit_vector (0 to 7);

signal VALUE: integer range 0 to 100;

با یک تاخیر مشخص پس از اجرای دستور انتساب به روز می شوند

SUM <= (A xor B) after 2 ns;

ميتوان با يك توالي از مقادیر، یک شکل موج دلخواه ایجاد کرد

signal wavefrm : std_logic;

wavefrm <=‘0’,‘1’ after 5ns,‘0’ after 10ns,‘1’ after 20ns;

Page 43: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 4343

تفاوت متغير و سيگنالتفاوت متغير و سيگنال

سیگنال باانتساب و ':=' انتساب متغیر با '=<'

بدون تاخیر ولی انتساب سیگنال انتساب متغیر با تاخیر)دلتا(

همروندانتساب سیگنال انتساب متغیر ترتیبی و

دو مثال بعد این موضوع را روشن می کند

Page 44: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 4444

----------------------------------------------------Example of a process using Variables----------------------------------------------------architecture VAR of EXAMPLE is signal TRIGGER, RESULT: integer := 0; begin

processvariable variable1: integer :=1;variable variable2: integer :=2;variable variable3: integer :=3;

beginwait on TRIGGER;variable1 := variable2;variable2 := variable1 + variable3;variable3 := variable2;RESULT <= variable1 + variable2 + variable3;

end process;end VAR---------------- RESULT=2+5+5=12 -------------------

Page 45: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 4545

---------------------------------------------------Example of a process using Signals---------------------------------------------------architecture SIGN of EXAMPLE is

signal TRIGGER, RESULT: integer := 0;signal signal1: integer :=1;signal signal2: integer :=2;signal signal3: integer :=3;

beginprocessbeginwait on TRIGGER;

signal1 <= signal2; --2signal2 <= signal1 + signal3; --1+3=4signal3 <= signal2; --2

RESULT <= signal1 + signal2 + signal3;end process;

end SIGN;----------------- RESULT=1+2+3=6 ------------------

Page 46: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 4646

انواع دادهانواع دادهVHDLیک زبان بشدت نوع گرا است مثال انتساب یک مقدارinteger به یک نوعbit

غیر مجاز استانواع تعریف شده

Boolean

Integer

Character

Bit

Time

Std_ulogicStd_logicArrayVectorsRecords

Page 47: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 4747

Boolean Type

Architecture rtl of ex isBegin

Process(…)Variable alpha: Boolean;

Beginalpha := a<b;If alpha then......

End process;End;

Page 48: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 4848

Integer Type

محدوده آن به تعریف بستگی دارد اکثر ابزارهایCAD بيت پشتیانی می 32 تا

کنندConstant loop_number: integer:=365;

Signal my_int: integer range 0 to 255;

Page 49: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 4949

Bit Type

به خود می گیرد1 یا 0فقط مقدار signal A: bit :=1 ;

Page 50: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 5050

Std_ulogic

یک نوع شمارشی است با مقادیر

'U' Un-initialized 'X' Forcing Unknown

'0' Forcing 0 '1' Forcing 1'Z' High Impedance 'W' Weak Unknown'L' Weak 0 'H' Weak 1'-' Don't care

Page 51: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 5151

Std_logic

همانStd_ulogic با این تفاوت که تضاد را با جدول زیر حل میکند

Page 52: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 5252

Resolved Data TypeEntity ex isPort(d,c,en1,en2:in std_logic;

dbus:out std_logic);End;Architecture rtl of ex isBegindbus<=d when en1=‘1’ else ‘Z’;dbus<=c when en2=‘1’ else ‘Z’;

End;

Page 53: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 5353

Unresolved Type

Entity ex isPort(d,c,en1,en2:in std_ulogic;

dbus:out std_ulogic);End;Architecture rtl of ex isBegindbus<=d when en1=‘1’ else ‘Z’;dbus<=c when en2=‘1’ else ‘Z’;

End;Error

Error

Page 54: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 5454

دستور انتساب سيگنال همروند سادهدستور انتساب سيگنال همروند ساده

Target_signal <= expression; انتساب موقع وقوع یک رخداد در یکی از

سیگنالها عبارت نوعtarget_signal باید با نوع عبارت یکسان

باشد

Page 55: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 5555

Example(5-1): driverExample(5-1): driver

----------------------------------------library ieee;use ieee.std_logic_1164.all;----------------------------------------entity Driver isport( x: in std_logic;

F: out std_logic );end Driver; ----------------------------------------architecture behv2 of Driver is begin F <= x; end behv2; ------------------------------------------

Page 56: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 5656

Example(5-2): InverterExample(5-2): Inverter

----------------------------------------library ieee;use ieee.std_logic_1164.all;----------------------------------------entity Inverter isport( x: in std_logic;

F: out std_logic );end Inverter ;

----------------------------------------architecture behv2 of Inverter is begin

F <= not x ;end behv2 ;

------------------------------------------

Page 57: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 5757

Example(5-3): AND gateExample(5-3): AND gate

--------------------------------------library ieee;use ieee.std_logic_1164.all;--------------------------------------entity AND_ent isport( x: in std_logic;

y: in std_logic;F: out std_logic );

end AND_ent; --------------------------------------architecture behav2 of AND_ent isbegin F <= x and y;end behav2;--------------------------------------

Page 58: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 5858

Example(5-4): OR gateExample(5-4): OR gate --------------------------------------library ieee;use ieee.std_logic_1164.all;--------------------------------------entity OR_ent isport( x: in std_logic;

y: in std_logic;F: out std_logic );

end OR_ent; ---------------------------------------architecture OR_beh of OR_ent is begin F <= x or y; end OR_beh;---------------------------------------

Page 59: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 5959

Example(5-5): NAND gateExample(5-5): NAND gate --------------------------------------library ieee;use ieee.std_logic_1164.all;--------------------------------------entity NAND_ent isport( x: in std_logic;

y: in std_logic;F: out std_logic );

end NAND_ent; --------------------------------------architecture behv2 of NAND_ent is begin

F <= x nand y; end behv2;--------------------------------------

Page 60: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 6060

Example(5-6): NOR gateExample(5-6): NOR gate

--------------------------------------library ieee;use ieee.std_logic_1164.all;--------------------------------------entity NOR_ent isport( x: in std_logic;

y: in std_logic;F: out std_logic);

end NOR_ent; --------------------------------------architecture behv2 of NOR_ent is begin F <= x nor y; end behv2;--------------------------------------

Page 61: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 6161

Example(5-7): XOR gateExample(5-7): XOR gate

--------------------------------------library ieee;use ieee.std_logic_1164.all;--------------------------------------entity XOR_ent isport( x: in std_logic;

y: in std_logic;F: out std_logic);

end XOR_ent; --------------------------------------architecture behv2 of XOR_ent is begin F <= x xor y; end behv2;--------------------------------------

Page 62: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 6262

Example(5-8): XORExample(5-8): XOR

--------------------------------------library ieee;use ieee.std_logic_1164.all;--------------------------------------entity XNOR_ent isport( x: in std_logic;

y: in std_logic;F: out std_logic);

end XNOR_ent; ---------------------------------------architecture behv2 of XNOR_ent is begin F <= x xnor y; end behv2;---------------------------------------

Page 63: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 6363

Example(5-9):Structural ModelExample(5-9):Structural Model

library ieee; -- component #1use ieee.std_logic_1164.all;---------------------------------------------------entity OR_GATE isport( X: in std_logic;

Y: in std_logic;F2:out std_logic );

end OR_GATE;---------------------------------------------------architecture behv of OR_GATE isbegin

F2 <= X or Y; -- behavior des.

end behv;

Page 64: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 6464

Example(5-9):Structural ModelExample(5-9):Structural Model

library ieee; -- component #2use ieee.std_logic_1164.all;---------------------------------------------------entity AND_GATE isport( A: in std_logic;

B: in std_logic;F1:out std_logic );

end AND_GATE;---------------------------------------------------architecture behv of AND_GATE isbeginF1 <= A and B; -- behavior des.end behv;

Page 65: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 6565

library ieee; -- top level circuituse ieee.std_logic_1164.all;use work.all;entity comb_ckt isport( input1: in std_logic;

input2: in std_logic;input3: in std_logic;output: out std_logic);

end comb_ckt;architecture struct of comb_ckt is component AND_GATE is -- as entity of

AND_GATE port(A: in std_logic; B: in std_logic; F1: out std_logic ); end component; component OR_GATE is -- as entity of OR_GATE port(X: in std_logic; Y: in std_logic; F2: out std_logic ); end component;

Page 66: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 6666

Example(5-9):Structural ModelExample(5-9):Structural Model

signal wire: std_logic; -- signal just like wire

begin

--use sign "=>" to clarify the pin mapping

Gate1: AND_GATE port map (A=>input1, B=>input2, F1=>wire);

Gate2: OR_GATE port map (X=>wire, Y=>input3, F2=>output);

end struct;

----------------------------------------------------------

Gate1: AND_GATE port map (input1, input2, wire);

Gate2: OR_GATE port map (wire, input3, output);

Page 67: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 6767

44--bit adder(Cout)bit adder(Cout)entity ADDER isport( A: in std_logic_vector(3 downto 0);

B: in std_logic_vector(3 downto 0);carry:out std_logic;sum: out std_logic_vector(3 downto 0));

end ADDER;-------------------------------------------------architecture behv of ADDER is-- define a temparary signal to store the resultsignal result: std_logic_vector(4 downto 0);begin -- the 3rd bit should be carry result <= ('0' & A)+('0' & B); sum <= result(3 downto 0); carry <= result(4);end behv;-------------------------------------------------

Page 68: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 6868

44--bit adder(Cin,Cout)bit adder(Cin,Cout)entity ADD4 is

port ( A: in STD_LOGIC_VECTOR (3 downto 0); B: in STD_LOGIC_VECTOR (3 downto 0);

CIN: in STD_LOGIC; SUM: out STD_LOGIC_VECTOR (3 downto 0);

COUT: out STD_LOGIC );end ADD4;

---------------------------------------------------architecture ADD4_concurnt of ADD4 is

-- define internal SUM signal including the carrysignal SUMINT: STD_LOGIC_VECTOR(4 downto 0);

begin SUMINT <= ('0' & A) + ('0' & B) + ("0000" & CIN);

COUT <= SUMINT(4); SUM <= SUMINT(3 downto 0);

end ADD4_concurnt--------------------------------------------------

Page 69: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 6969

شرطیشرطیانتساب سيگنال انتساب سيگنال دستور دستور

Target_signal <= expression when Boolean_condition else expression when Boolean_condition else

: expression when Boolean_condition else

expression;

مقدار اولین عبارتی که شرط آن درست است

انتساب داده می شود

وقوع یک رخداد در یکی از سیگنالهای موجود در باعث ارزشیابی مجدد شده و ها شرط یا عبارات

انتساب انجام می شود

Page 70: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 7070

4/14/1 MUXMUX----------------------------------------------------library ieee;use IEEE.std_logic_1164.all;-----------------------------------------------------entity MUX_4_1_funcTab is port (A, B, C, D: in std_logic;

SEL: in std_logic_vector (1 downto 0); Z: out std_logic);

end MUX4_1_ funcTab;-----------------------------------------------------architecture concurr_MUX41 of MUX_4_1_ funcTab is

beginZ <= A when SEL = ”00” else

B when SEL = ”01” elseC when SEL = “10” else D;

end concurr_MUX41; -----------------------------------------------------

Page 71: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 7171

4/14/1 MUXMUX-----------------------------------------------------

library ieee;use IEEE.std_logic_1164.all;

-----------------------------------------------------entity MUX_4_1_Conc is

port (S1, S0, A, B, C, D: in std_logic; Z: out std_logic);

end MUX_4_1_Conc;-----------------------------------------------------

architecture concurr_MUX41 of MUX_4_1_Conc isbegin

Z <= A when S1=’0’ and S0=’0’ elseB when S1=’0’ and S0=’1’ else

C when S1=’1’ and S0=’0’ else D;

end concurr_MUX41; -----------------------------------------------------

Page 72: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 7272

When StatementWhen Statement------------------------------------------------Entity ex is

Port (a,b,c: in std_logic; data: in std_logic_vector(1 downto 0); q: out std_logic);

End entity;------------------------------------------------Architecture rtl of ex isBegin

q <= a when data=“00” else b when data=“11” else c;

End architecture;------------------------------------------------

Page 73: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 7373

When StatementWhen Statement

DBUS <= DATA when enable = ‘1’ else ‘Z’;

DBUS <= DATA when enable =‘1’ else

(others => ‘Z’);

Page 74: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 7474

When StatementWhen Statement

می توان از سیگنال های متفاوت در شرط هااستفاده کرد

Q<= a when en=‘0’ else

b when data=“11” else

c when enable=‘1’ else

d;

Page 75: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 7575

88__bit tri_state driverbit tri_state driver ----------------------------------------------------library ieee;use ieee.std_logic_1164.all;----------------------------------------------------entity tristate_dr isport( d_in: in std_logic_vector(7 downto 0);

en: in std_logic; d_out: out std_logic_vector(7 downto 0) );

end tristate_dr;----------------------------------------------------architecture behavior of tristate_dr isbegin

d_out <= d_in when en='1' else "ZZZZZZZZ";end behavior;----------------------------------------------------

Page 76: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 7676

Page 77: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 7777

Page 78: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 7878

انتساب سيگنال انتخابيانتساب سيگنال انتخابيدستور دستور with choice_expression select

target_name <= expression when choices,target_name <= expression when choices,

:target_name <= expression when choices;target_name <= expression when others;

target يكي از مقادير expression را دريافت مي كند بر حسب ها برابر است choice با كدام يك از choice_expressionاينكه عبارت

اولينchoice حساب است که برابر باشد

Choice مثل( 4مي تواند يك عبارت يا يك بازه باشد to 9)

Choice ها نبايد همپوشاني داشته باشند

تمام حاالتchoice_expression بايد پوشش داده شود. مگر اينكه others داشته باشیم

توجه شود كهothers بايد آخرين انتخاب باشد

Page 79: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 7979

Page 80: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 8080

4/14/1 MUXMUXlibrary ieee;use IEEE.std_logic_1164.all;----------------------------------------------------entity MUX_4_1_Conc2 is port (A, B, C, D: in std_logic;

SEL: in std_logic_vector(1 downto 0); Z: out std_logic);

end MUX_4_1_Conc2;----------------------------------------------------architecture concurr_MUX41b of MUX_4_1_Conc2 is

begin with SEL select

Z <= A when “00”,B when “01”,C when “10”,D when “11”;

end concurr_MUX41b;

Page 81: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 8181

هرchoice مي تواند بصورت يك تك مقدار يا باشد choiceيك بازه يا تركيبي از چند

with inpt select

target <= value1 when “000”,

value2 when “001” | “011” | “101” ,

value3 when others;

Page 82: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 8282

Example(5-12): 2/4 DecoderExample(5-12): 2/4 Decoder entity DECODER isport( I:in std_logic_vector(1 downto 0);

O:out std_logic_vector(3 downto 0));end DECODER;-------------------------------------------------architecture when_else of DECODER isbegin -- use when..else statement O <= "0001" when I = "00" else

"0010" when I = "01" else"0100" when I = "10" else"1000" when I = "11" else"XXXX";

end when_else;--------------------------------------------------

Page 83: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 8383

پياده سازي پياده سازي

توابع منطقي توابع منطقي

بر اساس بر اساس

جدول جدول

درستي درستي

entity FullAdd_Conc is port (A, B, C: in std_logic;

sum, cout: out std_logic); end FullAdd_Conc;------------------------------------------------architecture FullAdd_Conc of FullAdd_Conc is

signal INS: std_logic_vector (2 downto 0);begin INS(2) <= A; INS(1) <= B; INS(0) <= C; with INS select

(sum, cout) <= std_logic_vector’(“00”) when “000”, std_logic_vector’(“10”) when “001”, std_logic_vector’(“10”) when “010”, std_logic_vector’(“01”) when “011”, std_logic_vector’(“10”) when “100”, std_logic_vector’(“01”) when “101”, std_logic_vector’(“01”) when “110”, std_logic_vector’(“11”) when “111”, std_logic_vector’(“11”) when others;

end FullAdd_Conc;

Page 84: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 8484

With StatementArchitecture mux2_beh of mux2 isBeginC<= a after 10ns when sel_0 =‘0’ else

b after 10ns;End mux2_beh;------------------------------------------------

Architecture mux2_beh of mux2 isBeginWith sel_0 selectC<= a after 10ns when ‘0’,

b after 10ns when others;End mux2_beh;

Page 85: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 8585

مدلسازی رفتاری : دستورات ترتيبیمدلسازی رفتاری : دستورات ترتيبی

مدل سازی جریان داده: جمالت همروند(data flow) الگوریتمیمدل سازی : جمالت ترتیبی( پردازهprocess)

امکان استفاده از جمالت ترتیبی(یک ساختار(امکان مدلسازی سیستم های پیچیده داخلarchitecture یک دستور همروند محسوب می شودمعادل بصورت ترتیبی اجرا می شوندآن جمالت داخل اصوال برای توصیف مدارات ترتیبی گرچه می توان برای

مدارات ترکیبی نیز استفاده نمود

Page 86: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 8686

قالب کلی دستور پردازه قالب کلی دستور پردازه

[process_label:] process [ (sensitivity_list) ] [is][ process_declarations]

beginlist of sequential statements such as:

signal assignmentsvariable assignmentscase statementexit statementif statementloop statementnext statementnull statementprocedure call wait statement

end process [process_label];

Page 87: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 8787

DDفلیپ فالپ فلیپ فالپ توصیفتوصیف ::مثال مثال ------------------------------------------------entity DFF_CLEAR is

port (CLK, CLEAR, D : in std_logic;Q : out std_logic);

end DFF_CLEAR;------------------------------------------------architecture BEHAV_DFF of DFF_CLEAR isbeginDFF_PROCESS: process (CLK, CLEAR)

beginif (CLEAR = ‘1’) then

Q <= ‘0’;elsif (CLK’event and CLK = ‘1’) then

Q <= D;end if;

end process;end BEHAV_DFF;------------------------------------------------

Page 88: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 8888

مثال: تمام جمع کننده با استفاده از دو عدد نیم جمع کنندهمثال: تمام جمع کننده با استفاده از دو عدد نیم جمع کننده

S_ha = (A B) C_ha = AB

Sum = (A B) Cin = S_ha CinCout = (A B)Cin + AB = S_ha.Cin + C_ha

Page 89: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 8989

-----------------------------------------

library ieee;

use ieee.std_logic_1164.all;

-----------------------------------------

entity FULL_ADDER is

port (A, B, Cin : in std_logic;

Sum, Cout : out std_logic);

end FULL_ADDER;

-----------------------------------------

Page 90: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 9090

---------------------------------------------------architecture BEHAV_FA of FULL_ADDER issignal int1, int2, int3: std_logic;begin-- Process P1 (defines the first half adder)P1: process (A, B)

beginint1<= A xor B;int2<= A and B;

end process;-- Process P2 (the second half adder & the OR gate)P2: process (int1, int2, Cin)

beginSum <= int1 xor Cin;int3 <= int1 and Cin;Cout <= int2 or int3;

end process;end BEHAV_FA;---------------------------------------------------

Page 91: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 9191

IFIFدستوردستور

دستورIF ترتيب اجراي دستورات ترتیبی را بر اساس شرط معین می کند

if condition then

sequential statements

[elsif condition then

sequential statements ]

[else

sequential statements ]

end if;

می تواند به تعداد بیشتری تکرار شودelsifجمله دستور مربوطه به اولین شرط درست اجرا می شود

را بصورت النه اي )تودرتو( نیز می توان نوشت. IFدستور

Page 92: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 9292

entity MUX_4_1a is port (S1, S0, A, B, C, D: in std_logic;

Z: out std_logic); end MUX_4_1a;------------------------------------------------architecture behav_MUX41a of MUX_4_1a isbeginP1: process (S1, S0, A, B, C, D)begin

if (( not S1 and not S0 )= ’1’) thenZ <= A;

elsif (( not S1 and S0) = ‘1’) thenZ <= B;

elsif ((S1 and not S0) = ’1’) thenZ <= C;

elseZ <= D;

end if;end process P1;end behav_MUX41a;

Page 93: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 9393

entity MUX_4_1a is port (S1, S0, A, B, C, D: in std_logic;

Z: out std_logic); end MUX_4_1a;------------------------------------------------architecture behav_MUX41a of MUX_4_1a isbeginP1: process (S1, S0, A, B, C, D)begin

if S1=’0’ and S0=’0’ thenZ <= A;

elsif S1=’0’ and S0=’1’ thenZ <= B;

elsif S1=’1’ and S0=’0’ thenZ <= C;

elsif S1=’1’ and S0=’1’ thenZ <= D;

end if;end process P1;end behav_MUX41a;

Page 94: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 9494

انواع عملگرهاانواع عملگرها

اولویت از پایین به باال و از راست به چپمگر اینکه از پرانتز استفاده شود

Page 95: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 9595

Example(5-1): driverExample(5-1): driver ----------------------------------------entity Driver isport( x: in std_logic;

F: out std_logic );end Driver; ----------------------------------------

architecture behv1 of Driver isbegin

process(x) begin

-- compare to truth table if (x='1') then

F <= '1'; else

F <= '0'; end if;

end process;end behv1;

------------------------------------------

F <= x ;

Page 96: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 9696

Example(5-2): InverterExample(5-2): Inverter ----------------------------------------entity Inverter isport( x: in std_logic;

F: out std_logic );end Inverter ;

----------------------------------------architecture behv1 of Inverter is

begin process(x)

begin -- compare to truth table

if (x='1') then F <= '0';

else F <= '1';

end if; end process;

end behv1;------------------------------------------ F <= not x ;

Page 97: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 9797

Example(5-3): AND gateExample(5-3): AND gate --------------------------------------entity AND_ent isport( x: in std_logic;

y: in std_logic;F: out std_logic );

end AND_ent; --------------------------------------architecture behav1 of AND_ent isbegin process(x, y) begin -- compare to truth table if ((x='1') and (y='1')) then

F <= '1';else

F <= '0';end if;

end process;end behav1;;--------------------------------------

F <= x and y ;

Page 98: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 9898

Example(5-4): OR gateExample(5-4): OR gate --------------------------------------entity OR_ent isport( x: in std_logic;

y: in std_logic;F: out std_logic );

end OR_ent; ---------------------------------------architecture OR_arch of OR_ent isbegin process(x, y) begin -- compare to truth table if ((x='0') and (y='0')) then

F <= '0';else

F <= '1';end if;

end process;end OR_arch;---------------------------------------

F <= x or y ;

Page 99: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 9999

Example(5-5): NAND gateExample(5-5): NAND gate --------------------------------------entity NAND_ent isport( x: in std_logic;

y: in std_logic;F: out std_logic );

end NAND_ent; --------------------------------------architecture behv1 of NAND_ent isbegin process(x, y) begin -- compare to truth table if (x='1' and y='1') then

F <= '0';else

F <= '1';end if;

end process;end behv1;--------------------------------------

F <= x nand y ;

Page 100: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 100100

Example(5-6): NOR gateExample(5-6): NOR gate --------------------------------------entity NOR_ent isport( x: in std_logic;

y: in std_logic;F: out std_logic);

end NOR_ent; --------------------------------------architecture behv1 of NOR_ent isbegin process(x, y) begin -- compare to truth table

if (x='0' and y='0') then F <= '1';

else F <= '0';

end if; end process;end behv1;--------------------------------------

F <= x nor y ;

Page 101: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 101101

Example(5-7): XOR gateExample(5-7): XOR gate --------------------------------------entity XOR_ent isport( x: in std_logic;

y: in std_logic;F: out std_logic);

end XOR_ent; --------------------------------------architecture behv1 of XOR_ent isbegin process(x, y) begin -- compare to truth table

if (x/=y) then F <= '1';else

F <= '0';end if;

end process;end behv1;--------------------------------------

F <= x xor y ;

Page 102: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 102102

Example(5-8): XORExample(5-8): XOR --------------------------------------entity XNOR_ent isport( x: in std_logic;

y: in std_logic;F: out std_logic);

end XNOR_ent; ---------------------------------------architecture behv1 of XNOR_ent isbegin process(x, y) begin -- compare to truth table if (x/=y) then

F <= '0';else

F <= '1';end if;

end process;end behv1;---------------------------------------

F <= x xnor y ;

Page 103: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 103103

   CaseCaseدستور دستور

case expression is

when choices =>

sequential statements

when choices =>

sequential statements

-- branches are allowed

[when others => sequential statements ]

end case;

(دو انتخابchoice ).نباید با هم همپوشانی داشته باشند اگر“when others” ذکر نمی شود تمام مقادیر ممکن

برای عبارت باید بوسیله مجموعه انتخابها پوشش داده شود.

Page 104: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 104104

11 به به 44مثال : مالتی پلکسر مثال : مالتی پلکسر -------------------------------------------------------

entity MUX_4_1 is port ( SEL: in std_logic_vector(2 downto 1);

A, B, C, D: in std_logic;Z: out std_logic);

end MUX_4_1;architecture behav_MUX41 of MUX_4_1 is

-------------------------------------------------------begin

PR_MUX: process (SEL, A, B, C, D) begin

case SEL iswhen “00” => Z <= A;

when “01” => Z <= B; when “10” => Z <= C;

when “11” => Z <= D;when others => Z <= ‘X’;

end case; end process PR_MUX;

end behav_MUX41;-------------------------------------------------------

Page 105: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 105105

سه بیتی سه بیتی11 به به 44( مالتی پلکسر ( مالتی پلکسر 1111--55مثال مثال entity Mux isport( I3: in std_logic_vector(2 downto 0);

I2: in std_logic_vector(2 downto 0);I1: in std_logic_vector(2 downto 0);I0: in std_logic_vector(2 downto 0);S: in std_logic_vector(1 downto 0);O: out std_logic_vector(2 downto 0));

end Mux; -------------------------------------------------architecture behv1 of Mux isbegin process(I3,I2,I1,I0,S) begin -- use case statement case S is

when "00" => O <= I0; when "01" => O <= I1; when "10" => O <= I2; when "11" => O <= I3; when others => O <= "ZZZ";

end case; end process;end behv1;

Page 106: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 106106

سه بیتی سه بیتی11 به به 44( مالتی پلکسر ( مالتی پلکسر 1111--55مثال مثال entity Mux isport( I3: in std_logic_vector(2 downto 0);

I2: in std_logic_vector(2 downto 0);I1: in std_logic_vector(2 downto 0);I0: in std_logic_vector(2 downto 0);S: in std_logic_vector(1 downto 0);O: out std_logic_vector(2 downto 0));

end Mux; -------------------------------------------------architecture behv2 of Mux isbegin -- use when.. else statement O <=I0 when S="00" else

I1 when S="01" elseI2 when S="10" elseI3 when S="11" else"ZZZ";

end behv2;--------------------------------------------------

Page 107: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 107107

------------------------------------------------- 44 به به 22( دیکودر ( دیکودر 1212--55مثال مثال entity DECODER isport( I: in std_logic_vector(1 downto 0);

O: out std_logic_vector(3 downto 0));end DECODER;-------------------------------------------------architecture behv of DECODER isbegin -- process statement process (I) begin -- use case statement

case I is when "00" => O <= "0001"; when "01" => O <= "0010"; when "10" => O <= "0100"; when "11" => O <= "1000"; when others => O <= "XXXX";

end case; end process;end behv;-------------------------------------------------

Page 108: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 108108

44 به به 22( دیکودر ( دیکودر 1212--55مثال مثال -------------------------------------------------entity DECODER isport( I: in std_logic_vector(1 downto 0);

O: out std_logic_vector(3 downto 0));end DECODER;-------------------------------------------------architecture when_else of DECODER isbegin -- use when..else statement O <= "0001" when I = "00" else

"0010" when I = "01" else"0100" when I = "10" else"1000" when I = "11" else"XXXX";

end when_else;-------------------------------------------------

Page 109: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 109109

بیتی بیتیnn( مقايسه کننده ( مقايسه کننده 1414--55مثال مثال ----------------------------------------------------- Example(5-14): n-bit Comparator -- two n-bit inputs & three 1-bit outputs---------------------------------------------------library ieee;use ieee.std_logic_1164.all;---------------------------------------------------entity Comparator isgeneric(n: natural :=2);port( A:in std_logic_vector(n-1 downto 0);

B:in std_logic_vector(n-1 downto 0);less:out std_logic;equal:out std_logic;greater:out std_logic);

end Comparator;

Page 110: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 110110

بیتی بیتیnn( مقايسه کننده ( مقايسه کننده 1414--55مثال مثال ---------------------------------------------------architecture behv of Comparator isbegin process(A,B) begin if (A<B) then

less <= '1'; equal <= '0'; greater <= '0';

elsif (A=B) then less <= '0'; equal <= '1'; greater <= '0';

else less <= '0'; equal <= '0'; greater <= '1';

end if; end process;

end behv;---------------------------------------------------

Page 111: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 111111

ی ساده ی ساده ALUALU( یک ( یک 1515--55مثال مثال

---------------------------------------------------library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;---------------------------------------------------entity ALU isport( A: in std_logic_vector(1 downto 0);

B: in std_logic_vector(1 downto 0);Sel: in std_logic_vector(1 downto 0);Res: out std_logic_vector(1 downto 0));

end ALU;

Page 112: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 112112

ی ساده ی ساده ALUALU( یک ( یک 1515--55مثال مثال ---------------------------------------------------architecture behv of ALU isbegin process(A,B,Sel) begin

-- use case statement to achieve -- different operations of ALU

case Sel is when "00" =>

Res <= A + B; when "01" =>

Res <= A + (not B) + 1; when "10" =>

Res <= A and B; when "11" =>

Res <= A or B; when others =>

Res <= "XX"; end case; end process;end behv;----------------------------------------------------

Page 113: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 113113

و ماشين حالت و ماشين حالتطراحی مدارات ترتیبیطراحی مدارات ترتیبی

:مدارات ترتيبي شاملسیگنالهای وروديسیگنالهای خروجی سیگنال کالک مانند( احیانا یکسری سیگنالهای کنترولی دیگرreset )

سيگنالهاي کنترلی می توانند فعال صفر یا یک باشند

انتقال از یک وضعیت به وضعیت دیگر لبه سیگنال کالک

)clock'event and clock='1 (' )clock'event and clock=‘0 ('

Page 114: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 114114

DD( نگهدار ( نگهدار 1717--55مثال مثال --------------------------------------------entity D_latch isport( data_in: in std_logic;

enable: in std_logic;data_out: out std_logic );

end D_latch;--------------------------------------------architecture behv of D_latch isbegin --compare this to D flipflop process(data_in, enable) begin

if (enable='1') then --no clock signal here

data_out <= data_in; end if;

end process;end behv;--------------------------------------------

Page 115: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 115115

DD( فلیپ فالپ ( فلیپ فالپ 1818--55مثال مثال ---------------------------------------------entity dff isport( data_in: in std_logic;

clock:in std_logic;data_out: out std_logic);

end dff;----------------------------------------------architecture behv of dff isbegin process(data_in, clock) begin -- clock rising edge

if (clock='1' and clock'event) then data_out <= data_in;

end if; end process;end behv;----------------------------------------------

Page 116: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 116116

( ( 1919--55مثال مثال

JKJKيك يك

فلیپ فالپفلیپ فالپ

----------------------------------------------entity JK_FF isport (clock, J, K, reset: in std_logic;

Q, Qbar: out std_logic);end JK_FF;-----------------------------------------------architecture behv of JK_FF is -- define the useful signals here signal state: std_logic; signal input: std_logic_vector(1 downto 0);begin -- combine inputs into vector input <= J & K; p: process(clock, reset) is begin

if (reset='1') then state <= '0';

elsif (clock='1' and clock'event) then -- compare to the truth table

case (input) is when "11" => state <= not state;

when "10" => state <= '1';

when "01" => state <= '0';

when others => null; end case;end if;

end process; -- concurrent statements Q <= state; Qbar <= not state;end behv;-------------------------------------------------

Page 117: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 117117

((2020--55مثال مثال

بیتیبیتیnn ثبات ثبات

---------------------------------------------------entity reg isgeneric(n: natural :=2);port( I: in std_logic_vector(n-1 downto 0);

clock: in std_logic;load: in std_logic;clear: in std_logic;Q: out std_logic_vector(n-1 downto 0) );

end reg;----------------------------------------------------architecture behv of reg is signal Q_tmp: std_logic_vector(n-1 downto 0);begin process(I, clock, load, clear) begin

if clear = '0' then -- use 'range in signal assigment Q_tmp <= (Q_tmp'range => '0');

elsif (clock='1' and clock'event) then if load = '1' then

Q_tmp <= I; end if;

end if; end process; -- concurrent statement Q <= Q_tmp;end behv;---------------------------------------------------

Page 118: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 118118

((2121--55مثال مثال

ثبات ثبات

انتقالیانتقالی

---------------------------------------------------entity shift_reg isport( I: in std_logic;

clock: in std_logic;shift: in std_logic;Q: out std_logic );

end shift_reg;---------------------------------------------------architecture behv of shift_reg is -- initialize the declared signal signal S: std_logic_vector(2 downto 0):="111";begin process(I, clock, shift, S) begin

-- everything happens upon the clock changingif clock'event and clock='1' then

if shift = '1' thenS <= I & S(2 downto 1);

end if;end if;

end process; -- concurrent assignment Q <= S(0);end behv;----------------------------------------------------

Page 119: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 119119

((2222--55مثال مثال

بيتيبيتي nn شمارنده شمارنده

----------------------------------------------------entity counter isgeneric(n: natural :=2);port( clock: in std_logic;

clear: in std_logic;count: in std_logic;Q: out std_logic_vector(n-1 downto 0));

end counter;----------------------------------------------------architecture behv of counter is signal Pre_Q: std_logic_vector(n-1 downto 0);begin -- behavior describe the counter process(clock, count, clear) begin

if clear = '1' then Pre_Q <= Pre_Q - Pre_Q;

elsif (clock='1' and clock'event) then if count = '1' then

Pre_Q <= Pre_Q + 1; end if; end if;

end process; -- concurrent assignment statement Q <= Pre_Q;end behv;-----------------------------------------------------

Page 120: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 120120

( ماشین حالت مور( ماشین حالت مور2323--55مثال مثال مقدار خروجی آن فقط وابسته به حالت فعلي است

دهیچ ورودی دخالت مستقیم در عبارت بولی خروجی ها ندار

Page 121: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 121121

( ماشین حالت مور( ماشین حالت مور2323--55مثال مثال

----------------------------------------------------------entity MOORE is -- Moore machine port(X, CLOCK: in BIT; Z: out BIT);end MOORE;----------------------------------------------------------architecture BEHAVIOR of MOORE is type STATE_TYPE is (S0, S1, S2, S3); signal CURRENT_STATE, NEXT_STATE: STATE_TYPE;begin------------------------------------------------------------ Process to hold combinational logicCOMBIN: process(CURRENT_STATE, X)begin case CURRENT_STATE is when S0 => Z <= '0'; if X = '0' then NEXT_STATE <= S0; else NEXT_STATE <= S2; end if; when S1 => Z <= '1'; if X = '0' then NEXT_STATE <= S0; else NEXT_STATE <= S2; end if;

Page 122: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 122122

<= when S2 ( ماشین حالت مور( ماشین حالت مور2323--55مثال مثال Z <= '1'; if X = '0' then NEXT_STATE <= S2; else NEXT_STATE <= S3; end if; when S3 => Z <= '0'; if X ='0' then NEXT_STATE <= S3; else NEXT_STATE <= S1; end if; end case;end process COMBIN;

------------------------------------------------------------ Process to hold synchronous elements (flip-flops)SYNCH: processbegin wait until CLOCK'event and CLOCK = '1'; CURRENT_STATE <= NEXT_STATE;end process SYNCH;end BEHAVIOR; ----------------------------------------------------------

Page 123: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 123123

((2424--55مثال مثال

ماشین مور ماشین مور

با ورودی ریستبا ورودی ریست

----------------------------------------------------------entity seq_design isport( a: in std_logic;

clock: in std_logic;reset: in std_logic;x: out std_logic );

end seq_design;----------------------------------------------------------architecture FSM of seq_design is -- define the states of FSM model type state_type is (S0, S1, S2, S3); signal next_state, current_state: state_type;begin---------------------------------------------------------- -- concurrent process#1: state registers state_reg: process(clock, reset) begin

if (reset='1') then current_state <= S0;

elsif (clock'event and clock='1') then current_state <= next_state;

end if; end process;

Page 124: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 124124

((2424--55مثال مثال

ماشین مور ماشین مور

با ورودی ریستبا ورودی ریست

-- concurrent process#2: combinational logic comb_logic: process(current_state, a) begin

-- use case statement to show the -- state transistioncase current_state is when S0 =>

x <= '0';if a='0' then

next_state <= S0;elsif a ='1' then next_state <= S1;end if;

when S1 =>x <= '0';

if a='0' then next_state <= S1;elsif a='1' then next_state <= S2;end if;

Page 125: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 125125

((2424--55مثال مثال

ماشین مور ماشین مور

با ورودی ریستبا ورودی ریست

when S2 =>x <= '0';if a='0' then next_state <= S2;elsif a='1' then next_state <= S3;end if;

when S3 =>x <= '1';if a='0' then next_state <= S3;elsif a='1' then next_state <= S0;end if;

when others =>x <= '0';next_state <= S0;

end case; end process;end FSM;----------------------------------------------------------

-

Page 126: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 126126

( آشکارساز توالی بیت )ماشين ( آشکارساز توالی بیت )ماشين 2525--55مثال مثال

مور(مور( توصیف رفتاری یک ماشین حالت از نوع مور 1110101101“هدف: تشخیص رشته ی بیتی”

است هر آشکار ساز توالیn بيتی به روش مور n+1

حالت مورد نیاز دارد حالت درنظر می گیریم 11 بیت داریم 10چون

Page 127: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 127127

((2525--55مثال مثال

آشکارساز توالی بیتآشکارساز توالی بیت

----------------------------------------------------------ENTITY seqdetector ISPORT (clk, reset :IN STD_LOGIC;

input :IN STD_LOGIC; output :OUT STD_LOGIC );

END seqdetector ;----------------------------------------------------------ARCHITECTURE stat OF seqdetector ISTYPE STATE_TYPE IS (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10);SIGNAL state, next_state : STATE_TYPE;BEGIN----------------------------------------------------------state_register: PROCESS (clk, reset)BEGIN

IF reset = '0' THENstate <= s0;output<='0';

ELSIF clk'EVENT AND clk = '1' THENstate <= next_state;

END IF;END PROCESS state_register;----------------------------------------------------------

Page 128: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 128128

((2525--55مثال مثال

آشکارساز توالی بیتآشکارساز توالی بیت

state_logic : PROCESS ( state )BEGINCASE state ISWHEN s0 => --detect "1"output<='0';IF (input='1') THENnext_state <=s1;ELSIF (input='0') THENnext_state <=s0;END IF;WHEN s1 => --detect "11"output<='0';IF (input='1') THENnext_state <=s2;ELSIF (input='0') THENnext_state <=s0;END IF;WHEN s2 => --detect "111"output<='0';IF (input='1') THENnext_state <=s3;ELSIF (input='0') THENnext_state <=s0;END IF;

Page 129: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 129129

((2525--55مثال مثال

آشکارساز توالی بیتآشکارساز توالی بیت

WHEN s3 => --detect "1110"output<='0';

IF (input='0') THENnext_state <=s4;ELSIF (input='1') THENnext_state <=s2;END IF;

WHEN s4 => --detect "11101"output<='0';IF (input='1') THENnext_state <=s5;ELSIF (input='0') THENnext_state <=s0;END IF;

WHEN s5 => --detect "111010" output<='0';IF (input='0') THENnext_state <=s6;ELSIF (input='1') THENnext_state <=s2;END IF;

Page 130: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 130130

((2525--55مثال مثال

آشکارساز توالی بیتآشکارساز توالی بیت

WHEN s6 => --detect "1110101"output<='0';IF (input='1') THENnext_state <=s7;ELSIF (input='0') THENnext_state <=s0;END IF;WHEN s7 => --detect "11101011"output<='0';IF (input='1') THENnext_state <=s8;ELSIF (input='0') THENnext_state <=s0;END IF;WHEN s8 => --detect "111010110" output<='0';IF (input='0') THENnext_state <=s9;ELSIF (input='1') THENnext_state <=s2;END IF;

Page 131: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 131131

((2525--55مثال مثال

آشکارساز توالی بیتآشکارساز توالی بیتWHEN s9 => --detect "1110101101"

output<='0';IF (input='1') THENnext_state <=s10;ELSIF (input='1') THENnext_state <=s0;END IF;

WHEN s10 => -- output assertedoutput<='1';next_state<=s0;

END CASE;END PROCESS state_logic;

END stat;

Page 132: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 132132

( ماشین ميلي( ماشین ميلي2626--55مثال مثال مقدار خروجی آن وابسته به حالت فعلي و خروجی

است

Page 133: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 133133

( ماشین ميلي( ماشین ميلي2626--55مثال مثال

----------------------------------------------------------entity MEALY is -- Mealy machine port(X, CLOCK: in BIT; Z: out BIT);end MEALY;----------------------------------------------------------architecture BEHAVIOR of MEALY is type STATE_TYPE is (S0, S1, S2, S3); signal CURRENT_STATE, NEXT_STATE: STATE_TYPE;begin------------------------------------------------------------ Process to hold combinational logic. COMBIN: process(CURRENT_STATE, X) begin case CURRENT_STATE is when S0 => if X = '0' then Z <= '0'; NEXT_STATE <= S0; else Z <= '1'; NEXT_STATE <= S2; end if; when S1 =>

if X = '0' then Z <= '0'; NEXT_STATE <= S0; else Z <= '0'; NEXT_STATE <= S2; end if;

Page 134: Hsabaghianb @ kashanu.ac.ir طراحی خودکار 4- 1 زبان توصيف سخت افزار VHDL ترم بهاره 85-84 دانشگاه کاشان Lec note 4 فصل چهارم

hsabaghianb @ kashanu.ac.ir hsabaghianb @ kashanu.ac.ir طراحی خودکار طراحی خودکار 44 - - 134134

( ماشین ميلي( ماشین ميلي2626--55مثال مثال

when S2 => if X = '0' then Z <= '1'; NEXT_STATE <= S2; else Z <= '0'; NEXT_STATE <= S3; end if; when S3 => if X = '0' then Z <= '0'; NEXT_STATE <= S3; else Z <= '1'; NEXT_STATE <= S1; end if;end case;end process COMBIN;------------------------------------------------------------ Process to hold synchronous elements (flip-flops)SYNCH: processbegin wait until CLOCK'event and CLOCK = '1'; CURRENT_STATE <= NEXT_STATE;end process SYNCH;end BEHAVIOR;----------------------------------------------------------