vhdl语言例程集锦.doc

上传人:sccc 文档编号:4596987 上传时间:2023-04-29 格式:DOC 页数:69 大小:577.50KB
返回 下载 相关 举报
vhdl语言例程集锦.doc_第1页
第1页 / 共69页
vhdl语言例程集锦.doc_第2页
第2页 / 共69页
vhdl语言例程集锦.doc_第3页
第3页 / 共69页
vhdl语言例程集锦.doc_第4页
第4页 / 共69页
vhdl语言例程集锦.doc_第5页
第5页 / 共69页
点击查看更多>>
资源描述

《vhdl语言例程集锦.doc》由会员分享,可在线阅读,更多相关《vhdl语言例程集锦.doc(69页珍藏版)》请在三一办公上搜索。

1、vhdl语言例程集锦Examples of VHDL Descriptions Advanced Electronic Design Automation Examples of VHDL Descriptions Author: Ian Elliott of Northumbria University This file contains a selection of VHDL source files which serve to illustrate the diversity and power of the language when used to describe variou

2、s types of hardware. The examples range from simple combinational logic, described in terms of basic logic gates, to more complex systems, such as a behavioural model of a microprocessor and associated memory. All of the examples can be simulated using any IEEE compliant VHDL simulator and many can

3、be synthesised using current synthesis tools. Use the hierarchical links below to navigate your way through the examples: l Combinational Logic l Counters l Shift Registers l Memory l State Machines l Registers l Systems l ADC and DAC l Arithmetic Combinational Logic l Exclusive-OR Gate (Dataflow st

4、yle) l Exclusive-OR Gate (Behavioural style) l Exclusive-OR Gate (Structural style) l Miscell aneous Logic Gates l Three-input Majority Voter l Magnitude Comparator l Quad 2-input Nand (74x00) l BCD to Seven Segment Decoder l Dual 2-to-4 Decoder l Octal Bus Transceiver l Quad 2-input OR l 8-bit Iden

5、tity Comparator l Hamming Encoder l Hamming Decoder l 2-to-4 Decoder with Testbench and Configuration l Multiplexer 16-to-4 using Selected Signal Assignment Statement l Multiplexer 16-to-4 using Conditional Signal Assignment Statement l Multiplexer 16-to-4 using if-then-elsif-else Statement l M68008

6、 Address Decoder l Highest Priority Encoder l N-input AND Gate Counters h t t p : / / w w w . a m i . b o l t o n . a c . u k / c o u r s e w a r e / a d v e d a / v h d l / v h d l e x m p . h t m l ( 1 o f 6 7 ) 2 3 / 1 / 2 0 0 2 4 : 1 5 : 0 1 Examples of VHDL Descriptions l Counter using a Conver

7、sion Function l Generated Binary Up Counter l Counter using Multiple Wait Statements l Synchronous Down Counter with Parallel Load l Mod-16 Counter using JK Flip-flops l Pseudo Random Bit Sequence Generator l Universal Counter/Register l n-Bit Synchronous Counter Shift Registers l Universal Shift Re

8、gister/Counter l TTL164 Shift Register l Behavioural description of an 8-bit Shift Register l Structural Description of an 8-bit Shift Register Memory l ROM-based Waveform Generator l A First-in First-out Memory l Behavioural model of a 16-word, 8-bit Random Access Memory l Behavioural model of a 25

9、6-word, 8-bit Read Only Memory State Machines l Classic 2-Process State Machine and Test Bench l State Machine using Variable l State Machine with Asynchronous Reset l Pattern Detector FSM with Test Bench l State Machine with Moore and Mealy outputs l Moore State Machine with Explicit State encoding

10、 l Mealy State Machine with Registered Outputs l Moore State Machine with Concurrent Output Logic Systems l Pelican Crossing Controller l Simple Microprocessor System l Booth Multiplier l Lottery Number Generator l Digital Delay Unit l Chess Clock ADC and DAC l Package defining a Basic Analogue type

11、 l 16-bit Analogue to Digital Converter l 16-bit Digital to Analogue Converter l 8-bit Analogue to Digital Converter l 8-bit Unipolar Successive Approximation ADC h t t p : / / w w w . a m i . b o l t o n . a c . u k / c o u r s e w a r e / a d v e d a / v h d l / v h d l e x m p . h t m l ( 2 o f 6

12、 7 ) 2 3 / 1 / 2 0 0 2 4 : 1 5 : 0 7 Examples of VHDL Descriptions Arithmetic l 8-bit Unsigned Multiplier l n-bit Adder using the Generate Statement l A Variety of Adder Styles l Booth Multiplier Registers l Universal Register l Octal D-Type Register with 3-State Outputs l Quad D-Type Flip-flop l 8-

13、bit Register with Synchronous Load and Clear Universal Register Description - This design is a universal register which can be used as a straightforward storage register, a bi-directional shift register, an up counter and a down counter. The register can be loaded from a set of parallel data inputs

14、and the mode is controlled by a 3-bit input. The termcnt (terminal count) output goes high when the register contains zero. LIBRARY ieee; USE ieee.Std_logic_1164.ALL; USE ieee.Std_logic_unsigned.ALL; ENTITY unicntr IS GENERIC(n : Positive := 8); -size of counter/shifter PORT(clock, serinl, serinr :

15、IN Std_logic; -serial inputs mode : IN Std_logic_vector(2 DOWNTO 0); -mode control datain : IN Std_logic_vector(n-1) DOWNTO 0); -parallel inputs dataout : OUT Std_logic_vector(n-1) DOWNTO 0); -parallel outputs termcnt : OUT Std_logic); -terminal count output END unicntr; ARCHITECTURE v1 OF unicntr I

16、S SIGNAL int_reg : Std_logic_vector(n-1) DOWNTO 0); BEGIN main_proc : PROCESS BEGIN WAIT UNTIL rising_edge(clock); CASE mode IS -reset WHEN 000 = int_reg 0); -parallel load WHEN 001 = int_reg int_reg int_reg int_reg int_reg NULL; END CASE; END PROCESS; det_zero : PROCESS(int_reg) -detects when count

17、 is 0 BEGIN termcnt = 1; FOR i IN int_regRange LOOP h t t p : / / w w w . a m i . b o l t o n . a c . u k / c o u r s e w a r e / a d v e d a / v h d l / v h d l e x m p . h t m l ( 3 o f 6 7 ) 2 3 / 1 / 2 0 0 2 4 : 1 5 : 0 8 Examples of VHDL Descriptions IF int_reg(i) = 1 THEN termcnt = 0; EXIT; EN

18、D IF; END LOOP; END PROCESS; -connect internal register to dataout port dataout = int_reg; END v1; Octal D-Type Register with 3-State Outputs Simple model of an Octal D-type register with three-state outputs using two concurrent statements. LIBRARY ieee; USE ieee.std_logic_1164.ALL; ENTITY ttl374 IS

19、 PORT(clock, oebar : IN std_logic; data : IN std_logic_vector(7 DOWNTO 0); qout : OUT std_logic_vector(7 DOWNTO 0); END ENTITY ttl374; ARCHITECTURE using_1164 OF ttl374 IS -internal flip-flop outputs SIGNAL qint : std_logic_vector(7 DOWNTO 0); BEGIN qint = data WHEN rising_edge(clock); -d-type flip

20、flops qout = qint WHEN oebar = 0 ELSE ZZZZZZZZ; -three-state buffers END ARCHITECTURE using_1164; Exclusive-OR Gate (Dataflow style) - 2 input exclusive or - Modeled at the RTL level. entity x_or is port ( in1 : in bit ; in2 : in bit ; out1 : out bit); end x_or; architecture rtl of x_or is begin out

21、1 = in1 xor in2 after 10 ns; end rtl; Exclusive-OR Gate (Behavioural style) - Exclusive or gate - modeled at the behavioral level. entity x_or is port ( in1 : in bit ; in2 : in bit ; out1 : out bit) ; end x_or; architecture behavior of x_or is h t t p : / / w w w . a m i . b o l t o n . a c . u k /

22、c o u r s e w a r e / a d v e d a / v h d l / v h d l e x m p . h t m l ( 4 o f 6 7 ) 2 3 / 1 / 2 0 0 2 4 : 1 5 : 0 8 Examples of VHDL Descriptions begin process(in1, in2) begin if in1 = in2 then out1 = 0 after 10 ns; else out1 = 1 after 10 ns; end if; end process; end behavior; Exclusive-OR Gate (S

23、tructural style) - 2 input exclusive-or gate. - Modeled at the structural level. entity x_or is port ( in1 : in bit ; in2 : in bit ; out1 : out bit) ; end x_or; entity and_gate is port ( a : in bit ; b : in bit ; c : out bit) ; end and_gate; architecture behavior of and_gate is begin process(a,b) be

24、gin c = a and b after 5 ns; end process; end behavior; entity or_gate is port ( d : in bit ; e : in bit ; f : out bit) ; end or_gate; architecture behavior of or_gate is begin process(d,e) begin f = d or e after 4 ns; end process; end behavior; entity inverter is port ( g : in bit ; h : out bit) ; e

25、nd inverter; architecture behavior of inverter is begin process(g) begin h t1, b = in2, c = t3); u1: and_gate port map ( a = in1, b = t2, c = t4); u2: inverter port map ( g = in1, h = t1); u3: inverter port map ( g = in2, h = t2); u4: or_gate port map ( d = t3, e = t4, f = out1); end structural; Thr

26、ee-input Majority Voter The entity declaration is followed by three alternative architectures which achieve the same functionality in different ways. ENTITY maj IS PORT(a,b,c : IN BIT; m : OUT BIT); END maj; -Dataflow style architecture ARCHITECTURE concurrent OF maj IS BEGIN -selected signal assign

27、ment statement (concurrent) WITH a&b&c SELECT m = 1 WHEN 110|101|011|111,0 WHEN OTHERS; END concurrent; -Structural style architecture ARCHITECTURE structure OF maj IS -declare components used in architecture COMPONENT and2 PORT(in1, in2 : IN BIT; out1 : OUT BIT); END COMPONENT; COMPONENT or3 PORT(i

28、n1, in2, in3 : IN BIT; out1 : OUT BIT); END COMPONENT; -declare local signals SIGNAL w1, w2, w3 : BIT; BEGIN -component instantiation statements. -ports of component are mapped to signals -within architecture by position. gate1 : and2 PORT MAP (a, b, w1); gate2 : and2 PORT MAP (b, c, w2); gate3 : an

29、d2 PORT MAP (a, c, w3); gate4 : or3 PORT MAP (w1, w2, w3, m); h t t p : / / w w w . a m i . b o l t o n . a c . u k / c o u r s e w a r e / a d v e d a / v h d l / v h d l e x m p . h t m l ( 6 o f 6 7 ) 2 3 / 1 / 2 0 0 2 4 : 1 5 : 0 8 Examples of VHDL Descriptions END structure; -Behavioural style

30、architecture using a look-up table ARCHITECTURE using_table OF maj IS BEGIN PROCESS(a,b,c) CONSTANT lookuptable : BIT_VECTOR(0 TO 7) := 00010111; VARIABLE index : NATURAL; BEGIN index := 0; -index must be cleared each time process executes IF a = 1 THEN index := index + 1; END IF; IF b = 1 THEN inde

31、x := index + 2; END IF; IF c = 1 THEN index := index + 4; END IF; m ,).Second architecture shows sequential behaviour -description.Both descriptions do not fully model behaviour of real -device for all possible combinations of inputs. ENTITY mag4comp IS GENERIC(eqdel,gtdel,ltdel : TIME := 10 ns); -o

32、utput delay parameters PORT(a,b : IN BIT_VECTOR(3 DOWNTO 0); -input words, DOWNTO ordering needed for comparison operators aeqbin,agtbin,altbin : IN BIT; -expansion inputs aeqbout,agtbout,altbout : OUT BIT); -outputs END mag4comp; ARCHITECTURE dataflow OF mag4comp IS -this architecture assumes that

33、only one of the expansion inputs -is active at any time,if more than one expansion input is active, -more than one output may be active. BEGIN aeqbout = 1 AFTER eqdel WHEN (a = b) AND (aeqbin = 1) ELSE 0 AFTER eqdel; agtbout b) OR (a = b) AND (agtbin = 1) ELSE 0 AFTER gtdel; altbout = 1 AFTER ltdel

34、WHEN (a b) THEN agtbout = 1 AFTER gtdel; aeqbout = 0 AFTER eqdel; altbout = 0 AFTER ltdel; ELSIF (a b) THEN altbout = 1 AFTER ltdel; aeqbout = 0 AFTER eqdel; agtbout = 0 AFTER gtdel; ELSE -a=b,expansion inputs have priority ordering IF (aeqbin = 1) THEN aeqbout = 1 AFTER eqdel; agtbout = 0 AFTER gtd

35、el; altbout = 0 AFTER ltdel; ELSIF (agtbin = 1) THEN agtbout = 1 AFTER gtdel; altbout = 0 AFTER ltdel; h t t p : / / w w w . a m i . b o l t o n . a c . u k / c o u r s e w a r e / a d v e d a / v h d l / v h d l e x m p . h t m l ( 7 o f 6 7 ) 2 3 / 1 / 2 0 0 2 4 : 1 5 : 0 8 Examples of VHDL Descri

36、ptions aeqbout = 0 AFTER eqdel; ELSIF (altbin = 1) THEN agtbout = 0 AFTER gtdel; altbout = 1 AFTER ltdel; aeqbout = 0 AFTER eqdel; ELSE agtbout = 0 AFTER gtdel; altbout = 0 AFTER ltdel; aeqbout = 0 AFTER eqdel; END IF; END IF; END PROCESS; END behaviour; 8-bit Register with Synchronous Load and Clea

37、r The design entity shows the standard way of describing a register using a synchronous process, ie. a process containing a single wait statement which is triggered by a rising edge on the clock input. library ieee; use ieee.std_logic_1164.all; entity reg8 is port(clock, clear, load : in std_logic;

38、d : in std_logic_vector(7 downto 0); q : out std_logic_vector(7 downto 0); end entity reg8; architecture v1 of reg8 is begin reg_proc : process begin wait until rising_edge(clock); if clear = 1 then q 0); elsif load = 1 then q = d; end if; end process; end architecture v1; BCD to Seven Segment Decod

39、er The use of the std_logic literal - (dont care) is primarily for the synthesis tool. This example illustrates the use of the selected signal assignment. LIBRARY ieee; USE ieee.std_logic_1164.ALL; ENTITY seg7dec IS PORT(bcdin : IN std_logic_vector(3 DOWNTO 0); segout : OUT std_logic_vector(6 DOWNTO

40、 0); END seg7dec; ARCHITECTURE ver3 OF seg7dec IS BEGIN WITH bcdin SELECT segout = 1000000 WHEN X0, 1100111 WHEN X1, 1101101 WHEN X2, 0000011 WHEN X3, 0100101 WHEN X4, 0001001 WHEN X5, 0001000 WHEN X6, 1100011 WHEN X7, 0000000 WHEN X8, h t t p : / / w w w . a m i . b o l t o n . a c . u k / c o u r

41、s e w a r e / a d v e d a / v h d l / v h d l e x m p . h t m l ( 8 o f 6 7 ) 2 3 / 1 / 2 0 0 2 4 : 1 5 : 0 8 Examples of VHDL Descriptions 0000001 WHEN X9, - WHEN OTHERS; END ver3; 2-to-4 Decoder with Testbench and Configuration This set of design units illustrates several features of the VHDL language including: l Using generics to pass time delay values to design entities. l Design hierarchy using instantiated components. l Test benches for design verification. l Configuration declaration for

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 教育教学 > 成人教育


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号