Download presentation
Presentation is loading. Please wait.
Published byMabel Turner Modified over 9 years ago
1
Copyright (c) 2003 by Valery Sklyarov and Iouliia Skliarova: DETUA, IEETA, Aveiro University, Portugal
2
This schematic, which has already been considered in previous tutorials will be used to illustrate various simulation modes The block fsm_data will be verified with the aid of different simulation techniques 1 means YES 0 1 0 S 0...S 7 Data can be entered from DIP switchers and the result can be displayed on LCD. Thus, the circuit can be not only verified in simulator but can also be tested in FPGA
3
This block permits to check if an 8-bit vector has 3 or more successive ones 1 0 S 0...S 7 10100111 = x”A7” contains 3 successive ones 1 means YES 1 it means YES it contains at least 3 successive ones library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity fsm_data is Port ( rin : in std_logic_vector(7 downto 0); result : out std_logic_vector(3 downto 0); reset : in std_logic; clk : in std_logic); end fsm_data; Just one less-significant bit of the result is used. This was done to avoid changes in the remaining circuit that is also used for other examples that require all 4 bits of the result 0-NO 1-YES
4
architecture Behavioral of fsm_data is type STATE_TYPE is (start, one_one, two_ones, three_ones); signal CS, NS: STATE_TYPE; signal tmp : std_logic; signal index : integer range 0 to 8; begin process (clk,reset) begin if reset='1' then CS <= start; elsif (clk'event and clk = '1') then CS <= NS; end if; end process; Current State of FSM Next State of FSM 1 0 S 0...S 7 extra index temporary value for the result (either 1 – YES or 0 - NO)
5
process (CS,rin,index) begin if index = 8 then NS <= start; else case CS is when start => tmp <= '0'; if (rin(index) = '1') then NS <= one_one; else NS <= start; end if; when one_one => if (rin(index) = '1') then NS <= two_ones; else NS <= start; end if; when two_ones => if (rin(index) = '1') then NS <= three_ones; else NS <= start; end if; when three_ones => tmp <= '1'; if index = 0 then NS <= start; else NS <= three_ones; end if; end case; end if; end process; one_one two_ones start index = 0, i.e. start from the beginning three_ones There are 3 successive ones
6
process (clk,reset) begin if (reset='1') then index <= 0; result '0'); elsif falling_edge(clk) then if index = 7 then result <= "000" & tmp; end if; if index = 8 then index <= 0; else index <= index+1; end if; end process; end Behavioral; 1 0 S 0...S 7 0 1 7 storing the result skipping one clock cycle for resynchronization between FSM and process (rising edge) end this process (falling edge) Just the less significant bit might be changed
7
2 3 4 1 5 6
8
14 7 89 10 right mouse button click 11 12 right mouse button click 13 15 16
9
19 Set 1 and 0 with the aid of mouse (click left mouse button) 17 18 2120 left mouse button double click 9D 16 = 10011101 2
10
1 2 left mouse button double click 3
11
4 10011101 2
12
period The Input setup time defines when inputs must be valid The Output valid delay defines the time after active clock edge when the outputs must be valid
13
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity VHDL_test is Port ( data_in : in std_logic_vector(7 downto 0); data_out : out std_logic_vector(3 downto 0); index_out: out std_logic_vector(3 downto 0)); end VHDL_test; architecture Behavioral of VHDL_test is function parity (input : std_logic_vector)return std_logic is variable temp : std_logic := '0'; begin for i in input'range loop temp := temp xor input(i); end loop; return temp; end parity; begin data_out <= "000" & parity(data_in); end Behavioral;
14
12
16
4 Workspace 1 325
18
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity shift_r is Port ( CLK: in STD_LOGIC; RESET : in STD_LOGIC; DIN: in STD_LOGIC; DOUT: out STD_LOGIC_VECTOR(3 downto 0)); end shift_r; architecture Behavioral of shift_r is signal REG: STD_LOGIC_VECTOR(3 downto 0); begin process (CLK,RESET) begin if reset = '1' then REG '0'); elsif CLK'event and CLK='1' then REG <= DIN & REG(3 downto 1); end if; DOUT <= REG; end process; end Behavioral; BIT2BIT3BIT1BIT0 CLK RESET DIN DOUT
19
6 7 8 right mouse button click 9 the compiled design unit 10 left mouse button double click
20
11 12 13 14
21
15 left mouse button double click 16 17
22
18 19 20
23
21222324 Run Restart Run Continue Run Run All Break
24
see slides 2-6 This can be done just in ModelSim environment, i.e. without Xilinx ISE 5.x 123456
25
789 10 11 12 13
26
14151617 18 19 20 21 22 Double click left mouse button to load the design
27
23 24 25 Main Window Workspace Transcript (command line) Dataflow window The Dataflow window allows to explore the "physical" connectivity of the design. It displays processes and signals, nets, and registers. Process window displays a list of processes Signals window The left pane shows the names of HDL items. The left pane shows the values of the associated HDL items at the end of the current run Source window The Source window allows to view and edit HDL source code Variables window Wave window allows to view the results of simulation.
28
26 27 28 1 force clk 0 0, 1 50 -repeat 100 2 force reset 1 0, 0 70 3 force rin 01011101 29 050 100 150200250 70 rin = 01011101 2 clk reset 30 31 32
29
3334 35 The value of rin specified in the file stimulus current state (CS)next state (NS) After one iteration (index is changed from 0 to 8) the result is equal to 1 (YES) - 01011101 reset clock tmp keeps intermediate result
30
36 37 38 39 left mouse button click break can be set only for blue numbers 4041 42 click left mouse button to disable (to enable break point)
31
To delete the breakpoint or to change its options, click the line number with the right mouse button 43 breakpoint step 44 Step inserting a cursor deleting a cursor
32
The first cursor The second cursor Time between the cursors Point to a wave with the mouse in order to see the value Point to a wave with the mouse in order to see the value find previous transition find next transition
34
Zoom with mouse specifying zoom area
35
to quit simulation to quit ModelSim
36
list window shows all changes of signals step by step You can use list window much like wave window this vector contains 5 values “1” compare this two pictures
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.