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.

[SOLVED] I need to write a verilog code to generate a signal which goes high for one clock pulse after every tenth clock pulse

Status
Not open for further replies.

tipra

Newbie
Joined
Dec 8, 2020
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
29
I need to write verilog code wherein I need a signal which goes high for one clock pulse after every tenth clock pulse. I tried something this way,

Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module top  #(
                  WIDTH=8
                 )
                 (
                  input clk,
                  output reg [WIDTH-1:0] sig1,
        
                  );
     reg [WIDTH-1:0] count;
     always@(posedge clk)
     begin
      count <= count + 1;
      if (count == 'd10 || count == 'd20 || count == 'd30 || count == 'd40 )
       begin
         sig1<= 1;
       else
         begin
          sig1<= 0;
         end
    endmodule



This code works fine and is able to produce the required signal 'sig1' which goes high for one cycle after every tenth clock cycle.

Is there any better and generalized way to generate 'sig1' with the required characterstics?

Note: I intend to use this signal 'sig1' in a larger design which needs to be synthesised.
 
Last edited by a moderator:

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
23,018
Helped
4,715
Reputation
9,446
Reaction score
5,087
Trophy points
1,393
Activity points
152,505
Hi,

try this:
**********
...

Code Verilog - [expand]
1
2
3
4
5
6
7
begin
     count <= count + 1;
     if (count == 'd10 )
      begin
        sig1<= 1;
        count<= 0;
      else


...
*************
width could be "4"

Klaus
 
Last edited by a moderator:

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,935
Helped
1,822
Reputation
3,654
Reaction score
1,806
Trophy points
1,393
Location
USA
Activity points
60,130
KlausSt your code example results in a divide by 11 pulse generator not a divide by 10 as it resets to 0, so 0-10, 0-10, ....

The original code only produces 4 pulses then has a gap of 225 (give or take a clock) clocks before the next pulse, so it doesn't work correctly either.

A divide by 10 pulse generator can be done similar to this code.

Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
always @(posedge clk) begin
  if (rst) begin
    count <= 'b0;
  end else if (count < DIVIDE_BY_N-1) begin // for 10 uses count < 9
    count <= count + 1;
  end else begin
    count <= 'b0;
  end
end
// combonational pulse output
assign sig1 = (count == DIVIDE_BY_N-1) ? 1'b1 : 1'b0;
// or synchronous pulse output
always @(posedge clk) sig1 <= (count == DIVIDE_BY_N-1) ? 1'b1 : 1'b0;

 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
23,018
Helped
4,715
Reputation
9,446
Reaction score
5,087
Trophy points
1,393
Activity points
152,505
Hi,
KlausSt your code example results in a divide by 11 pulse generator not a divide by 10
I'm in need of an excuse..
O.K. here it is: the OP says: " one clock pulse after every tenth clock pulse"
.. after the tenth is the eleventh ;-)

No, joke aside. For sure you are right. It counts 0 .. 10, but should 0..9

Klaus
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top