The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Jul 16th, 2024, 4:23pm
Pages: 1
Send Topic Print
How to break in a "case ...endcase" statement ?? (Read 5124 times)
ZaraCattle
New Member
*
Offline



Posts: 7

How to break in a "case ...endcase" statement ??
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...
Back to top
 
 
View Profile   IP Logged
Saran
Junior Member
**
Offline

Getting wiser by the
second

Posts: 10

Re: How to break in a "case ...endcase" statement
Reply #1 - Apr 25th, 2007, 8:15am
 
Please spell out this problem more clearly...Thanks!
Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1999
Massachusetts, USA
Re: How to break in a "case ...endcase" statement
Reply #2 - 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.
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
ZaraCattle
New Member
*
Offline



Posts: 7

Re: How to break in a "case ...endcase" statement
Reply #3 - 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....
Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1999
Massachusetts, USA
Re: How to break in a "case ...endcase" statement
Reply #4 - 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})
...
 

Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
ZaraCattle
New Member
*
Offline



Posts: 7

Re: How to break in a "case ...endcase" statement
Reply #5 - 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....
Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1999
Massachusetts, USA
Re: How to break in a "case ...endcase" statement
Reply #6 - 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.
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.