forast
Junior Member level 3
- Joined
- Mar 10, 2014
- Messages
- 25
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 3
- Activity points
- 216
I'm suppose to do a finite state machine and I'm still fairly new with verilog so if anyone can look over my code to see why it's not working correctly that'll be great. I have my test bench already and it seems to be working correctly but the outputs are all wrong. It doesn't seem to output where z=1. I'm pretty sure I did something wrong in the FF_function or OG_function with the if else but I'm not sure how I would go about fixing it. Any help is appreciated. :grin:
Also I should mention I get a few warnings but everything still runs, most of the warnings are in FSM module.
Also I should mention I get a few warnings but everything still runs, most of the warnings are in FSM module.
Code:
module NSG_function
(
input x,
input [1:0] q, // current_state,
output [1:0] d // next_state
);
assign d[1] = ~x&q[0]&q[1] | x&~q[0]&q[1] | x&q[0]&~q[1];
assign d[0] = ~x | ~q[0]&q[1];
endmodule
Code:
module FF_function
(
input clock, reset, next_state,
output reg current_state
);
always@(posedge clock, posedge reset)
begin
if (reset == 1)
current_state <= 3'b000;
else
current_state <= next_state;
end
endmodule
Code:
module OG_function
(
input current_state,
output reg z
);
always@(*)
begin
if(current_state == 3'b100)
z = 1;
else
z = 0;
end
endmodule
Code:
`include "NSG_function.v"
`include "OG_function.v"
`include "FF_function.v"
module FSM
(
input x, clock, reset,
output z
);
wire [2:0] current_state;
wire [2:0] next_state;
NSG_function nsg1(x, q, d);
OG_function og1(current_state, z);
FF_function ff1(clock, reset, next_state, current_state);
endmodule
Last edited: