Plz help it is not giving correct output it is showing in count 3'hX

OP (Company: UET) #2627403
Rate this post
• ▲ useful
▼ not useful
module Up_Down(count, up_dwn, clock, reset_);
output [2:0] count;
input [1:0] up_dwn;
input clock, reset_;
reg [2:0] count;

reg [2:0] state, next_state;
parameter state_idle=3'b000, state_inc=3'b010, state_dec=3'b100;

always@ (posedge clock or posedge reset_ )
if(reset_) state<=state_idle;
else state<=next_state;

always @ (state or up_dwn)
begin next_state=state;
case(state)
state_idle:
begin
//if(up_dwn==2'b00 || up_dwn==2'b11)

if(up_dwn==2'b01)
begin
count<=count+1;
next_state=state_inc;
end
else if(up_dwn==2'b10)
begin
count<=count-1;
next_state=state_dec;
end
else
next_state= state_idle;
end


state_inc:
begin

if(up_dwn==2'b01)
begin
count<=count+1;
next_state=state_inc;
end
else if(up_dwn==2'b10)
begin
count<=count-1;
next_state=state_dec;
end
else
next_state= state_idle;

end

state_dec:
begin
if(up_dwn==2'b01)
begin
count<=count+1;
next_state=state_inc;
end
else if(up_dwn==2'b10)
begin
count<=count-1;
next_state=state_dec;
end
else
next_state= state_idle;
end
endcase
end

endmodule

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.