mirror of
https://github.com/handsomezhuzhu/2025-yatcpu.git
synced 2026-02-20 20:10:14 +00:00
updates
This commit is contained in:
@@ -1,46 +1,25 @@
|
|||||||
`timescale 1ns / 1ps
|
`timescale 1ns / 1ps
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
// fpga4student.com: FPGA projects, VHDL projects, Verilog projects
|
||||||
// Company:
|
// Verilog project: Verilog code for clock divider on FPGA
|
||||||
// Engineer:
|
// Top level Verilog code for clock divider on FPGA
|
||||||
//
|
|
||||||
// Create Date: 2023/11/29 15:52:55
|
|
||||||
// Design Name:
|
|
||||||
// Module Name: clock_control
|
|
||||||
// Project Name:
|
|
||||||
// Target Devices:
|
|
||||||
// Tool Versions:
|
|
||||||
// Description:
|
|
||||||
//
|
|
||||||
// Dependencies:
|
|
||||||
//
|
|
||||||
// Revision:
|
|
||||||
// Revision 0.01 - File Created
|
|
||||||
// Additional Comments:
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
module clock_control(
|
module clock_control(
|
||||||
input clk_in,
|
input clock_in,
|
||||||
input enable_clk,
|
input enable_clk,
|
||||||
output clk_out
|
output reg clock_out
|
||||||
);
|
);
|
||||||
|
reg[3:0] counter = 4'd0;
|
||||||
// if clock is divided
|
parameter DIVISOR = 4'd5;
|
||||||
localparam clk_div = 2; // clock is diveded by half of divisor
|
// The frequency of the output clk_out
|
||||||
reg [3:0] cnt = 4'd0;
|
// = The frequency of the input clk_in divided by DIVISOR
|
||||||
reg out = 1'b0;
|
// For example: Fclk_in = 50Mhz, if you want to get 1Hz signal to blink LEDs
|
||||||
always @(posedge clk_in) begin
|
// You will modify the DIVISOR parameter value to 28'd50.000.000
|
||||||
cnt <= cnt + 4'd1;
|
// Then the frequency of the output clk_out = 50Mhz/50.000.000 = 1Hz
|
||||||
if (cnt >= (clk_div - 1)) begin
|
always @(posedge clock_in)
|
||||||
out <= ~out;
|
begin
|
||||||
cnt <= 0;
|
counter <= counter + 4'd1;
|
||||||
|
if(counter>=(DIVISOR-1)) begin
|
||||||
|
counter <= 4'd0;
|
||||||
end
|
end
|
||||||
|
clock_out <= ((counter<DIVISOR/2)?1'b1:1'b0) && enable_clk;
|
||||||
end
|
end
|
||||||
assign clk_out = out & enable_clk;
|
|
||||||
|
|
||||||
|
|
||||||
// original clock
|
|
||||||
// assign clk_out = clk_in & enable_clk;
|
|
||||||
|
|
||||||
endmodule
|
endmodule
|
||||||
|
|||||||
Reference in New Issue
Block a user