Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbb0897a

Browse files
committed
Fix clog usage in pulse_stretch.sv
1 parentf0edcd3 commitbb0897a

File tree

1 file changed

+53
-48
lines changed

1 file changed

+53
-48
lines changed

‎pulse_stretch.sv‎

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
//--------------------------------------------------------------------------------
22
// pulse_stretch.sv
3+
// published as part of https://github.com/pConst/basic_verilog
34
// Konstantin Pavlov, pavlovconst@gmail.com
45
//--------------------------------------------------------------------------------
56

67
// INFO --------------------------------------------------------------------------------
78
// Pulse stretcher/extender module
8-
// this implementftion uses a simple delay line or counter to stretch pulses
9-
// WIDTH parameter sets output pulse width
10-
// if you need variable output poulse width, see pulse_gen.sv module
9+
//
10+
// - this implementftion uses a simple delay line or counter to stretch pulses
11+
// - WIDTH parameter sets output pulse width
12+
// - if you need variable output poulse width, see pulse_gen.sv module
1113

1214

1315
/* --- INSTANTIATION TEMPLATE BEGIN ---
@@ -24,6 +26,7 @@ pulse_stretch #(
2426
2527
--- INSTANTIATION TEMPLATE END ---*/
2628

29+
2730
modulepulse_stretch#( parameter
2831
WIDTH=8,
2932
USE_CNTR=0// ==0 - stretcher is implemented on delay line
@@ -37,55 +40,57 @@ module pulse_stretch #( parameter
3740
);
3841

3942

40-
localparamCNTR_WIDTH=$clog2(WIDTH)+1;
41-
42-
generate
43-
44-
if (WIDTH==0 )begin
45-
assign out=0;
46-
47-
endelseif(WIDTH==1 )begin
48-
assign out= in;
49-
50-
endelsebegin
51-
if(USE_CNTR=='0 )begin
52-
// delay line
43+
localparamCNTR_W=$clog2(WIDTH+1);
5344

54-
logic [WIDTH-1:0] shifter='0;
55-
always_ff@(posedge clk)begin
56-
if(~nrst )begin
57-
shifter[WIDTH-1:0]<='0;
58-
endelsebegin
59-
// shifting
60-
shifter[WIDTH-1:0]<={shifter[WIDTH-2:0],in};
61-
end// nrst
62-
end// always
45+
generate
46+
//==========================================================================
47+
if(WIDTH==0 )begin
48+
assign out=0;
6349

64-
assign out= (shifter[WIDTH-1:0]!='0);
50+
//==========================================================================
51+
endelseif(WIDTH==1 )begin
52+
assign out= in;
6553

54+
//==========================================================================
6655
endelsebegin
67-
// counter
68-
69-
logic [CNTR_WIDTH-1:0] cntr='0;
70-
always_ff@(posedge clk)begin
71-
if(~nrst )begin
72-
cntr[CNTR_WIDTH-1:0]<='0;
73-
endelsebegin
74-
if( in )begin
75-
// setting counter
76-
cntr[CNTR_WIDTH-1:0]<=CNTR_WIDTH'(WIDTH);
77-
endelseif( out )begin
78-
// decrementing counter
79-
cntr[CNTR_WIDTH-1:0]<= cntr[CNTR_WIDTH-1:0]-1'b1;
80-
end
81-
end// nrst
82-
end// always
83-
84-
assign out= (cntr[CNTR_WIDTH-1:0]!='0);
85-
86-
end
87-
end// if WIDTH
88-
endgenerate
56+
if(USE_CNTR=='0 )begin
57+
// delay line
58+
59+
logic [WIDTH-1:0] shifter='0;
60+
always_ff@(posedge clk)begin
61+
if(~nrst )begin
62+
shifter[WIDTH-1:0]<='0;
63+
endelsebegin
64+
// shifting
65+
shifter[WIDTH-1:0]<={shifter[WIDTH-2:0],in};
66+
end// nrst
67+
end// always
68+
69+
assign out= (shifter[WIDTH-1:0]!='0);
70+
71+
endelsebegin
72+
// counter
73+
74+
logic [CNTR_W-1:0] cntr='0;
75+
always_ff@(posedge clk)begin
76+
if(~nrst )begin
77+
cntr[CNTR_W-1:0]<='0;
78+
endelsebegin
79+
if( in )begin
80+
// setting counter
81+
cntr[CNTR_W-1:0]<=CNTR_W'(WIDTH);
82+
endelseif( out )begin
83+
// decrementing counter
84+
cntr[CNTR_W-1:0]<= cntr[CNTR_W-1:0]-1'b1;
85+
end
86+
end// nrst
87+
end// always
88+
89+
assign out= (cntr[CNTR_W-1:0]!='0);
90+
91+
end
92+
end// if WIDTH
93+
endgenerate
8994

9095

9196
endmodule

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp