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.

counters question to count no of ones in a given data stream

Status
Not open for further replies.

Ekta Rao

Newbie level 1
Joined
Aug 4, 2015
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
8
How to count no of ones in a data stream of 4 bits
 

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,820
Helped
1,811
Reputation
3,632
Reaction score
1,772
Trophy points
1,393
Location
USA
Activity points
59,025
What is up with all the vague questions lately that require clarification?

Do you mean the data stream is made up of nibbles? If so, an adder (accumulator) and a lookup table (i.e. simple ROM conversion to a number of 1's count)


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
always @(posedge clk) begin
  case (nibble)
    4'b0000 : num_1s <= 3'd0;
    4'b0001 : num_1s <= 3'd1;
    4'b0010 : num_1s <= 3'd1;
    4'b0011 : num_1s <= 3'd2;
    4'b0100 : num_1s <= 3'd1;
    4'b0101 : num_1s <= 3'd2;
    4'b0110 : num_1s <= 3'd2;
    4'b0111 : num_1s <= 3'd3;
    4'b1000 : num_1s <= 3'd1;
    4'b1001 : num_1s <= 3'd2;
    4'b1010 : num_1s <= 3'd1;
    4'b1011 : num_1s <= 3'd3;
    4'b1100 : num_1s <= 3'd2;
    4'b1101 : num_1s <= 3'd3;
    4'b1110 : num_1s <= 3'd3;
    4'b1111 : num_1s <= 3'd4;
  endcase
  accum <= init_accum ? 0 : (accum + num_1s);
end

 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
19,707
Helped
4,340
Reputation
8,689
Reaction score
4,303
Trophy points
1,393
Activity points
130,466
Hi,

A counter with reset and enable.
Reset with the start of a new 4 bit frame
Clock it with every bit
Enable when incoming bit is high.

Klaus
 

dpaul

Advanced Member level 4
Joined
Jan 16, 2008
Messages
1,478
Helped
307
Reputation
614
Reaction score
303
Trophy points
1,373
Location
Germany
Activity points
11,065
What is up with all the vague questions lately that require clarification?

I think a sticky note is needed which can contain explanations regarding
1> How to ask question related to h/w design & its implementation, what things need to be included in the Qs for others to better and quickly understand the scenario.
2> Many a times members ask Qs such as what is the command for this and that without searching the corresponding user or command ref manuals (mostly newbies don't even know such things exist). So a description can be included regarding the likely place to be searched for such documents.
3> some other newbie Q scenario, which often gets repeated (doesn't come to my mind right now).

Last but not the least come up with a method to enforce new members to read such a sticky thread before posting the first time.

I am only talking about the forums related to digital hardware design. I have no idea about the situation in other sub-forums.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top