Altera_Forum
Honored Contributor
12 years agoI have problem to get counter to PWM
I'm trying to assign _t3 value from _t1, before I reset _t1 to 0. And I use _t3 value to run next pwm to out
Here is the code. module convert_Ref(input clk, input in, output reg out); reg [15: 0] _t1, _t2, _t3, _i1; reg _tA, _tB; initial begin _t1 = 0; _t2 = 0; _t3 = 0; _tA = 0; _tB = 0; _i1 = 0; end always @(posedge clk) begin if (in) begin if (_tA) begin _t3 <= _t1; _t1 <= 0; _t2 <= 0; _tB <= 1; end _tA <= 0; _t1 <= _t1 + 1; end else begin if (!_tA) begin _tB <= 0; end _tA <= 1; _t2 <= _t2 + 1; end if (_tB) begin _i1 <= _i1 + 1; if (_i1 < _t3) out <= 1; else out <= 0; if (_i1 == (_t3 + 100)) _i1 <= 0; end end