Code FSM Mẫu Verilog HDL

2 832 14
Code FSM Mẫu Verilog HDL

Đang tải... (xem toàn văn)

Thông tin tài liệu

Đây là 2 chương trình FSM mẫu viết bằng ngôn ngữ verilog HDL, sử dụng cho 2 máy: moore và mealy... với các giải thuật và code được viết trong file.... các bạn có thể sử dụng để làm tài liệu ôn tập thi học kì môn ngôn ngữ mô tả phần cứng HDL.

Moore machine – String 1011 Detector module Moore_FSM(x, clk, rst, w); input x, clk, rst; output w; reg w; parameter [2:0] A = 3'b 000, B = 3'b 001, C = 3'b 010, D = 3'b 011, E = 3'b 100; reg [2:0] p_state, n_state; // present and next states, respectively always @(x or p_state) begin: Transitions n_state = A; //Reset state case (p_state) A: if (x == 1'b 1) n_state = else n_state = A; B: if (x == 1'b 1) n_state = else n_state = C; C: if (x == 1'b 1) n_state = else n_state = A; D: if (x == 1'b 1) n_state = else n_state = C; E: if (x == 1'b 1) n_state = else n_state = C; B; B; D; E; B; default: n_state = A; // reset state endcase end always @(x or p_state) begin: Outputing w = 1'b 0; w = (p_state == E); end always @(posedge clk) begin: Registering //Synchronous if (rst) p_state = A; //reset state else p_state = n_state; end endmodule Mealy machine– String 1011 Detector module Mealy_FSM(x, clk, rst, w); input x, clk, rst; output w; reg w; parameter [1:0] A = 2'b 00, B = 2'b 01, C = 2'b 10, D = 2'b 11; reg [1:0] p_state, n_state; // present and next states, respectively always @(x or p_state) begin: Transitions n_state = A; //Reset state case (p_state) A: if (x == 1'b 1) n_state = else n_state = A; B: if (x == 1'b 1) n_state = else n_state = C; C: if (x == 1'b 1) n_state = else n_state = A; D: if (x == 1'b 1) n_state = else n_state = C; B; B; D; B; default: n_state = A; // reset state endcase end always @(x or p_state) begin: Outputing w = 1'b 0; w = (p_state == D)&(x == 1'b 1); end always @(posedge clk) begin: Registering //Synchronous if (rst) p_state = A; //reset state else p_state = n_state; end endmodule ...Mealy machine– String 1011 Detector module Mealy _FSM( x, clk, rst, w); input x, clk, rst; output w; reg w; parameter [1:0] A = 2'b 00, B = 2'b 01,

Ngày đăng: 15/11/2015, 12:40

Tài liệu cùng người dùng

Tài liệu liên quan