Forum Discussion

SFitz3's avatar
SFitz3
Icon for New Contributor rankNew Contributor
6 years ago

How do I make a I2S transmitter on the DE0-Nano?

I am trying to transmit a square wave in I2S for the CS4334 DAC, but I do not understand the timing behind it. The code I have so far doze not work.

Music.v

module Music(input wire clk, output reg SDATA, output reg SCLK, output reg LRCK, output reg MCLK, output reg[7:0] debugs);
reg[23:0] PCM[0:4];
initial begin
	$readmemh ("pcm.mem", PCM);
end
 
 
reg[31:0] Mcounter; //Master Clock Counter
reg[31:0] Scounter; //Serial Clock Counter
reg[31:0] Lcounter; //Channel Counter
always @ (posedge clk ) begin //50000000 hertz
	//Create MCLK
	if(Mcounter == 195) begin
		Mcounter <= 0;
		MCLK <= !MCLK;
	end else begin
		Mcounter <= Mcounter + 1;
	end
	
	//Create SCLK
	if(Scounter == 2083) begin
		Scounter <= 0;
		SCLK <= ~SCLK;
	end else begin
		Scounter <= Scounter + 1;
	end
	
		//Create LCLK
	if(Lcounter == 50000) begin
		Lcounter <= 0;
		LRCK <= ~LRCK;
	end else begin
		Lcounter <= Lcounter + 1;
	end
end
 
 
reg[31:0] byte;
reg[7:0] serialBit;
reg[23:0] tmp;
//Serial Signal Generator
always @ (negedge SCLK) begin
	if(serialBit == 23) begin
		serialBit <= 0;
		if(byte == 4) begin
			byte <= 0;
		end else begin
			byte <= byte + 1;
		end
	end else begin
		serialBit <= serialBit;
	end
	
	SDATA <= ((tmp & (1 << serialBit)) >> serialBit);
end
 
always @ (*) begin
	tmp = PCM[byte];
end
endmodule

pcm.mem

FFFFFF FFFFFF 000000 000000

Is there any documentation about I2S.

Sorry if this question is posted in the incorrect spot because I did not know where to post it.

3 Replies