Prev Problem
Next Problem

30. PWM with 4-bit Resolution

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

 

Code

/*Write your code here*/
module pwm4_basic(

    input  wire clk,
    input  wire rst,
    input  wire [3:0] duty,
    output reg  [3:0] pwm_out
);

    reg [3:0] counter;
    wire [3:0] next_counter, pwm_out_next;
    always @(posedge clk, posedge rst)begin
        if(rst)begin 
            counter <=0;
            pwm_out <=0;
        end
        else begin
            counter <= next_counter;
            pwm_out <= pwm_out_next;
        end
    end
    assign next_counter = counter + 4'b0001;
    assign pwm_out_next = counter < duty; 
endmodule

 

Was this helpful?
Upvote
Downvote