-
Notifications
You must be signed in to change notification settings - Fork 1
/
PWM10.v
50 lines (44 loc) · 1.01 KB
/
PWM10.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 14:08:41 12/04/2014
// Design Name:
// Module Name: PWM10
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module PWM10(
input clk,
input [3:0] duty,
output pwm_out
);
// pwm to output
reg [4:0] cycle; // 65535
reg pwm;
assign pwm_out = pwm;
initial begin
cycle = 0;
pwm = 0;
end
parameter CYCLE_SIZE = 10; // tune this to fit exact
// PWM signal
always @(posedge clk) begin
// cycle incrementer
cycle <= (cycle >= CYCLE_SIZE) ? 0 : cycle+1;
// assign pwm based on percentage (duty cycle) of the cycle size
// for advanced
pwm <= (cycle < duty) ? 1 : 0;
// ^^ Complex expression
end
endmodule