Add stubbed out pwm implementation
All checks were successful
ci/woodpecker/push/test-workflow Pipeline was successful

This commit is contained in:
Waylon Cude 2025-05-22 20:26:29 -07:00
parent 3f626074f9
commit ec6ce08b21

33
design/audio/pwm.sv Normal file
View File

@ -0,0 +1,33 @@
module pwm(
input logic clk, reset,
// Load control signal, if this is high we should load a new sample
input logic load,
// The audio sample to play back
input logic [15:0] sample,
// The audio output pin
output wire pwm_pin
);
// What I imagine is that the counter here can be incremented each clock.
// If the counter value is less than or equal to the value in the sample buffer
// then you should turn on the PWM output. Otherwise if the counter is greater
// than the value in the sample buffer the output will be off.
//
// This means that for small sample values the output will be enabled for only
// short periods of time, exactly what we want.
logic [15:0] pulse_counter;
// A buffer to hold the sample in. Every clock cycle you should check load
// to see if you should pull the sample off the bus and store it in here.
logic [15:0] sample_buffer;
// A control signal for driving the PWM high or low. This gets translated into
// either a 'z or a '0 later as the PWM requires.
logic should_output;
// NOTE: tristating the pwm pin with a 'z will output a 1
// sending a 0 will pull the pin to 0 as usual
assign pwm_pin = should_output ? 'z : '0;
endmodule