Continue to Site

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.

help me to write a VERILOG code for MODULO 12 counter

Status
Not open for further replies.

arannyabd

Newbie level 1
Joined
Apr 9, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,286
pls anybody help me to write a VERILOG code for MODULO 12 counter
 

From Google:

Mod-13:

Code:
`define TICK #2
module mod13Cntr(clk, reset, Q);
input clk, reset;
output [3:0] Q;
reg [3:0] Q;

//Behavioral Code for a Mod-13 counter
always @ (posedge clk) begin
    if (~reset) begin
        if (Q == 4'b1100) begin
           Q <= `TICK 4'b0;
       end
       else begin
           Q <= `TICK Q+1;
       end
    end
end
always @ (posedge reset) begin
    Q <= 4'b0000;
end
endmodule

Try to understand it and then modify it to become mod-12.
 

Code:
module mod_n_cntr #(parameter [3:0] n = 'd12)(
           input clk_i, rst_n_i,
           output [3:0] cntr_o);

   reg [3:0] cntr_d, cntr_q;


always @ (posedge clk_i, negedge rst_n_i) begin: clk process
    if (!rst_n_i) begin
       cntr_q <= 'b0;
    end else begin
       cntr_q <= cntr_d;
    end
end

always @ (*) begin : comb
   if(cntr_q == n - 1) begin
       cntr_d = 'b0;
   end else begin
       cntr_d = cntr_q + 1;
   end
end

assign cntr_o = cntr_q;

endmodule
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top