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 code error I can't define!

Status
Not open for further replies.

billkas

Newbie level 3
Joined
Jun 18, 2012
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,306
Hello everyone!

I'm a noob in Verilog and I've written this module:

Code:
module databus_send(data_out, signature, data_send, data_last);

	output [31:0] data_out;
	output signature;
	
	input [31:0] data_send;
	input [31:0] data_last;
	
	integer i, count;
	
	assign count = 0;
	
	//hamming distance detector
	for (i=0;i<32;i=i+1)
		begin
			if data_send[i]^data_last[i]==1 
				count = count + 1;
		end
	end
	if count > 16
		begin
			signature = 0;
		end
	else
		begin
			signature = 1;
		end
	end
	
	data_out = data_send;
	data_last = data_send;
	
endmodule

What I get is: v(16): Error [...] near "for": syntax error
As far as I can tell, my for loop syntax is ok, what's going on?

Sorry if this post is in the wrong category. I would really appreciate your help!
Thank you! :wink:
 

You have too many "end". Try

for (i=0;i<32;i=i+1) begin
if (data_send^data_last==1)
count = count + 1;
end

in verilog each "end" must be linked to a "begin" I see that the rest of your code have too many "end" statements


if count > 16
signature = 0;
else
signature = 1;

This should do the work. You dont need the "Begin" statement when your "if" only have one line.

If you had written something like the following code you must write both "begin" and "end"

if (count > 16) begin
signature = 0;
signature1=0;
end
else begin
signature = 1;
signature1 = 1;
end

Also, always use the () when you use the : if,case...

Hope it help
 
Last edited:
Thank you for the answer! I did exactly what you suggested, but still it won't compile :/
 

The coding style is wrong. Don't use this kind of "FOR" loop and you cannot synthesize.
Better change the logic and then try. With the combination of XOR gate and a counter you can achieve this..
 

For loop is synthesizable only.
for loop, if statements should be within always block.
put "count" also inside always block.
without using assign.
Do this changes along with what "FboDigit" suggested.
 

Thank you very much for your answers, I've found out what the mistake was! I'll post the right one asap!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top