Forum Discussion
Altera_Forum
Honored Contributor
12 years agoTo count how many '1's ( or '0's ) you may design a majority circuit. This code:
jurado1: process (t1) variable m1 : unsigned (2 downto 0); begin m1:=TO_UNSIGNED(0,3); for i in 0 to 3 loop if (t1(i) = '1') then m1:=m1+1; end if; end loop; count <= m1; end process jurado1; count will have the numbers of '1's on vector t1 ( 4 bits ). I don't know how many '1's do want count. For a greater number of switch a sequential counter will be easier. Of course you have to decode bcd number on count, to 7 segment code. If you count more than 9 '1's you'll need 2 digits, so you need a bin to bcd converter.