From 4b6e0102d20d9ab060ce930e4b846c8be446bb06 Mon Sep 17 00:00:00 2001 From: Vasil Zlatanov Date: Mon, 12 Dec 2016 21:51:10 +0000 Subject: public push --- part_3/ex11/pwm.v | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 part_3/ex11/pwm.v (limited to 'part_3/ex11/pwm.v') diff --git a/part_3/ex11/pwm.v b/part_3/ex11/pwm.v new file mode 100644 index 0000000..6dce0a5 --- /dev/null +++ b/part_3/ex11/pwm.v @@ -0,0 +1,28 @@ +module pwm (clk, data_in, load, pwm_out); + + input clk; + input [9:0] data_in; + input load; + output pwm_out; + + reg [9:0] d; + reg [9:0] count; + 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 \ No newline at end of file -- cgit v1.2.3-54-g00ecf