URL
https://opencores.org/ocsvn/zet86/zet86/trunk
[/] [zet86/] [trunk/] [soc/] [timer.v] - Diff between revs 49 and 52
Show entire file |
Details |
Blame |
View Log
Rev 49 |
Rev 52 |
Line 1... |
Line 1... |
module timer (
|
/*
|
|
* Phase accumulator clock:
|
|
* Fo = Fc * N / 2^bits
|
|
* here N: 12507 and bits: 32
|
|
* it gives a frequency of 18.200080376 Hz
|
|
*/
|
|
|
|
module timer #(
|
|
parameter res = 33, // bit resolution (default: 33 bits)
|
|
parameter phase = 12507 // phase value for the counter
|
|
)
|
|
(
|
// Wishbone slave interface
|
// Wishbone slave interface
|
input wb_clk_i,
|
input wb_clk_i,
|
input wb_rst_i,
|
input wb_rst_i,
|
output reg wb_tgc_o, // intr
|
output reg wb_tgc_o // intr
|
input wb_tgc_i // inta
|
|
);
|
);
|
|
|
// Registers and nets
|
// Registers and nets
|
reg [17:0] cnt;
|
reg [res-1:0] cnt;
|
reg old_clk2;
|
reg old_clk2;
|
reg pulse;
|
|
wire clk2;
|
wire clk2;
|
|
|
// Continuous assignments
|
// Continuous assignments
|
assign clk2 = cnt[17];
|
assign clk2 = cnt[res-1];
|
|
|
// Behaviour
|
// Behaviour
|
// cnt
|
// cnt
|
always @(posedge wb_clk_i)
|
always @(posedge wb_clk_i)
|
cnt <= wb_rst_i ? 18'h00 : (cnt + 18'h1);
|
cnt <= wb_rst_i ? 0 : (cnt + phase);
|
|
|
// old_clk2
|
// old_clk2
|
always @(posedge wb_clk_i)
|
always @(posedge wb_clk_i)
|
old_clk2 <= wb_rst_i ? 1'b0 : clk2;
|
old_clk2 <= wb_rst_i ? 1'b0 : clk2;
|
|
|
// pulse
|
|
always @(posedge wb_clk_i)
|
|
pulse <= wb_rst_i ? 1'b0 : (clk2!=old_clk2);
|
|
|
|
// intr
|
// intr
|
always @(posedge wb_clk_i)
|
always @(posedge wb_clk_i)
|
wb_tgc_o <= wb_rst_i ? 1'b0
|
wb_tgc_o <= wb_rst_i ? 1'b0 : (!old_clk2 & clk2);
|
: ((pulse & !wb_tgc_i) ? 1'b1
|
|
: (wb_tgc_o ? !wb_tgc_i : 1'b0));
|
|
endmodule
|
endmodule
|
|
|
No newline at end of file
|
No newline at end of file
|
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.