Skip to main content

Product Engineer II at Cadence Design Systems

Hello Dear Readers, Cadence Design Systems has a vacancy for a Product Engineer II role. Cadence is a pivotal leader in electronic design, building upon more than 30 years of computational software expertise. The company applies its underlying Intelligent System Design strategy to deliver software, hardware and IP that turn design concepts into reality.  Cadence customers are the world’s most innovative companies, delivering extraordinary electronic products from chips to boards to systems for the most dynamic market applications including consumer, hyperscale computing, 5G communications, automotive, aerospace industrial and health. The Cadence Advantage: The opportunity to work on cutting-edge technology in an environment that encourages you to be creative, innovative, and to make an impact. Cadence’s employee-friendly policies focus on the physical and mental well-being of employees, career development, providing opportunities for learning, and celebrating success in recog...

Different types of Counters In Verilog HDL

 Hello Dear Readers,

Today, I will explain Designing of the different types of counters. There are two types of counter based on the how clock signal is assigned to it namely 1). Synchronous Counters 2). Asynchronous Counter. 

1). Synchronous Counters:

If all the storage elements are triggered by the same source clock signal then the design is said to be synchronous. The advantage of the synchronous design is the overall propagation delay for the design is equal to the propagation delay of the flip-flop or storage element. STA is very easy for the synchronous logic and even performance improvement is possible by using the pipelining. Most of the ASIC implementation uses synchronous logic. In practical applications counters are used as a clock divider network. Even counters are used in the frequency synthesizers to generate variable frequency outputs.

i) Parameterized N Bit Up Counter:

Counters are used to generate the predefined and required count sequence on the active edge of the clock. In ASIC design it is essential to write an efficient RTL code for the counter by using the synthesizable constructs. The N-bit-up counter is described by using Verilog to generate the synthesizable design. Here I have design every RTL is parameterized so we can modify it for any number of bits.

Verilog Code:

module counters #(parameter N=3)(data_in,load_en,rst,clk,q_out);

input [N-1:0] data_in;

input load_en,clk,rst;

output reg [N-1:0] q_out;

always@(posedge clk or negedge rst)

begin

 if(~rst)

 q_out <= 3'b0;

 else if(load_en)

 q_out <= data_in;

 else

 q_out <= q_out+1'b1;

 end

endmodule


In the above code, the procedural block is sensitive to the clock(clk) and reset(rst) signal. Here for reset 'rst=0' is assign 3'b000 to the q_out. So it is called asynchronous reset and it has the highest priority over any other input. Similarly, if you want to design a down counter as shown below.

Verilog Code:

module counters #(parameter N=3)(data_in,load_en,rst,clk,q_out);

input [N-1:0] data_in;

input load_en,clk,rst;

output reg [N-1:0] q_out;

always@(posedge clk or negedge rst)

begin

 if(~rst)

 q_out <= 3'b0;

 else if(load_en)

 q_out <= data_in;

 else

 q_out <= q_out-1'b1;

 end

endmodule

Now if we want to design a Common Up-Down counter based on signal value let's say one-bit 'up_down' signal if its value '1' counter work as an up counter and if the value is '0' then it works as a down counter. Synthesized RTL Verilog is shown below.

Verilog Code:

module counters #(parameter N=3)(data_in,load_en,rst,clk,up_down,q_out);

input [N-1:0] data_in;

input load_en,clk,rst,up_down;

output reg [N-1:0] q_out;

always@(posedge clk or negedge rst)

begin

 if(~rst)

 q_out <= 3'b0;

 else if(load_en)

 q_out <= data_in;

 else

 begin

 if(up_down)

 q_out <= q_out+1'b1;

 else

 q_out <= q_out-1'b1;

 end

end

endmodule

(ii) Gray Counters:

Gray Counters is another example of a synchronous counter. Gray counters are used in the multiple clock domain designs as only one-bit changes on the active clock edge. Gray codes are used in the synchronizers. The Gray counter is described below. In which first we increment input data as binary counter and then using code converter algorithms final output is Gray counter which is represented by 'q_out'.

Verilog Code:

module counters #(parameter N=4)(data_in,load_en,rst,clk,up_down,q_out);

input [N-1:0] data_in;

input load_en,clk,rst,up_down;

output reg [N-1:0] q_out;

reg q2,q1,q0;

reg [N-1:0] count;

always@(posedge clk)

begin

 if(rst) begin

 q_out <= 4'b0;

 {q2,q1,q0}<=3'b0;

 count<=4'b0;

 q_out<=4'b0;

 end

 else if(load_en) begin

 count <= data_in;

 {q2,q1,q0}<={data_in[2],data_in[1],data_in[0]};

 q_out<={data_in[3],data_in[2],data_in[1],data_in[0]};

 end

 else

 begin

 count<= count+1'b1;

 q2<=count[3]^count[2];

 q1<=count[2]^count[1];

 q0<=count[1]^count[0];

 q_out<={count[3],q2,q1,q0};

 end

end

endmodule

(iii) Ring Counters:

Ring Counters is a synchronous counter where the sequence is repeated after few clock cycles. Ring Counters are used in practical applications to provide the predefined delay. These counters are synchronous in nature and used in practical applications like traffic light controller, timers to introduce the certain amount of predefined delay. The internal logic structure using the D flip-flops for the four-bit ring counter is shown in Fig.1, as shown the output of MSB flip-flop is fed back to the LSB flip-flop input, and the counter shifts the data on every active edge of clock signal.

Fig. 1

Verilog Code:

module counters #(parameter N=4)(set_in,clk,q_out);

input set_in;

input clk;

output reg [N-1:0] q_out;

always@(posedge clk)

 if(set_in)

 begin

 q_out<=4'b1000;

 end

 else

 begin

 q_out<=q_out<<1; // describe functionality that MSB is                           feedback to the LSB

 q_out[0]<=q_out[3];

 end

end

endmodule

(iv) Johnson Counters:

Johnson Counter is a special type of synchronous counter and designed by using the shift register. The internal structure for the three-bit Johnson counter is shown in Fig.2. The Verilog RTL for the four-bit Johnson counter is shown below.

Fig.2

Verilog Code:

module counters #(parameter N=4)(rst,clk,q_out);

input rst;

input clk;

output reg [N-1:0] q_out;

always@(posedge clk or negedge rst)

begin 

 if(~rst)

 q_out<=4'b0;

 else

 q_out<={{q_out[2:0]},{~q_out[3]}};

end

endmodule 


2). Asynchronous Counters:

In the asynchronous counters, the clock signal is not driven by the common clock source. If the output of the LSB flip-flop is given as an input to the subsequent flip-flop then the design is asynchronous. The issue with the asynchronous design is the cumulative clock to q delay of flip-flop due to the cascading of the stages. Asynchronous counters are not recommended in the ASIC design due to the issue of glitches or spikes and even the timing analysis for such kind of design is very complex.

Ripple Counters:

The ripple counter is an asynchronous counter and is shown in Fig.3. As shown in the logic diagram all the flip-flops are positive edge triggered and the LSB register receives the clock from the master clock source. The output of the LSB flip-flop is given as clock input to the next subsequent stage. 

Fig.3

The Verilog RTL for the four-bit ripple up counter is shown below.

Verilog Code:

module ripple_counters #(parameter N=4)(rst,clk,togle_in,q_out);

input rst,clk,togle_in;

output reg [N-1:0] count_out;

wire c0,c1,c2;

assign c0=count_out[0];

assign c1=count_out[1];

assign c2=count_out[2];

always@(posedge clk or negedge rst)

begin

 if(~rst)

count_out[0]<=1'b0;

else if(togle_in)

count_out[0]<=~count_out[0];

always@(negedge rst or negedge c0)

begin

 if(~rst)

count_out[1]<=1'b0;

else if(togle_in)

count_out[1]<=~count_out[1];

always@(negedge rst or negedge c1)

begin

 if(~rst)

count_out[2]<=1'b0;

else if(togle_in)

count_out[2]<=~count_out[2];

always@(negedge rst or negedge c2)

begin

 if(~rst)

count_out[3]<=1'b0;

else if(togle_in)

count_out[3]<=~count_out[3];

endmodule

Thanks for reading and comment your doubts I will try to resolve early as possible.



Connect with me 



Comments

  1. Wow bro really helpful post.

    ReplyDelete
  2. Wonderful post bro keep it up

    ReplyDelete
  3. Superb flow of information.

    ReplyDelete

Post a Comment

Popular posts from this blog

SDC (Synopsys Design Constraints) contents part 4

Today, we will be discussing the remaining constraints mentioned in the SDC, which pertain to timing exceptions and design rules. This is the final part of the SDC contents. This is going to be interesting, especially with multicycle paths. Take time to read and try to comprehend. 10. set_max_transition     By setting max transition value, our design checks that all ports and pins are meeting the specified limits mentioned in SDC. If these are not satisfied then timing report will give DRVs (design rule violations) in terms of slack. This is specified as               set_max_transition 0.5  UBUF1/A setting maximum limit of 500ps on pin A of Buffer1. 11. set_max_capacitance     This is same as max transition, setting the maximum capacitance value. if our design not meeting this value then violation will occur. This will also reports under design rule violations in terms of slack.     set_max_capacitance 0.7 [all_...

Apprenticeship CAI at MediaTek Bangalore

Hello Dear Readers,   Currently at MediaTek Bangalore vacancy for an Apprenticeship CAI role. Job Description: B.Tech degree in Electrical/Electronics Engineering with a strong educational background in Digital circuit design Experience in physical design of high performance design with frequencies > 2 Ghz. Experienced in hierarchical design, budgeting, multiple voltage domains and multiple clock domains. Strong skills with Cadence Encounter. Solid understanding of STA and timing constraints. Experienced in working on advanced process nodes (16nm). Strong expertise in Physical Verification to debug LVS/DRC issues at the block level. Requirement: B.Tech degree in Electrical/Electronics Engineering with strong educational background in Digital circuit design Experience in physical design of high performance design with frequencies > 2 Ghz. Experienced in hierarchical design, budgeting, multiple voltage domains and multiple clock domains. Strong skills with Cadence Enc...

IC Physical Design (PnR) at Ulkasemi

Hello Dear Readers,   Ulkasemi  has a vacancy for an IC Physical Design (PnR) role. Job Overview: As a full-time Trainee Engineer, the individual will be working on IC Physical Design implementation from RTL to GDSII to create design databases ready for manufacturing with a special focus on power, performance & area optimization with next-generation state-of-the-art process technologies. Job Responsibilities: Perform physical design implementation which includes Floor planning, Power Planning, Clock Tree Synthesis, Place and Route, ECO, Logic Equivalence checks Timing analysis, physical & electrical verification, driving the sign-off closure meeting schedule, and design goals Develop flow, methodologies, and automation scripts for various implementation steps Follow the instructions, compile documents, prepare deliverables, and report to the team lead Should remain up to date with the latest technology trends Educational Qualification:   B.Sc/M.Sc   in EEE or...