Skip to content

Commit

Permalink
Merge pull request #188 from vvvictor/sound
Browse files Browse the repository at this point in the history
Sound output via sigma-delta DAC
  • Loading branch information
yuri-panchul authored Nov 11, 2024
2 parents cecb0fb + 5a45275 commit 2ee9c35
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 7 deletions.
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

0 comments on commit 2ee9c35

Please sign in to comment.