util_pulse_gen: Add configuration interface for 'pulse period'.

main
Istvan Csomortani 2016-10-28 10:59:00 +03:00
parent 825d46259b
commit d061104a3c
1 changed files with 17 additions and 7 deletions

View File

@ -40,33 +40,43 @@
module util_pulse_gen #(
parameter PULSE_WIDTH = 7,
parameter PULSE_PERIOD = 100000000) (
parameter PULSE_WIDTH = 7,
parameter PULSE_PERIOD = 100000000)( // t_period * clk_freq
input clk,
input rstn,
input clk,
input rstn,
output reg pulse);
input [31:0] pulse_period,
input pulse_period_en,
output reg pulse
);
// internal registers
reg [(PULSE_WIDTH-1):0] pulse_width_cnt = {PULSE_WIDTH{1'b1}};
reg [31:0] pulse_period_cnt = 32'h0;
reg [31:0] pulse_period_d = 32'b0;
wire end_of_period_s;
// flop the desired period
always @(posedge clk) begin
pulse_period_d <= (pulse_period_en) ? pulse_period : PULSE_PERIOD;
end
// a free running pulse generator
always @(posedge clk) begin
if (rstn == 1'b0) begin
pulse_period_cnt <= 32'h0;
end else begin
pulse_period_cnt <= (pulse_period_cnt < PULSE_PERIOD) ? (pulse_period_cnt + 1) : 32'b0;
pulse_period_cnt <= (pulse_period_cnt < pulse_period) ? (pulse_period_cnt + 1) : 32'b0;
end
end
assign end_of_period_s = (pulse_period_cnt == (PULSE_PERIOD - 1)) ? 1'b1 : 1'b0;
assign end_of_period_s = (pulse_period_cnt == (pulse_period - 1)) ? 1'b1 : 1'b0;
// generate pulse with a specified width