Verilog - Separating bits for case statement

Thread Starter

tquiva

Joined Oct 19, 2010
176
My goal is to connect two modules together: RfileReceiver and RegFile
I did this by implementing a top level module to create instances for these modules. Below is a block diagram of the two modules.



The arrow pointing into RfileReceiver is a 7-bit output called "link" coming from another module. Below is the description of link's bits:

link[6]: starting bit
link[5] & link[4]: address
link[3],link[2],link[1],link[0]: data

I have the verilog code for modules RegFile and toplevel. My only question here is, how would I go about seperating the bits of the link input into RfileReceiver to accomplish the above description?

My idea right now is using a case statement. However, I do not know how to represent the particular bits for a given case. For instance, if link = 1011100, I would have:

case(link)
begin
link[5] & link[4]: address
link[3],link[2],link[1],link[0]: data
endcase

I tried googling for the correct Verilog syntax to represent the pseudocode above, but I can't seem to find a solution. Will someone please help me?
 

Attachments

panic mode

Joined Oct 10, 2011
2,753
logic start_bit;
logic [1:0] address;
logic [3:0] data;

assign start_bit=link[6];
assign address=link[5:4];
assign data=link[3:0];
 

Thread Starter

tquiva

Joined Oct 19, 2010
176
logic start_bit;
logic [1:0] address;
logic [3:0] data;

assign start_bit=link[6];
assign address=link[5:4];
assign data=link[3:0];
Thank you so much!

Will someone please take a look at my code? Please let me know if I am missing anything. I'm still kind of new to Verilog.

Rich (BB code):
// Let RfileReceiver = A and RegFile = B

// Register file that has four 4-bit registers


module RegFile(rfdata,clock,waddr,rfaddr,wdata,write);

output [3:0] rfdata;  // read data
input clock;
input [1:0] waddrB;  // write address
input [1:0] rfaddrB; // read address
input [3:0] wdataB;  // write data
input writeB;        // write enable


reg [3:0] regcell[0:3]; // Register array that's 4-bits wide

assign rfdata = regcell[rfaddrB]; // Output read data

always @(posedge clock)  // Write to the register file
   if (writeB==1) regcell[waddrB]=wdataB;


endmodule



//-------------------------------------------------------------------------

// RfileReceiver circuit
// Assignment is to design this module.  

module RfileReceiver(waddr,wdata,write,clock,link,clear);

output [1:0] waddrA; // used to control register file
output [3:0] wdataA; // used to tranfer data to register file
output writeA;	    // write enable to register file
input  clock;
input  link;	    // input from serial link from transmitter
input  clear;

assign waddrA = link[5:4];
assign wdataA = link[3:0];

always @(posedge clock)
	if (clear != 0) writeA <= 1; 

endmodule

// Top level module to create instances for RfileReceiver and RegFile 
// This will connect outputs of RfileReceiver to inputs of RegFile
module toplevel;

wire waddrA_waddrB; // Wire from waddrA to waddrB
wire wdataA_wdataB; // wire from wdataA to wdataB
wire writeA_writeB; // wire from writeA to writeB

RfileReceiver Rfilereceiver_instance(
	.waddrA(waddrA_waddrB),
	.wdataA(wdataA_wdataB),
	.writeA(writeA_writeB)
	);
	
RegFile RegFile_instance(
	.waddrB(waddrA_waddrB),
	.wdataB(wdataA_wdataB),
	.writeB(writeA_writeB)
	);
	
endmodule
 

panic mode

Joined Oct 10, 2011
2,753
first of all what language version you use? verilog-1995, verilog-2001 or SystemVerilog-2005? they are different, I only used SystemVerilog-2005 so your syntax looks odd to me.

did you try to compile it? what kind of errors do you get?

the way i see it, your module declaration is incorrect so this probably cannot compile.

also your code does not match signals in the block diagram. in the diagram you have one input whcih is not labeled (presumably 'link') and three outputs: 'waddr', 'wdata', 'write'. your code however seem to use bunch of inputs and only output is rfdata. for me this alone is good enough reason to not even look any further, as this need to be addressed frst.
 
Last edited:
Top