-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from vvvictor/sound
Sound output via sigma-delta DAC
- Loading branch information
Showing
4 changed files
with
67 additions
and
7 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,2 +1,3 @@ | ||
`define FORCE_NO_INSTANTIATE_TM1638_BOARD_CONTROLLER_MODULE | ||
//`define INSTANTIATE_SOUND_DAC_OUTPUT_INTERFACE_MODULE | ||
`include "../tang_nano_9k_hdmi_tm1638/board_specific_top.sv" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// PWM DAC | ||
// | ||
// MSBI is the highest bit number. NOT amount of bits! | ||
// | ||
// https://github.com/MiSTer-devel/Genesis_MiSTer/blob/master/sys/sigma_delta_dac.v | ||
// | ||
|
||
module sigma_delta_dac #(parameter MSBI=7, parameter INV=1'b1) | ||
( | ||
output reg DACout, //Average Output feeding analog lowpass | ||
input [MSBI:0] DACin, //DAC input (excess 2**MSBI) | ||
input CLK, | ||
input RESET | ||
); | ||
|
||
reg [MSBI+2:0] DeltaAdder; //Output of Delta Adder | ||
reg [MSBI+2:0] SigmaAdder; //Output of Sigma Adder | ||
reg [MSBI+2:0] SigmaLatch; //Latches output of Sigma Adder | ||
reg [MSBI+2:0] DeltaB; //B input of Delta Adder | ||
|
||
always @(*) DeltaB = {SigmaLatch[MSBI+2], SigmaLatch[MSBI+2]} << (MSBI+1); | ||
always @(*) DeltaAdder = DACin + DeltaB; | ||
always @(*) SigmaAdder = DeltaAdder + SigmaLatch; | ||
|
||
always @(posedge CLK or posedge RESET) begin | ||
if(RESET) begin | ||
SigmaLatch <= 1'b1 << (MSBI+1); | ||
DACout <= INV; | ||
end else begin | ||
SigmaLatch <= SigmaAdder; | ||
DACout <= SigmaLatch[MSBI+2] ^ INV; | ||
end | ||
end | ||
|
||
endmodule |