Presentation is loading. Please wait.

Presentation is loading. Please wait.

Finite State Machines VHDL ET062G & ET063G Lecture 6 Najeem Lawal 2012.

Similar presentations


Presentation on theme: "Finite State Machines VHDL ET062G & ET063G Lecture 6 Najeem Lawal 2012."— Presentation transcript:

1 Finite State Machines VHDL ET062G & ET063G Lecture 6 Najeem Lawal 2012

2 FINITE STATE MACHINES OUTLINE –Range Sensor display –FSM in VHDL Medvedev FSM Moore FSM Mealy FSM –FSMD – FSM and Data path

3 RANGE SENSOR DISPLAY Najeem Lawal, 20123 VHDL ET062G & ET063G Lecture 6 1.Specify the number of rows 2.Specify the location of the display 3.Determine the effective number of bits for range sensor data 479 639 0 0 300 301 50 364 400 40 20 64

4 RANGE SENSOR DISPLAY Najeem Lawal, 20124 VHDL ET062G & ET063G Lecture 6 1.Specify the number of rows 2.Specify the location of the display 3.Determine the effective number of bits for range sensor data What do you need 1.2 counters 1.Column counter to assess the content of the memory 2.Row counter to know what to display 2.Comparator 479 639 0 0 300 301 50 364 400 40 20 64

5 RANGE SENSOR DISPLAY Najeem Lawal, 20125 VHDL ET062G & ET063G Lecture 6 1.Specify the number of rows 2.Specify the location of the display 3.Determine the effective number of bits for range sensor data if (vcount > 300 and vcount < 365) then if ((vcount - 300) >= (64 - pixel_data(7 downto 2))) then red_out <= "111"; green_out<= "111"; blue_out <= "11"; else red_out <= "000"; green_out<= "000"; blue_out <= "00"; end if; else red_out <= red_in; green_out <= green_in; blue_out <= blue_in; end if; 479 639 0 0 300 301 50 364 400 40 20 64

6 RANGE SENSOR DISPLAY Najeem Lawal, 20126 VHDL ET062G & ET063G Lecture 6 1.Specify the number of rows 2.Specify the location of the display 3.Determine the effective number of bits for range sensor data To solve this problem 1.use if statements 2.use case statements 3.or combine into FSM 479 639 0 0 300 301 50 364 400 40 20 64

7 USE CASES Najeem Lawal, 20127 VHDL ET062G & ET063G Lecture 5 STUDENT PROJECT PRESENTATIONS –Farid –Ashkan –Patrick HOW THE SOLVED –Range sensor –Edge detection –Sliding window

8 DESIGN OF STATE MACHINES Najeem Lawal, 20128 VHDL ET062G & ET063G Lecture 6 MANUAL DESIGN WORK FLOW: Develop a state graph that captures the problem Develop a solution state graph Coding of states Select register elements (D-,T-,JK- ?) Develop a transition table Develop boolean functions for and  Design circuitry at gate level

9 DESIGN OF STATE MACHINES Najeem Lawal, 20129 VHDL ET062G & ET063G Lecture 6 AUTOMATIC SYNTHESIS Develop a state diagram for the problem Write VHDL-code that captures the problem Automatic synthesis will perform coding of state graph and generate a gate level netlist

10 FINITE STATE MACHINES AND VHDL COMPARISON Medvedev is too inflexible Moore is preferred, because of safe operation Mealy more flexible but danger of Spikes Unnecessary long paths (maximal clock period)

11 MEDVEDEV MACHINE Najeem Lawal, 201211 VHDL ET062G & ET063G Lecture 6 Output IS the state Two Processes architecture RTL of MEDVEDEV is... begin REG: process (CLK, RESET) begin -- State Registers Inference end process REG ; CMB: process (X, STATE) begin -- Next State Logic end process CMB ; end RTL ; One Process architecture RTL of MEDVEDEV is... begin REG: process (CLK, RESET) begin -- State Registers Inference with Logic Block end process REG ; end RTL ;

12 MEDVEDEV EXAMPLE Najeem Lawal, 201212 VHDL ET062G & ET063G Lecture 6 architecture RTL of MEDVEDEV_TEST is signal STATE,NEXTSTATE : STATE_TYPE ; begin REG: process (CLK, RESET) begin if RESET=`1` then STATE <= START ; elsif CLK`event and CLK=`1` then STATE <= NEXTSTATE ; end if ; end process REG; CMB: process (A,B,STATE) begin NEXTSTATE <= STATE ; case STATE is when START => if (A and B)=`0` then NEXTSTATE <= MIDDLE ; end if ; when MIDDLE => if (A and B)=`1` then NEXTSTATE <= STOP ; end if ; when STOP => if (A xor B)=`1` then NEXTSTATE <= START ; end if ; when others => NEXTSTATE <= START ; end case ; end process CMB ; --concurrent signal assignments for output (Y,Z) <= STATE ; end RTL ; Output IS the state

13 MEDVEDEV WAVEFORM Najeem Lawal, 201213 VHDL ET062G & ET063G Lecture 6 (Y,Z) = STATE => Medvedev machine Output IS the state

14 MOORE MACHINE Najeem Lawal, 201214 VHDL ET062G & ET063G Lecture 6 Three Processes architecture RTL of MOORE is... begin REG: -- Clocked Process CMB: -- Combinational Process OUTPUT: process (STATE) begin -- Output Logic end process OUTPUT ; end RTL ; Two Processes architecture RTL of MOORE is... begin REG: process (CLK, RESET) begin -- State Registers Inference with Next State Logic end process REG ; OUTPUT: process (STATE) begin -- Output Logic end process OUTPUT ; end RTL ; Output is a function of ONLY the state

15 MOORE MACHINE EXAMPLE Najeem Lawal, 201215 VHDL ET062G & ET063G Lecture 6 architecture RTL of MOORE_TEST is signal STATE,NEXTSTATE : STATE_TYPE ; begin REG: process (CLK, RESET) begin if RESET=`1` then STATE <= START ; elsif CLK`event and CLK=`1` then STATE <= NEXTSTATE ; end if ; end process REG ; CMB: process (A,B,STATE) begin NEXTSTATE <= STATE ; case STATE is when START => if (A and B)=`0` then NEXTSTATE <= MIDDLE ; end if ; when MIDDLE => if (A and B)=`1` then NEXTSTATE <= STOP ; end if ; when STOP => if (A xor B)=`1` then NEXTSTATE <= START ; end if ; when others => NEXTSTATE <= START ; end case ; end process CMB ; -- concurrent signal assignments for output Y <= ’1’ when STATE=MIDDLE else ‘0’ ; Z <= ‘1’ when STATE=MIDDLE or STATE=STOP else ‘0’ ; end RTL ; Output is a function of ONLY the state

16 MOORE MACHINE WAREFORM Najeem Lawal, 201216 VHDL ET062G & ET063G Lecture 6 (Y,Z) changes synchronous with STATE => Moore machine Output is a function of ONLY the state

17 MEALY MACHINE Najeem Lawal, 201217 VHDL ET062G & ET063G Lecture 6 Three Processes architecture RTL of MEALY is... begin REG: -- Clocked Process CMB: -- Combinational Process OUTPUT: process (STATE, X) begin -- Output Logic end process OUTPUT ; end RTL ; Two Processes architecture RTL of MEALY is... begin MED: process (CLK, RESET) begin -- State Registers Inference with Next State Logic end process MED ; OUTPUT: process (STATE, X) begin -- Output Logic end process OUTPUT ; end RTL ; Output is a function of state AND input

18 MEALY MACHINE EXAMPLE Najeem Lawal, 201218 VHDL ET062G & ET063G Lecture 6 architecture RTL of MEDVEDEV_TEST is signal STATE,NEXTSTATE : STATE_TYPE ; begin REG: process (CLK, RESET) begin if RESET=`1` then STATE <= START ; elsif CLK`event and CLK=`1` then STATE <= NEXTSTATE ; end if ; end process REG; CMB: process (A,B,STATE) Begin -- Like Medvedev and Moore Examples end process CMB ; -- concurrent signal assignments for output Y <= `1` when (STATE=MIDDLE and (A or B)=`0`) or (STATE=STOP and (A and B)=`0`) else `0` ; Z <= `1` when (STATE=START and (A and B)=`1`) or (STATE=MIDDLE) or (STATE=STOP and (A or B)=`1`) else `0` ; end RTL ; Output is a function of state AND input

19 MEALY MACHINE WAVEFORM Najeem Lawal, 201219 VHDL ET062G & ET063G Lecture 6 (Y,Z) changes with input => Mealy machine Notice the "spikes" of Y and Z in the waveform FSM has to be modeled carefully so there are no spikes in normal operation. Output is a function of state AND input Spike

20 EXAMPLE OF STATE MACHINE IN VHDL Najeem Lawal, 201220 VHDL ET062G & ET063G Lecture 6 architecture rtl of fsm_simple is type state_type is (start, r1, r2); signal state : state_type; begin -- rtl update_state : process (clk, reset) begin -- process fsm if reset = '0' then state <= start; elsif clk'event and clk = '1' then case state is when start => if A = '0' then state <= start; else state <= r1; end if; when r1 => if A = '0' then state <= r1; else state <= r2; end if; when r2 => if A = '0' then state <= r2; else state <= start; end if; end case; end if; end process update_state; output_logic : process(state) begin case state is when start => z <= '0'; when r1 => z <= '1'; when r2 => z <= '0'; end case; end process output_logic; end rtl; r2 z=0 start z=0 r1 z=1 A=0 A=1 A=0 A=1

21 MEALY TYPE IN VHDL Najeem Lawal, 201221 VHDL ET062G & ET063G Lecture 6 architecture mealy of fsm2 is type state is (S1, S2, S3, S4); signal present_state, next_state: state; begin process (aIn, present_state) begin CASE present_state IS when s1 => if (aIn = ’1’) then yOut yOut yOut if (aIn = ’1’) then yOut <= ’1’; next_state <= s2; else yOut <= ’0’; next_state <= s1; end if; end case; end process; process begin wail until clk = ’1’; present_state <= next_state; end process; end mealy; S1S4 S3S2 aIn=1/yOut=1 aIn=-/yOut=1 aIn=0/yOut=0 aIn=1/yOut=0 aIn=0/ yOut=1 aIn=-/ yOut=1 aIn yOut next_state present_state Output function

22 MOORE TYPE IN VHDL Najeem Lawal, 201222 VHDL ET062G & ET063G Lecture 6 library ieee; use ieee.std_logic_1164.all; entity fsm1 is port (aIn, clk: in std_logic; yOut: out std_logic); end fsm1; architecture moore of fsm1 is type state is (s1, s2, s3, s4); signal present_state, next_state: state; begin process (aIn, present_state) begin case present_state is when s1 => yOut yOut yOut yOut <= ’1’; if (aIn = ’0’) then next_state <= s1; end if; end case; end process; process begin wait until clk = ’1’; present_state <= next_state; end process; end moore; S1S2 S4S3 yOut=0 aIn=0 yOut=0 yOut=1 aIn=0 aIn=1

23 COMPONENTS IN AN DIGITAL DESIGN Najeem Lawal, 201223 VHDL ET062G & ET063G Lecture 6 A digital design consists of –At least one control unit (FSM) –At least one datapath unit For example, adder, multiplier, comparator Register for temporary storage of variables Often a design consists of many controllers and datapaths Design model: FSM with datapath –Describes the function of the designs containing both control unit and datapath

24 FSM WITH DATAPATH Najeem Lawal, 201224 VHDL ET062G & ET063G Lecture 6 Control unit Datapath Control signals Status signals Control inputs control outputs Data inputs Data outputs FSMD control inputs Data inputs control outputs Data outputs

25 DESIGN EXAMPLE Najeem Lawal, 201225 VHDL ET062G & ET063G Lecture 6 DESIGN A FUNCTION COMPUTING: TypeDescription#bits Din, datavalues, positive integer, for a, x and b in sequence8 startin, controlActivate computation of Y, active high1 busyout, controlindicate that unit is busy computing1 Yout, dataThe computed value Y17 resetin, controlInitialize the unit1 Y=25 a = 5 x = 3b = 10 D start clk busy Y

26 CONT. DESIGN EXAMPLE Najeem Lawal, 201226 VHDL ET062G & ET063G Lecture 6 Y = a·x + b D start reset clk Y busy Control unit Datapath D Y resetstart busy storeA storePr External control signals Controlling the unit External control signal internal control signals External data signals

27 CONT. DESIGN EXAMPLE Najeem Lawal, 201227 VHDL ET062G & ET063G Lecture 6 start getA multAX addB Start=0 Start=1 busy = 0 storeA = 0 storePr = 0 busy = 1 storeA = 1 storePr = 0 busy = 1 storeA = 0 storePr = 1 busy = 1 storeA = 0 storePr = 0 × + EN D Y clk storeA storePr A X A×X B A×X+B

28 SUMMARY Najeem Lawal, 201228 VHDL ET062G & ET063G Lecture 6 ALL DIGITAL DESIGNS FOLLOW THE MODEL OF FSMD DESIGN FLOW –Specify the algorithm to be implemented –Identify Which components are needed in the datapath Which states are needed in the control unit Which control signals are needed to the datapath Which status signals are needed to the control unit –Develop State Transition Graph for the control unit Block diagram for the data path

29 QUESTIONS Najeem Lawal, 201229 VHDL ET062G & ET063G Lecture 5 ABOUT FPGA / VHDL ABOUT VGA DISPLAY / TIMING ABOUT IMAGE SENSOR TIMING ABOUT RANGE SENSOR ABOUT LINE BUFFERS ABOUT MEMORIES & COUNTERS

30 END OF LECTURE 6 Najeem Lawal, 201230 VHDL ET062G & ET063G Lecture 5 OUTLINE –Range Sensor display –FSM in VHDL Medvedev FSM Moore FSM Mealy FSM –FSMD – FSM and Data path

31 TESTBENCH IMAGES Najeem Lawal, 201231 VHDL ET062G & ET063G Lecture 5

32 RANGE SENSOR Najeem Lawal, 201232VHDL ET062G & ET063G SRF05 HTTP://WWW.ROBOTSTOREHK.COM/SENSORS/DOC/SRF05TECH.PDF HTTP://WWW.ROBOTSTOREHK.COM/SENSORS/DOC/SRF05TECH.PDF –10us pulse to the Trigger input –50ms period between each Trigger pulse –Mode 1 recommended

33 PROJECT IMPLEMENTATION Najeem Lawal, 201233VHDL ET062G & ET063G CONTROLLER IS FPGA –System Clock and Exposure are generated –Understand timing diagrams and implement the project.

34 SLIDING WINDOW Najeem Lawal, 201234VHDL ET062G & ET063G –An image is read from left to right and top to bottom sliding –Given an algorithm with many tasks O(x,y) = F(x,y) x I(x,y) –Some of the task are neighbourhood oriented sliding window N x M sliding window. N and M are odd numbers

35 SLIDING WINDOW Najeem Lawal, 201235VHDL ET062G & ET063G Suggested implementation architecture 1.linebuffers 2.Boundary controller 3.Pixel switch 4.Filter function 5.Output synchronisation

36 SLIDING WINDOW Najeem Lawal, 201236VHDL ET062G & ET063G –At the image edges –There are invalid pixel –How do you build a valid neighbouthood of pixels around edge pixels? –3 alternatives Avoid processing edge pixels Copy centre pixel to the invalid pixel locations Reflections. Default to 0 or 255


Download ppt "Finite State Machines VHDL ET062G & ET063G Lecture 6 Najeem Lawal 2012."

Similar presentations


Ads by Google