Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sound output via sigma-delta DAC #188

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions boards/tang_nano_9k_hdmi_no_tm1638/board_specific_top.sv
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"
36 changes: 29 additions & 7 deletions boards/tang_nano_9k_hdmi_tm1638/board_specific_top.sv
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
`define REVERSE_KEY
`define REVERSE_LED


//`define INSTANTIATE_SOUND_DAC_OUTPUT_INTERFACE_MODULE
//----------------------------------------------------------------------------

module board_specific_top
Expand Down Expand Up @@ -428,6 +430,26 @@ module board_specific_top

//------------------------------------------------------------------------

`ifdef INSTANTIATE_SOUND_DAC_OUTPUT_INTERFACE_MODULE
`undef INSTANTIATE_SOUND_OUTPUT_INTERFACE_MODULE

wire dac_out;

sigma_delta_dac
#( .MSBI ( 7 ),
.INV ( 1'b0 )
)
SD_DAC
( .DACout( dac_out ), //Average Output feeding analog lowpass
.DACin ( sound[15 -:8] ), //DAC input (excess 2**MSBI)
.CLK ( clk ),
.RESET ( rst )
);
assign LARGE_LCD_HS = dac_out;
assign LARGE_LCD_CK = ~dac_out;

`endif

`ifdef INSTANTIATE_SOUND_OUTPUT_INTERFACE_MODULE

i2s_audio_out
Expand All @@ -436,13 +458,13 @@ module board_specific_top
)
inst_audio_out
(
.clk ( clk ),
.reset ( rst ),
.data_in ( sound ),
.mclk ( LARGE_LCD_DE ),
.bclk ( LARGE_LCD_VS ),
.lrclk ( LARGE_LCD_HS ),
.sdata ( LARGE_LCD_CK )
.clk ( clk ),
.reset ( rst ),
.data_in ( sound ),
.mclk ( LARGE_LCD_DE ),
.bclk ( LARGE_LCD_VS ),
.lrclk ( LARGE_LCD_HS ),
.sdata ( LARGE_LCD_CK )
);

`endif
Expand Down
1 change: 1 addition & 0 deletions peripherals/lab_specific_board_config.svh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
`define INSTANTIATE_GRAPHICS_INTERFACE_MODULE
`define INSTANTIATE_MICROPHONE_INTERFACE_MODULE
`define INSTANTIATE_SOUND_OUTPUT_INTERFACE_MODULE
// `define INSTANTIATE_SOUND_DAC_OUTPUT_INTERFACE_MODULE

`endif // `ifndef LAB_SPECIFIC_BOARD_CONFIG_SVH

Expand Down
36 changes: 36 additions & 0 deletions peripherals/sigma_delta_dac.v
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