Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #30

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Sequence_Detect_FSM/MealyFSM_RTL.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions Sequence_Detect_FSM/Mealy_FSM.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 10/19/2024 02:59:03 AM
// Design Name: Mealy FSM
// Module Name: Mealy_FSM
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////


module Mealy_FSM (
input logic clk, rst, in,
output logic out
);

typedef enum logic [1:0] {
s0 = 2'b00,
s1 = 2'b01,
s2 = 2'b10
} state_s;

state_s c_state, n_state;

always_ff @(posedge clk or negedge rst) begin
if (!rst) begin
c_state <= s0;
end else begin
c_state <= n_state;
end
end

always_comb begin
case (c_state)
s0: begin
if (in == 0) begin
n_state = s1;
end else if (in == 1) begin
n_state = s2;
out = 1'b0;
end
end

s1: begin
if (in == 0) begin
n_state = s1;
end else if (in == 1) begin
n_state = s2;
out = 1'b1;
end
end

s2: begin
if (in == 1) begin
n_state = s2;
end else if (in == 0) begin
n_state = s1;
out = 1'b1;
end
end

default: n_state = s0;
endcase
end

endmodule

52 changes: 52 additions & 0 deletions Sequence_Detect_FSM/Mealy_FSM_tb.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 10/19/2024 04:10:05 AM
// Design Name:
// Module Name: Mealy_FSM_tb
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////


module Mealy_FSM_tb;
reg clk, rst, in;
wire out;

Mealy_FSM dut1(.clk(clk), .rst(rst), .in(in), .out(out));

initial begin
clk = 0;
forever #5 clk = ~clk;
end

initial begin
rst = 0;
in = 0;
#10 rst = 1;

in = 0; #10 //sequence 010
in = 1; #10
in = 0; #10

in = 0; #10 // Delay before sequence 101

in = 1; #10 //sequence 101
in = 0; #10
in = 1; #10

#10 $finish;
end
endmodule