Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Verilog case :- unexpected behaviour

Status
Not open for further replies.

otis

Member level 3
Joined
Sep 21, 2010
Messages
60
Helped
4
Reputation
8
Reaction score
3
Trophy points
1,288
Activity points
1,711
I have a following code

Code:
module test(clk,out1,out2)

  input      clk;
  output     out1,out2;
  reg        out1,out2;

  reg [1:0]  next_state;

  parameter [1:0] ONE   = 2'b00,
                  TWO   = 2'b01,
                  THREE = 2'b10,
                  FOUR  = 2'b11;

  paramter  ON  = 0,
            OFF = 1;

  always @ (next_state)
  begin
      out1 <= next_state[ON];
      out2 <= next_state[OFF];

  end

 always @(posedge clk or posedge rst)
 begin
   if (posedge rst)
     next_state <= ONE;
  else
    case (next_state)
      ONE    : next_sate <= TWO;
      TWO    : next_sate <= THREE;
      THREE  : next_sate <= FOUR;
      FOUR   : next_state <= ONE;
    endcase
 end
Above is my simplified version of my current code... Original code exactly the same structure.

control goes to case ONE after reset and next_state gets value TWO. Then I expect that on next clock the next_state will get THREE and so on.

But in my case all assignments happens at same clock edge. I means at same edge next_state updated with ONE,TWO,THREE and FOUR. I found this by adding display comment on every case value.


What is wrong?
 

Hi, I tried your code.

There were a few syntax errors, but after fixing them it appeared to simulate ok. I think it was your reset...

See attached casetest.tar . Pull up the vcd file to see the sim results.

A couple of things:
1) your rst control did not appear to be working properly; see modified test.v; i am guessing you wanted a synchronous active high reset...

2) more importantly, you do not have a default for your case statement; this won't break
simulation, but you may have problems comparing RTL to synthesized gates...always have a default for case statements; my preferred way is have the default to be X so that you can catch missed states easily
 

Attachments

  • casetest.tar
    10 KB · Views: 57
  • Like
Reactions: otis

    otis

    Points: 2
    Helpful Answer Positive Rating
Thanks for your time....Really appreciate that!!!

In my case there was one signal which I used in sensitivity list without initializing... After fixing that one my issue has gone....
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top