mirror of
https://github.com/supleed2/EIE4-FYP.git
synced 2024-12-22 22:25:50 +00:00
Working version of sample generator
This commit is contained in:
parent
cf504787e2
commit
0ce0835a45
|
@ -4,36 +4,36 @@ module genSaw
|
||||||
( input var i_clk48
|
( input var i_clk48
|
||||||
, input var i_rst48_n
|
, input var i_rst48_n
|
||||||
, input var i_pause
|
, input var i_pause
|
||||||
, input var [23:0] i_tf
|
, input var [23:0] i_targetf
|
||||||
, output var [47:0] o_lr
|
, output var [15:0] o_sample
|
||||||
, output var o_new_pulse
|
, output var o_pulse
|
||||||
);
|
);
|
||||||
|
|
||||||
logic [8:0] clk_div;
|
logic [8:0] clk_div;
|
||||||
always_ff @(posedge i_clk48)
|
always_ff @(posedge i_clk48) // Count half 48kHz cycle
|
||||||
if (!i_rst48_n) clk_div <= 0; // Reset if reset is low
|
if (!i_rst48_n) clk_div <= 0;
|
||||||
else if (clk_div == 9'd500) clk_div <= 0; // Reset count every 500 cycles
|
else if (clk_div == 9'd499) clk_div <= 0;
|
||||||
else clk_div <= clk_div + 1; // Increment otherwise
|
else clk_div <= clk_div + 1;
|
||||||
|
|
||||||
logic clk_48k;
|
logic clk_48k;
|
||||||
always_ff @(posedge i_clk48)
|
always_ff @(posedge i_clk48) // Generate 48kHz clock
|
||||||
if (!i_rst48_n) clk_48k <= 0; // Reset if reset is low
|
if (!i_rst48_n) clk_48k <= 0;
|
||||||
else if (clk_div == 9'd500) clk_48k <= ~clk_48k; // Invert every 500 cycles
|
else if (clk_div == 9'd0) clk_48k <= ~clk_48k;
|
||||||
|
|
||||||
logic clk_48k_past;
|
logic clk_48k_past;
|
||||||
always_ff @(posedge i_clk48)
|
always_ff @(posedge i_clk48) // Track rising / falling edge of 48kHz clock
|
||||||
clk_48k_past <= clk_48k; // 1 cycle delayed version of 48kHz clock
|
clk_48k_past <= clk_48k;
|
||||||
|
|
||||||
assign o_new_pulse = clk_48k && !clk_48k_past; // Detect rising edge of 48kHz clock
|
assign o_pulse = clk_48k && !clk_48k_past; // Detect rising edge of 48kHz clock
|
||||||
|
|
||||||
logic [23:0] saw_step;
|
logic [23:0] int_saw_step;
|
||||||
assign saw_step = (24'd699 * i_tf) >> 1; // Sawtooth step calc from input target freq
|
assign int_saw_step = (24'd699 * i_targetf); // Sawtooth step calc from input target freq
|
||||||
|
|
||||||
logic [23:0] waveform;
|
logic [15:0] saw_step;
|
||||||
always_ff @(posedge clk_48k)
|
assign saw_step = {1'b0, int_saw_step[23:9]}; // Shift step right correctly (2^9)
|
||||||
if (!i_rst48_n) waveform <= '0; // Reset if reset is low
|
|
||||||
else if (!i_pause) waveform <= waveform + saw_step; // Add saw step if not paused (48kHz)
|
|
||||||
|
|
||||||
assign o_lr = {waveform, waveform}; // Output same sample to left & right
|
always_ff @(posedge clk_48k) // Generate new sample on rising edge of 48kHz clock
|
||||||
|
if (!i_rst48_n) o_sample <= '0;
|
||||||
|
else if (!i_pause) o_sample <= o_sample + saw_step; // Add saw_step if not paused (48kHz)
|
||||||
|
|
||||||
endmodule
|
endmodule
|
||||||
|
|
Loading…
Reference in a new issue