The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Design Languages >> Verilog-AMS >> How to break in a "case ...endcase" statement ??
https://designers-guide.org/forum/YaBB.pl?num=1177111617

Message started by ZaraCattle on Apr 20th, 2007, 4:26pm

Title: How to break in a "case ...endcase" statement ??
Post by ZaraCattle on Apr 20th, 2007, 4:26pm

I'm using "always" block.In this block I use "begin ...and   " and 2 "case ...endcase"..I don't know how to my program only can excute one of  2 "case ...endcase" everytime I excute this block....I mean when I excute a above "case...endcase",then it still excutes a under "case...endcase"...Please help me.....Thanks everybody very much...

Title: Re: How to break in a "case ...endcase" statement
Post by Saran on Apr 25th, 2007, 8:15am

Please spell out this problem more clearly...Thanks!

Title: Re: How to break in a "case ...endcase" statement
Post by Geoffrey_Coram on Apr 25th, 2007, 10:49am

You probably want:

Code:
case (var)
 1 :  $display(" got a 1");
 2 : begin
     $display (" got a 2");
     var = 1;
   end
 default $strobe("got something else");
endcase


I think you probably mis-understood the syntax for case/endcase.

Title: Re: How to break in a "case ...endcase" statement
Post by ZaraCattle on Apr 27th, 2007, 1:32am

This is my code

Code:
`timescale 1 ns / 1 ps

module IC74LS160 (Pin_Pe,Pin_P0,Pin_P1,Pin_P2,Pin_P3,Pin_Cep,Pin_Cet,Pin_Reset,Pin_Q0,Pin_Q1,Pin_Q2,Pin_Q3,Pin_Tc,Pin_Clk);
input Pin_Pe,Pin_Cep,Pin_Cet,Pin_Reset,Pin_P0,Pin_P1,Pin_P2,Pin_P3,Pin_Clk;
output Pin_Q0,Pin_Q1,Pin_Q2,Pin_Q3,Pin_Tc;
reg Pin_Q0,Pin_Q1,Pin_Q2,Pin_Q3;
reg [3:0]dem;
initial            
  dem = 0;        
 
always @(posedge Pin_Clk)
begin  
   casex ({Pin_Reset,Pin_Pe,Pin_Cet,Pin_Cep})      
     //Neu Chan Reset khong tich cuc va chan PE tich cuc thi load cac gia tri hien tai cua chan Pi vao chan Qi
  4'b10xx:
     begin
       Pin_Q0 = Pin_P0;
     Pin_Q1 = Pin_P1;
     Pin_Q2 = Pin_P2;
     Pin_Q3 = Pin_P3;  
       dem[0] = Pin_Q0;
       dem[1] = Pin_Q1;
       dem[2] = Pin_Q2;
       dem[3] = Pin_Q3;
   end            
//Neu Binh thuong thi dem binh thuong
4'b1111:
begin
if (dem <9)
     begin
    dem = dem + 1;
    Pin_Q0 = dem[0];
    Pin_Q1 = dem[1];
    Pin_Q2 = dem[2];
    Pin_Q3 = dem[3];  
   end      
     end
     //Neu Chan Reset tich cuc
     4'b0xxx:
     begin
      dem = 0;
     Pin_Q0 = 1'b0;
     Pin_Q1 = 1'b0;
     Pin_Q2 = 1'b0;
     Pin_Q3 = 1'b0;
   end      
endcase



//I don't want to excute second "case ...endcase " statement
//when the program excuted first "case ...endcase" statement
//I want the program will exit out of "Always" block  
//when the program excuted first "case...endcase" statement  




case({Pin_Q0,Pin_Q1,Pin_Q2,Pin_Q3})
     //Neu Dem den 9 thi tro ve 0 trong xung ke
        4'b1001:
        begin
          dem = 0;
        Pin_Q0 = 1'b0;
          Pin_Q1 = 1'b0;
          Pin_Q2 = 1'b0;
        Pin_Q3 = 1'b0;
     
      end
//Neu ban dau o 11 thi tro ve 6 trong xung ke
      4'b1101:
      begin
          dem = 6;
            Pin_Q0 = 1'b0;
            Pin_Q1 = 1'b1;
            Pin_Q2 = 1'b1;
            Pin_Q0 = 1'b0;
     
      end
//Neu ban dau o 13 thi tro ve 4 trong xung ke
      4'b1011:
      begin
        dem = 4;
        Pin_Q0 = 1'b0;
        Pin_Q1 = 1'b0;      
        Pin_Q2 = 1'b1;
        Pin_Q3 = 1'b0;
           
      end
//Neu bat dau o 15 thi tro ve 2 trong xung ke
      4'b1111:
      begin
        dem = 2;
        Pin_Q0 = 1'b0;
        Pin_Q1 = 1'b1;
        Pin_Q2 = 1'b0;
        Pin_Q3 = 1'b0;
     
      end
//Neu ban dau o 10 thi nhay len 11 trong xung ke
      4'b0101:
          begin
        Pin_Q0 = 1'b1;
        Pin_Q1 = 1'b1;
        Pin_Q2 = 1'b0;
        Pin_Q3 = 1'b1;
      end
//Neu ban dau la 12 thi nhay len 13 trong xung ke
      4'b0011:
      begin
        Pin_Q0 = 1'b1;
        Pin_Q1 = 1'b0;
        Pin_Q2 = 1'b1;
        Pin_Q3 = 1'b1;
      end
//Neu ban dau la 14 thi nhay len 15 trong xung ke  
          4'b0111:
      begin
        Pin_Q0 = 1'b1;
        Pin_Q1 = 1'b1;
        Pin_Q2 = 1'b1;
        Pin_Q3 = 1'b1;  
      end
endcase
end
endmodule

Thanks for your helping....

Title: Re: How to break in a "case ...endcase" statement
Post by Geoffrey_Coram on Apr 27th, 2007, 3:52am

You could do something like:


Code:
integer done;

always @(posedge Pin_Clk)
begin
 done = 0;
 casex ({Pin_Reset,Pin_Pe,Pin_Cet,Pin_Cep})
   4'b10xx:
     begin
       done = 1
...
 if (done == 0) begin
   case({Pin_Q0,Pin_Q1,Pin_Q2,Pin_Q3})
...

Title: Re: How to break in a "case ...endcase" statement
Post by ZaraCattle on Apr 27th, 2007, 7:47am

Thanks you Geoffrey-Coram.. I thought this way to solve my problem...I only want to know another way that is easier to solve my problem...It's like "break" or "exit" in C..Thanks for your ideas....

Title: Re: How to break in a "case ...endcase" statement
Post by Geoffrey_Coram on Apr 30th, 2007, 4:21am

It's not like break in C, because there's no enclosing loop to "break" out of, and even if there were, the "break" would apply to the case statement (the innermost construct).  In a very contorted way, it might be like "continue" if you considered the simulator's timestep control loop as the enclosing loop (while time < end_time) or "return" if you considered the module execution as some sort of function.

The Designer's Guide Community Forum » Powered by YaBB 2.2.2!
YaBB © 2000-2008. All Rights Reserved.