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.

problem with the counter

Status
Not open for further replies.

QMA

Member level 4
Joined
Apr 5, 2007
Messages
72
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,832
dear all
I have designed following code in verilog using Xilinx and it is not giving me the results. i have a 16 bit vector bit_s_row. i want to calculate 1's from index i = 0 up to the index B_addr. Please help me in resolving the issue.
Code:
   if(i<B_addr)
	begin 
	   if(bits_s_row[i]==1)
		  pop_count = pop_count +1'b1;
	   else
	          pop_count = pop_count;
	          i=i+1;
	 end
 
Last edited by a moderator:

aminpix

Member level 3
Joined
Sep 30, 2008
Messages
54
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,773
You should'n't use IF command. may be you wanted to type FOR instead, but I am not sure in real implemention you can have for or not.
if it is only for simulation, instead of the first IF use "FOR":
Code:
for (i = 0; i < B_addr; i = i +1) 
begin
if(bits_s_row[i]==1)
pop_count = pop_count +1'b1;
else
pop_count = pop_count;
i=i+1;
end
 
Last edited by a moderator:

aruipksni

Full Member level 6
Joined
May 23, 2013
Messages
346
Helped
68
Reputation
136
Reaction score
66
Trophy points
1,308
Activity points
3,004
your code is to ambigious for hdl design.
you dont know what the syntisizer will make out of it.

for wloop orks in hdl only on constant range value.

to implement this you will need to do for on full range - 16.

the basic idea is to code or convert indexes to numbers.
for example bits_s_row will now have 4 extra bits indicate index number

so to do everthing in parallel
you will need 16 comperators to compare index number to b_addr.
this will give you a masking bit vector.
and then you will need to sum all this numbers - depends how you do sum.
 
  • Like
Reactions: QMA

    QMA

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top