blob: c3b34d97fcbd8ddbcaadb7b4a41a7af71329cb74 (
plain)
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
|
module pwm (clk, data_in, load, pwm_out);
input clk; // system clock
input [9:0] data_in; // input data for conversion
input load; // high pulse to load new data
output pwm_out; // PWM output
reg [9:0] d; // internal register
reg [9:0] count; // internal 10-bit counter
reg pwm_out;
always @ (posedge clk)
if (load == 1'b1) d <= data_in;
initial count = 10'b0;
always @ (posedge clk) begin
count <= count + 1'b1;
if (count > d)
pwm_out <= 1'b0;
else
pwm_out <= 1'b1;
end
endmodule
|