EASTERN MEDITERRANEAN UNIVERSITY COMPUTER ENGINEERING DEPARTMENT CMPE224 DIGITAL LOGIC SYSTEMS VHDL EXPERIMENT VII TITLE: VHDL IMPLEMENTATION OF ALGORITHMIC STATE MACHINES OBJECTIVES: VHDL implementation of digital systems described using ASM charts will be studied. The students are expected to learn the implementation issues of ASM charts. Below, you will find detailed examples on the implementation of different ASM charts and associated digital systems in VHDL. Examine these VHDL codes and implement them in Quartus II environment to understand the underlying ideas better. Example : Bit-Counting Circuit. Pseudo-code of counting the number of s within the contents of a register A and storing the count in counter B is as follows: B=; while A do if a = then B=B+; Right-shift A; end while; ASM chart for this pseudo-code is given below: The state box for the starting state S specifies that B is initialized to. There is an input signal s used to indicate when the data to be processed has been loaded into A, so that the machine can start. When s becomes one the machine changes to state S2.The decision box below state S2 checks whether A=. If so, the bit counting operation is complete and the machine should change to state S3. If not, the ASM remains in S2. In state S3, counter B contains the result which is the number of s in A. An output signal Done is set to to indicate that the algorithm is finished. The FSM stays in S3 until s goes back to.
Reset S Load B s s S2 S Shift right A Done B B + A =? a ASM chart for the bit-counting circuit. Data-path circuit The datapath circuit for the bit-counting system described above consists of an n-bit shift register and a log 2 n -bit up-counter.
Data n log 2 n LA EA Clock w L E Shift A LB EB L E Counter log 2 n n z a B Datapath circuit for ASM of bit-counting system. In the above datapath circuit LA and EA represents the Load A and Enable A signals. The parallel input to register A is named Data, and its parallel aoutput is A. An n-input NOR gate is used to test whether A=. The output of this gate is when A=; i.e., z= when A=. The counter has a log 2 n bits, with parallel inputs connected to. The counter has a parallel load input LB and an enable input EB. Control Circuit The ASM needed for the control circuit is given below. This ASM illustrates how the inputs LA, s, a, and z are processed and how the outputs EA, LB, EB, and Done are generated. the control circuit of the bit- The VHDL code implementing the datapath and counting system is also presented below.
Reset S EA LB EB LA s s S2 S3 EA Done EB z a ASM needed for the control circuit of bit-counting system VHDL Code for the BIT COUNTING example
Date: May 9, 23 ExpVII.vhd Project: ExpVII LIBRARY ieee; USE ieee.std_logic_64.all; USE ieee.std_logic_unsigned.all ; ENTITY ExpVII IS PORT( Clock : IN STD_LOGIC; Load_A,s : IN STD_LOGIC; InputStream : IN STD_LOGIC_VECTOR (7 DOWNTO ); B : OUT STD_LOGIC_VECTOR (3 DOWNTO ); Done : OUT STD_LOGIC); END ExpVII; ARCHITECTURE Behavior OF ExpVII IS SIGNAL STATE : STD_LOGIC_VECTOR ( DOWNTO ); SIGNAL A : STD_LOGIC_VECTOR (7 DOWNTO ); SIGNAL BB : STD_LOGIC_VECTOR (3 DOWNTO ); SIGNAL z, EA, EB : STD_LOGIC; State_Transitions: PROCESS (Clock) IF (Clock'EVENT AND Clock='') THEN if STATE = "" then if s = '' then STATE <= ""; else STATE <= ""; elsif STATE = "" then if z = '' then STATE <= ""; else STATE <= ""; elsif STATE = "" then if s = '' then STATE <= ""; else STATE <= ""; END PROCESS; Control_Outputs: PROCESS (STATE,s,A()) Done<=''; IF STATE="" THEN EA<=''; EB<=''; ELSIF STATE="" THEN EA<=''; IF A()='' THEN EB<=''; ELSE Revised by ShAhin MPA Page of 2 Revision: ExpVII
Date: May 9, 23 ExpVII.vhd Project: ExpVII EB<=''; ELSIF STATE="" THEN EA <= ''; EB <= ''; Done<=''; END PROCESS; Datapath: PROCESS (Clock) IF (Clock'EVENT AND Clock='') THEN IF STATE="" THEN BB<=""; ELSE if EB = '' then BB<=BB+; END PROCESS; ShiftA: PROCESS(Clock,InputStream,Load_A,s,Clock) IF (Clock'EVENT AND Clock='') THEN IF (Load_A='') THEN A<=InputStream; ELSE IF EA='' THEN A<=''&A(7 DOWNTO ); IF A="" THEN z<=''; ELSE z<=''; END PROCESS; B<=BB; END Behavior; Revised by ShAhin MPA Page 2 of 2 Revision: ExpVII
PRELIMINARY WORK:. Write down the VHDL code for the bit-counting circuit described above. Perform all experimental steps including VHDL coding, waveform preparation, and simulations; make them ready before you come to the laboratory. 2. Make slight modifications in the above VHDL code to count the number of s in A. Perform all experimental steps for this implementation also. EXPERIMENTAL WORK: Demonstrate your preliminary work to the laboratory assistants using Quartus II environment. Be ready for detailed questions on your work. Good Luck. Dr. Adnan Acan Dr. Evgueni Doukhnitch Dr. Muhammed Salamah.