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 coding problem.

Status
Not open for further replies.

priyanka24

Advanced Member level 4
Joined
Jan 19, 2011
Messages
100
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
India
Activity points
1,976
Hi..

i want to calculate run length from the binary sequence.
for example if my number is '0001' then my run length is 3.
suppose my number is '1' then my run length is 0.
suppose my run length is '00110001' then my run lengths are 2, 0, 3.
so for that i have written verilog code as follows:


module runcount(i, o);
input [7:0] i;
output [3:0]o;
reg [3:0]o;
integer count=0;
integer j=0;

initial o=4'b0000;
always@(i)
begin
for(j=7;j>=0;j=j-1)
begin
if(i[j]==0)
begin
o=count+1;
end
else if(i[j]==1)
begin
o=count;
count=0;
end
end
end
endmodule


but my output is always zero. so can anyone tell whats the problem???
 

Problem is for loop will give you end result only. It wont give intermediate results.
You need to try some other way to get the results.
example you can try FSM to track no of zero's for this.
There may be some better way to implement this
 
Problem is for loop will give you end result only. It wont give intermediate results.
You need to try some other way to get the results.
example you can try FSM to track no of zero's for this.
There may be some better way to implement this

can u tell me any ways to implement it because am new in this...i have tried same code with case statement also but in that program also output is always zero. can any ways you know.
 

simple way to do it is make output an array

module runcount(i, o);
input [7:0] i;
output reg [3:0]o[7:0];
integer count=0;
integer j=0;
integer k=o;
initial o=4'b0000;
always@(i)
begin
for(j=7;j>=0;j=j-1)
begin
if(i[j]==0)
begin
o=count+1;
end
else if(i[j]==1)
begin
o[k]=count;
k=k+1;
count=0;
end
end
end
endmodule
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top