-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cores/vco: fix and modularize vco example (#36)
- Loading branch information
Showing
4 changed files
with
37 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,29 @@ | ||
module wavetable_osc #( | ||
parameter W = 16, | ||
parameter FRAC_BITS = 10, | ||
parameter WAVETABLE_PATH = "cores/util/vco/wavetable.hex", | ||
parameter WAVETABLE_SIZE = 256, | ||
parameter WAVETABLE_SIZE = 256 | ||
)( | ||
input rst, | ||
input sample_clk, | ||
input [31:0] wavetable_inc, | ||
output signed [W-1:0] out, | ||
output logic signed [W-1:0] out | ||
); | ||
|
||
logic [W-1:0] wavetable [0:WAVETABLE_SIZE-1]; | ||
initial $readmemh(WAVETABLE_PATH, wavetable); | ||
|
||
logic [31:0] wavetable_pos = 32'h0; | ||
// Position in wavetable - N.F fixed-point where BIT_START is size of F. | ||
logic [31:0] wavetable_pos = 0; | ||
|
||
always_ff @(posedge sample_clk) begin | ||
// TODO: linear interpolation between frequencies, silence oscillator | ||
// whenever we are outside the LUT bounds. | ||
wavetable_pos <= wavetable_pos + wavetable_inc; | ||
if (rst) begin | ||
wavetable_pos <= 0; | ||
end else begin | ||
wavetable_pos <= wavetable_pos + wavetable_inc; | ||
// Take top N bits of wavetable_pos as output. | ||
out <= wavetable[wavetable_pos[FRAC_BITS+$clog2(WAVETABLE_SIZE)-1:FRAC_BITS]]; | ||
end | ||
end | ||
|
||
// Top 8 bits of the N.F fixed-point representation are index into wavetable. | ||
localparam BIT_START = 10; | ||
wire [$clog2(WAVETABLE_SIZE)-1:0] wavetable_idx = | ||
wavetable_pos[BIT_START+$clog2(WAVETABLE_SIZE)-1:BIT_START]; | ||
|
||
assign out = wavetable[wavetable_idx]; | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters