Simple counter

Hi,

I 'm trying to count the number of '1' in a std_logic_vector of 64 bits. In fact, I want ot know if there are more '1' or '0'.

I want to use 10 slices(MAX). So I write the following line

SUM = IN(0)+IN(1)+..+IN(63);

These is a error with the compilatot, so I try :

SUM = '0'&IN(0) + '0'&IN(1) + .. + '0'&IN(63);

no error with the compilator, but result(SUM) is false.

thank for your help

Cedric

Reply to
cedric
Loading thread data ...

try with SUM = '00000'&IN(0) + '000000''&IN(1) + .. + '000000''&IN(63); because the max value will be 64 so it needs a result on 7 bits. or try to declare sum as an integer ranged betwen 0 and 64 and convert element of IN signal in integer

alexis

"cedric" a écrit dans le message de news: snipped-for-privacy@posting.google.com...

Reply to
KCL

If you care about delay, you want a carry save adder tree, though I don't know if it will synthesize it from a sum of bits.

I believe it is also close to the minimum number of slices.

A full adder will add three bits and provide a two bit sum.

21 full adders, given 63 inputs, will provide 21 bits of place value 1 and 21 bits of place value 2, plus the 64th bit.

The next level combines the 1's and 2's using more full adders, generating place values of 1, 2, and 4.

Continue until you have only one of each place value.

It might be that you don't need all the logic to only detect more '1' or '0', but you will need it all to test for '1' and '0' being equal.

-- glen

P.S. If this is homework, reference the newsgroup. Your instructor probably reads it, too.

Reply to
glen herrmannsfeldt

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.