Question

In: Electrical Engineering

can i ask FSM verilog? ---------------------- module FSM(clk, rst, choice, out); input clk, rst, choice; output...

can i ask FSM verilog?

----------------------

module FSM(clk, rst, choice, out);

input clk, rst, choice; output reg [1:0] out;

reg [1:0] state, nextstate;
parameter [1:0] S0 = 2’b00, S1 = 2’b01,

S2 = 2’b10, S3 = 2’b11;

always@(posedge clk) begin

if (rst == 1’b0) begin

state <= S0;

end else

end state <= nextstate;

always@(state, rst, choice) begin

case (state) S0 : begin

out = 2’b00;

if (rst == 1’b1) nextstate <= S1; end

S1 : begin
out = 2’b01;
if (choice == 1’b1) nextstate <= S2; else nextstate <= S3;

end

S2 : begin
out = 2’b10;
if (rst == 1’b1) nextstate <= S0;

end

S3 : begin
out = 2’b11;
if (rst == 1’b1) nextstate <= S0;

end endcase

end endmodule

---------------

Q) i knew this kind of fsm verilog code contain sequen, comb logic

how can i rewrite that code with seq + comb+ output logic?

Solutions

Expert Solution

// Code your design here
module FSM(clk, rst, choice, out);
input clk, rst, choice;
output reg [1:0] out;

reg [1:0] state, nextstate;
parameter [1:0] S0=0, S1 =1,S2 =2, S3 =3;
  
// reset block sequntial block for state transition

always@(posedge clk)
begin
if(!rst)
begin
state <= S0;
end
else
state <= nextstate;
end
  
// block combinational for next state determination
always@(state, rst, choice)
begin
case (state)
S0 :
begin
  
if (rst) nextstate <= S1;
end
S1 :
begin
  
if (choice) nextstate <= S2; else nextstate <= S3;
end
S2 :
begin
  
if (rst) nextstate <= S0;
end
S3 : begin
  
if (rst) nextstate <= S0;
end
endcase
end
  
  
// output block combinational
always@(state)
begin
case (state)
S0 :
begin
out =0;
end
S1 :
begin
out =1;
end
S2 :
begin
out = 2;
  
end
S3 : begin
out = 3;
end
endcase
end
endmodule

note: the code that you have written is also divided into two parts

the reset part with posedge clock will work as sequential block.

since.

FSM has two combinational of blocks.

1 combination block for Flip flop excitation

second for output.

the sequential block will just take the outputs of the combination excitation block and just buffer it to output according to sequential logic.


Related Solutions

module traffic(clk, reset, P1, P2, P3, P4, PL); input clk; input reset; output[4:0] P1; output[4:0] P2;...
module traffic(clk, reset, P1, P2, P3, P4, PL); input clk; input reset; output[4:0] P1; output[4:0] P2; output[4:0] P3; // four roads output [4:0] P4; output[3:0] PL; //Pl is pedestrian reg [4:0] P1; reg [4:0] P2; reg [4:0] P3; reg [4:0] P4; reg [3:0] PL; reg [4:0] sig; always @(posedge clk or negedge reset) begin    if(reset == 1'b0)begin        P1 <= 5'b00100;        P2 <= 5'b00100;        P3 <= 5'b00100;        P4 <= 5'b00100;       ...
create a test bench for the following code: module signed_mult (out, clk, a, b); output [15:0]...
create a test bench for the following code: module signed_mult (out, clk, a, b); output [15:0] out; input clk; input signed [7:0] a; input signed [7:0] b; reg signed [7:0] a_reg; reg signed [7:0] b_reg; reg signed [15:0] out; wire signed [15:0] mult_out; assign mult_out = a_reg * b_reg; always@(posedge clk) begin a_reg <= a; b_reg <= b; out <=mult_out; end endmodule
module traffic(a, b,clk, reset, P1, P2, PL1, PL2, ind); input a,b; input clk; //g=100 y=010 r=001...
module traffic(a, b,clk, reset, P1, P2, PL1, PL2, ind); input a,b; input clk; //g=100 y=010 r=001 input reset; //g for pedes = 000 red = 111 input ind; output[2:0] P1; output[2:0] P2; // two roads output[1:0] PL1; //Pl is pedestrian output[1:0] PL2; reg [2:0] P1; reg [2:0] P2; reg [1:0] PL1; reg [1:0] PL2; reg [2:0] sig; always @(posedge clk, posedge reset) if(reset) begin P1 <= 3'b100; P2 <= 3'b001; PL1 <= 3'b111; PL2 <= 3'b000; end else begin //...
1. Write Verilog code and test bench for Moore FSM having a single input line ‘X’...
1. Write Verilog code and test bench for Moore FSM having a single input line ‘X’ and a single output-line ’Z’. An output of 1 is to be produced coincident with the pattern 1101 and an output of ‘ 0’ is to be produced for all the other sequences and simulate it.
I/O Lab Java Purpose To practice the input and output concepts discussed in this module. Specifically,...
I/O Lab Java Purpose To practice the input and output concepts discussed in this module. Specifically, reading from and writing to local files, and formatting output. Instructions Read in file input.csv and generate a cleanly formatted table in output.txt. See the samples below. input.csv name,ID,salary,years experience foo,1,13890,12 bar,2,2342,3 baz,3,99999,24 output.txt Name | ID | Salary | Years experience -----+----+--------+----------------- Foo | 1 | 13890 | 12 Bar | 2 | 2342 | 3 Baz | 3 | 99999 | 24
Derive a state diagram and table for a single-input and single-output Moore-type FSM that produces an...
Derive a state diagram and table for a single-input and single-output Moore-type FSM that produces an output of 1 if an input sequence of 101 is detected
Analyze the following Verilog code and write down its output as pictured in the code. module...
Analyze the following Verilog code and write down its output as pictured in the code. module blocking; reg [0:7] A, B; initial begin: init1 A = last decimal digit of your ID; #1 A = A + 1; // blocking procedural assignment B = A + 1; $display("Output 1: A= %b B= %b", A, B ); A = last decimal digit of your ID; #1 A <= A + 1; B <= A + 1; #1 $display ("Output 2: A=...
Create the Parser module in System Verilog to convert the 8-bit Button Board input into four...
Create the Parser module in System Verilog to convert the 8-bit Button Board input into four 4-bit Binary Coded Decimal numbers. The parser should read in an 8-bit Button Board input as an 8-bit number (0-255). Parse that 8-bit number into four 4-bit numbers (0-9) representing its ones, tens, hundreds, and thousands digit.
Write a Verilog HDL module that has three inputs, A, B, C, and one output, Y,...
Write a Verilog HDL module that has three inputs, A, B, C, and one output, Y, to implement a function that Y output is true if at least two of the inputs are false Also, write a testbench for the function.
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT