High-Low Guessing Game

Slides:



Advertisements
Similar presentations
Fundamentals of Digital Signal Processing יהודה אפק, נתן אינטרטור אוניברסיטת תל אביב.
Advertisements

Arbitrary Waveform Discussion 5.5 Example 34.
1 VLSI DESIGN USING VHDL Part II A workshop by Dr. Junaid Ahmed Zubairi.
Ring Counter Discussion D5.3 Example 32. Ring Counter if rising_edge(CLK) then for i in 0 to 2 loop s(i)
Generic Multiplexers: Parameters Discussion D2.5 Example 8.
Decoders and Encoders Lecture L4.2. Decoders and Encoders Binary Decoders Binary Encoders Priority Encoders.
Integer Square Root.
Simple Sequential Circuits in VHDL. Contents Sequential circuit examples: - SR latch in dataflow style - D flip-flop in behavioral style - shift register.
1 Comparators Discussion D A 1-Bit Comparator The variable Gout is 1 if x > y or if x = y and Gin = 1. The variable Eout is 1 if x = y and Gin =
Counters Discussion D5.3 Example 33. Counters 3-Bit, Divide-by-8 Counter 3-Bit Behavioral Counter in Verilog Modulo-5 Counter An N-Bit Counter.
Digilab 7-Segment Displays Lab 4. selyInstruction name “000”true if b = a false otherwise = “001”true if b /= a false otherwise “010”true if b < a.
Finite State Machines Discussion D8.1 Example 36.
7-Segment Displays Digilent Spartan 3 Board Discussion DS-4.2.
Introduction to VHDL Multiplexers Discussion D1.1.
Binary-to-BCD Converter
Binary-to-BCD Converter
Shift Registers Discussion D5.2 Example Bit Shift Register qs(3) qs(2) qs(1) qs(0) if rising_edge(CLK) then for i in 0 to 2 loop s(i) := s(i+1);
4-bit Shift Register. 2-bit Register Serial-in-serial-out Shift Register.
1 Part V: VHDL CODING. 2 Design StructureData TypesOperators and AttributesConcurrent DesignSequential DesignSignals and VariablesState Machines A VHDL.
Binary-to-BCD Converter
1 Copyright (c) 2003 by Valery Sklyarov and Iouliia Skliarova: DETUA, IEETA, Aveiro University, Portugal.
A.7 Concurrent Assignment Statements Used to assign a value to a signal in an architecture body. Four types of concurrent assignment statements –Simple.
Figure 5.1 Conversion from decimal to binary. Table 5.1 Numbers in different systems.
1 Sequential Logic Lecture #7. 모바일컴퓨팅특강 2 강의순서 Latch FlipFlop Shift Register Counter.
CprE / ComS 583 Reconfigurable Computing
VHDL in 1h Martin Schöberl. AK: JVMHWVHDL2 VHDL /= C, Java,… Think in hardware All constructs run concurrent Different from software programming Forget.
1 ECE 545—Digital System Design with VHDL Lecture 6 Behavioral VHDL Coding (for Synthesis): Finite State Machines and ASMs 9/30/08.
ENG241 Digital Design Week #8 Registers and Counters.
VHDL for Combinational Circuits. VHDL We Know Simple assignment statements –f
Reaction Timer Project
ECE 331 – Digital System Design Multiplexers and Demultiplexers (Lecture #13)
2’s Complement 4-Bit Saturator Discussion D2.8 Lab 2.
1 MIPS VHDL Overview Reference: VHDL Tutorial on CDROM, or Accolade Reference Guide Notes: / / pdf / MIPS_vhdl_notes.pdf.
4-to-1 Multiplexer: Module Instantiation Discussion D2.2 Example 5.
VHDL Discussion Sequential Sytems. Memory Elements. Registers. Counters IAY 0600 Digital Systems Design Alexander Sudnitson Tallinn University of Technology.
 Seattle Pacific University EE Logic System DesignCounters-1 Shift Registers DQ clk DQ DQ ShiftIn Q3Q3 Q2Q2 DQ Q1Q1 Q0Q0 A shift register shifts.
CS/EE 3700 : Fundamentals of Digital System Design
Sequential Logic Design by VHDL
George Mason University ECE 448 – FPGA and ASIC Design with VHDL VHDL Coding for Synthesis ECE 448 Lecture 12.
Copyright (c) 2003 by Valery Sklyarov and Iouliia Skliarova: DETUA, IEETA, Aveiro University, Portugal.
Number Representation and Arithmetic Circuits
Lecture 8 Review Combinational Devices –Decoder –Multiplexor (Bhasker p-81) –Shifter –Barrel Shifter (Bhasker p-303)
EGRE 6311 LHO 04 - Subprograms, Packages, and Libraries EGRE 631 1/26/09.
Registers and Counters Discussion D8.1. Logic Design Fundamentals - 3 Registers Counters Shift Registers.
Fundamentals of Digital Signal Processing יהודה אפק, נתן אינטרטור אוניברסיטת תל אביב.
Sequential statements (1) process
Combinational logic circuit
Describing Combinational Logic Using Processes
Registers and Counters
Figure 7.1 Control of an alarm system
Part III: SYSTEM DESIGN
Hardware Description Languages
CHAPTER 17 VHDL FOR SEQUENTIAL LOGIC
Part IV: VHDL CODING.
Comparators Discussion DS-3.1.
ECE 4110–5110 Digital System Design
CPE 528: Session #7 Department of Electrical and Computer Engineering University of Alabama in Huntsville.
Algorithmic State Machine (ASM) Charts: VHDL Code & Timing Diagrams
Binary-to-BCD Converter
VHDL (VHSIC Hardware Description Language)
ECE 448 Lecture 13 Multipliers Timing Parameters
CPE 528: Lecture #5 Department of Electrical and Computer Engineering University of Alabama in Huntsville.
Fibonacci Sequence Lecture L4.1 Lab 3.
ECE 331 – Digital System Design
Figure 8.1. The general form of a sequential circuit.
Fast, Asynchronous SRAM
Sequntial-Circuit Building Blocks
4-Input Gates VHDL for Loops
디 지 털 시 스 템 설 계 UP2 Kit를 이용한 카운터 설계
(Sequential-Circuit Building Blocks)
Presentation transcript:

11.2.3 High-Low Guessing Game

Clock.vhd LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; ENTITY Clockdiv IS PORT ( Clk25Mhz: IN STD_LOGIC; Clk: OUT STD_LOGIC); END Clockdiv; ARCHITECTURE Behavior OF Clockdiv IS -- CONSTANT max: INTEGER := 1000; -- minimum to debounce switch CONSTANT max: INTEGER := 5000000; -- good to see FSM states -- CONSTANT max: INTEGER := 10000000; -- 10000000; = 1sec CONSTANT half: INTEGER := max/2; SIGNAL count: INTEGER RANGE 0 TO max; BEGIN PROCESS WAIT UNTIL Clk25Mhz'EVENT and Clk25Mhz = '1'; IF count < max THEN count <= count + 1; ELSE count <= 0; END IF; IF count < half THEN Clk <= '0'; Clk <= '1'; END PROCESS; END Behavior;

Bcd.vhd LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; ENTITY BCD IS PORT ( in_bcd: IN std_logic_vector(3 DOWNTO 0); segs: OUT std_logic_vector(1 TO 7)); END BCD; ARCHITECTURE Behavioral OF BCD IS BEGIN PROCESS(in_bcd) CASE in_bcd IS -- 0=on; 1=off WHEN "0000" => segs <= "0000001"; -- 0 WHEN "0001" => Segs <= "1001111"; -- 1 WHEN "0010" => Segs <= "0010010"; -- 2 WHEN "0011" => Segs <= "0000110"; -- 3 WHEN "0100" => Segs <= "1001100"; -- 4 WHEN "0101" => Segs <= "0100100"; -- 5 WHEN "0110" => Segs <= "0100000"; -- 6 WHEN "0111" => Segs <= "0001111"; -- 7 WHEN "1000" => Segs <= "0000000"; -- 8 WHEN "1001" => Segs <= "0001100"; -- 9 WHEN "1010" => Segs <= "0001000"; -- A WHEN "1011" => Segs <= "1100000"; -- b WHEN "1100" => Segs <= "0110001"; -- C WHEN "1101" => Segs <= "1000010"; -- d WHEN "1110" => Segs <= "0110000"; -- E WHEN "1111" => Segs <= "0111000"; -- F WHEN OTHERS => Segs <= "1111111"; -- all off END CASE; END PROCESS; END Behavioral;

Bin_to_bcd.vhd IF (n >= 90) THEN IF (n >= 100) THEN bcd_tenth <= "1001"; ten := 90; ELSIF (n >= 80) THEN bcd_tenth <= "1000"; ten := 80; ELSIF (n >= 70) THEN bcd_tenth <= "0111"; ten := 70; ELSIF (n >= 60) THEN bcd_tenth <= "0110"; ten := 60; ELSIF (n >= 50) THEN bcd_tenth <= "0101"; ten := 50; ELSIF (n >= 40) THEN bcd_tenth <= "0100"; ten := 40; ELSIF (n >= 30) THEN bcd_tenth <= "0011"; ten := 30; ELSIF (n >= 20) THEN bcd_tenth <= "0010"; ten := 20; ELSIF (n >= 10) THEN bcd_tenth <= "0001"; ten := 10; ELSE bcd_tenth <= "0000"; ten := 0; END IF; unit := n - ten; bcd_unit <= CONV_STD_LOGIC_VECTOR(unit,4); END Process; END Behavioral; -- this program converts an 8-bit unsigned value to two BCD values -- if number >= 200, the decimal point for the tenth digit is on -- if 200 > number >= 100, the decimal point for the unit digit is on -- if number < 99, the two decimal digits will be separated into two BCD values LIBRARY IEEE; USE IEEE.std_logic_1164.all; USE ieee.std_logic_unsigned.all; -- for CONV_INTEGER() USE IEEE.std_logic_arith.all; -- for CONV_STD_LOGIC_VECTOR() ENTITY bin_to_bcd IS PORT ( binary: IN STD_LOGIC_VECTOR(7 DOWNTO 0); point200, point100: OUT STD_LOGIC; bcd_tenth, bcd_unit: OUT STD_LOGIC_VECTOR(3 DOWNTO 0)); END bin_to_bcd; ARCHITECTURE Behavioral OF bin_to_bcd IS BEGIN PROCESS(binary) VARIABLE n: integer RANGE 0 TO 255; VARIABLE ten: integer RANGE 0 TO 99; VARIABLE unit: integer RANGE 0 TO 9; n := CONV_INTEGER(binary); IF (n >= 200) THEN point200 <= '1'; n := n - 100; ELSE point200 <= '0'; END IF; IF (n >= 100) THEN point100 <= '1'; point100 <= '0';

Bin2dec.vhd LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; ENTITY bin2dec IS PORT ( input: IN STD_LOGIC_VECTOR(7 DOWNTO 0); PointN200,PointN100: OUT STD_LOGIC; aN10,bN10,cN10,dN10,eN10,fN10,gN10,aN1,bN1,cN1,dN1,eN1,fN1,gN1: OUT STD_LOGIC); END bin2dec; ARCHITECTURE Structural OF bin2dec IS COMPONENT bin_to_bcd PORT ( binary: IN STD_LOGIC_VECTOR(7 DOWNTO 0); point200, point100: OUT STD_LOGIC; bcd_tenth, bcd_unit: OUT STD_LOGIC_VECTOR(3 DOWNTO 0)); END COMPONENT; COMPONENT BCD PORT ( in_bcd: IN std_logic_vector(3 DOWNTO 0); segs: OUT std_logic_vector(1 TO 7)); SIGNAL c_bcd1,c_bcd10: STD_LOGIC_VECTOR(3 DOWNTO 0); SIGNAL c_point200,c_point100: STD_LOGIC; SIGNAL c_seg10,c_seg1: STD_LOGIC_VECTOR(1 TO 7); BEGIN U1: bin_to_bcd PORT MAP (input,c_point200,c_point100,c_bcd10,c_bcd1); U2: BCD PORT MAP (c_bcd10,c_seg10); U3: BCD PORT MAP (c_bcd1,c_seg1); PointN200 <= NOT c_point200; PointN100 <= NOT c_point100; aN10 <= c_seg10(1); bN10 <= c_seg10(2); cN10 <= c_seg10(3); dN10 <= c_seg10(4); eN10 <= c_seg10(5); fN10 <= c_seg10(6); gN10 <= c_seg10(7); aN1 <= c_seg1(1); bN1 <= c_seg1(2); cN1 <= c_seg1(3); dN1 <= c_seg1(4); eN1 <= c_seg1(5); fN1 <= c_seg1(6); gN1 <= c_seg1(7); END Structural;

Mp.vhd BEGIN next_state_logic: PROCESS(reset, clock) IF(reset = '1') THEN state <= s0; Largest <= (OTHERS => '0'); ELSIF(clock'EVENT AND clock = '1') THEN CASE state IS WHEN s0 => X <= input; IF (enter = '1') THEN state <= s1; ELSE state <= s0; END IF; WHEN s1 => IF (X = "00000000") THEN state <= s3; ELSIF (X > Largest) THEN state <= s2; ELSIF (enter = '0') THEN state <= s0; ELSE state <= s1; END IF; WHEN s2 => Largest <= X; IF (enter = '0') THEN state <= s0; ELSE state <= s2; END IF; WHEN s3 => state <= s3; WHEN OTHERS => END CASE; END PROCESS; -- all the output signals must be assigned in a process without -- the IF Clock'EVENT condition, otherwise they will be treated -- as storage elements and therefore cannot be tri-stated output_logic: PROCESS(state) output <= Largest; done <= '1'; done <= '0'; END FSMD; Mp.vhd LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.STD_LOGIC_unsigned.ALL; ENTITY mp IS PORT ( clock, reset : IN STD_LOGIC; input: IN STD_LOGIC_VECTOR(7 DOWNTO 0); enter: IN STD_LOGIC; done: OUT STD_LOGIC; output: OUT STD_LOGIC_VECTOR(7 DOWNTO 0)); END mp; ARCHITECTURE FSMD OF mp IS TYPE state_type IS (s0, s1, s2, s3); SIGNAL state: state_type; SIGNAL X: STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL Largest: STD_LOGIC_VECTOR(7 DOWNTO 0);

Up2flex.gdf

signal pin number clock Pin_91 Enter Pin_28 Reset Pin_29 aN1 Pin_17 aN10 Pin_6 input(7) Pin_41 bN1 Pin_18 bN10 Pin_7 input(6) Pin_40 cN1 Pin_19 cN10 Pin_8 input(5) Pin_39 dN1 Pin_20 dN10 Pin_9 input(4) Pin_38 eN1 Pin_21 eN10 Pin_11 input(3) Pin_36 fN1 Pin_23 fN10 Pin_12 input(2) Pin_35 gN1 Pin_24 gN10 Pin_13 input(1) Pin_34 pointN100 Pin_25 pointN200 Pin_14 input(0) Pin_33