Add Lab work No2

This commit is contained in:
Imants Pulkstenis
2020-03-25 00:08:31 +02:00
parent 27e63599f4
commit f19b7c8ca1
11 changed files with 878 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
/////////////////////////////
// Author - Imants Pulkstenis
// Date - 24.03.2020
// Project name - Lab work No2 - Counter
// Module name - clock divider module for counter
//
// Detailed module description:
//
// This module devide FPGA input clock
// by DIVIDER. Result is 50% duty cicle
// pulses.
//
//
// Revision:
// A - initial design
// B -
//
//
/////////////////////////////
module clock_divider #(
parameter DIVIDER =2,
parameter WIDTH =2
) (
input clk,
output clk_out);
reg state=1'b0, next_state=1'b1;
reg [WIDTH-1:0] counter = DIVIDER-1 ;
always@(posedge clk)begin
state <= next_state;
if ( counter == 0) begin
next_state <= ~next_state;
counter <= DIVIDER-1;
end
else if (counter >= 0 )
counter <= counter - 1;
end
assign clk_out = state;
endmodule