I2S簡(jiǎn)介
I2S_RX.png
如上圖所示:
- SCLK :位時(shí)鐘艺挪,數(shù)據(jù)單bit反轉(zhuǎn)。 頻率=2 * 采樣頻率 * 采樣位寬
- LRCK :幀時(shí)鐘,左右聲道標(biāo)志位乍钻。 頻率=采樣頻率
- SDATA :串行音頻數(shù)據(jù)BIT位。圖中表示音頻數(shù)據(jù)為8bit,即采樣位寬=8
- sdata在sclk的下降沿變化团赁,上升沿采集育拨。且在lrck發(fā)生反轉(zhuǎn)后的第二個(gè)上升沿采集音頻數(shù)據(jù)的最高位。音頻數(shù)據(jù)的最低位是lrck再次反轉(zhuǎn)的第一個(gè)上升沿欢摄。
I2S詳介
功能簡(jiǎn)介
將音頻數(shù)據(jù)經(jīng)過存儲(chǔ)后熬丧,進(jìn)行并傳串處理,按照I2S協(xié)議輸出怀挠。
模塊端口
i2s_tx.png
接口描述
signal_name | direction | width | description |
---|---|---|---|
i_clk | input | 1 | FPGA內(nèi)部系統(tǒng)時(shí)鐘 |
i_rst_n | input | 1 | 異步復(fù)位析蝴,低電平有效 |
i_dsp_clk | input | 1 | 由DSP給出,用于分頻出 sclk 和 lrck |
i_aud_left_data | input | SAMP_BITS | 左聲道的音頻數(shù)據(jù) |
i_aud_right_data | input | SAMP_BITS | 右聲道的音頻數(shù)據(jù) |
i_aud_en | input | 1 | 音頻樣本有效標(biāo)志 |
o_aud_sclk | output | 1 | I2S位時(shí)鐘 |
o_aud_lrck | output | 1 | I2S幀時(shí)鐘 |
o_aud_sdata | output | 1 | I2S串行音頻數(shù)據(jù) |
o_rd_req | output | 1 | 向上級(jí)模塊發(fā)出音頻數(shù)據(jù)請(qǐng)求绿淋,若上級(jí)模塊無(wú)存儲(chǔ)則忽略該信號(hào) |
參數(shù)定義
Paramter | description |
---|---|
DIV_SCLK_DEPTH | sclk 是 i_dsp_clk 的 2^N 分頻闷畸,取值 N |
DIV_LRCK_DEPTH | lrck 是 sclk 的 2^M 分頻,取值 M |
SAMP_BITS | 左 (右)音頻的采樣位寬 |
FIFO_DEPTH | FIFO數(shù)據(jù)深度的位寬吞滞。如深度為256佑菩,則取值8 |
實(shí)現(xiàn)方案
i2s_tx方案簡(jiǎn)略圖.png
- i_dsp_clk經(jīng)過分頻模塊divdreq_clk分頻出lrck和sclk。
- 將左右聲道位拼接后寫入FIFO中裁赠。
- 利用lrck上升沿讀取FIFO數(shù)據(jù)殿漠,配合I2S時(shí)序移位輸出。
電路圖描述
i2s_tx電路圖.png
注:綠色為wire型佩捞,藍(lán)色為reg型绞幌,紫色是邏輯計(jì)算
資源占用估計(jì)
資源 | 類型 | 個(gè)數(shù) | 用途 |
---|---|---|---|
寄存器 | 1bit | 3 | 信號(hào)延拍 |
寄存器 | 2*SAMP_BITS bit | 2 | 數(shù)據(jù)流 |
FIFO | 深度:FIFO_DEPTH;位寬:2*SAMP_BITS | 1 | 跨時(shí)鐘域變化 |
子模塊(div_freq)
功能簡(jiǎn)介
- i_clk根據(jù)parameter進(jìn)行2^N分頻得到o_clk一忱。(N為parameter)
- 根據(jù)i_rst_n進(jìn)行異步復(fù)位同步釋放處理得到與o_clk相匹配的o_rst_n莲蜘。
接口描述
signal_name | direction | width | description |
---|---|---|---|
i_clk | input | 1 | FPGA內(nèi)部系統(tǒng)時(shí)鐘 |
i_rst_n | input | 1 | 異步復(fù)位,低電平有效 |
o_clk | output | 1 | 分頻得到的時(shí)鐘 |
o_rst_n | output | 1 | 分頻得到的復(fù)位信號(hào) |
參數(shù)定義
Paramter | description |
---|---|
DIV_CNT_DEPTH | o_clk 是 i_clk 的2^X分頻帘营,取值為X |
代碼實(shí)現(xiàn)
module div_freq
#(
parameter DIV_CNT_DEPTH = 2
)
(
input i_clk ,
input i_rst_n ,
output reg o_clk ,
output reg o_rst_n
)
//----------------------------- reg && wire -------------------------------
reg rst_n_temp_0 ;
reg rst_n_temp_1 ;
//-------------------------------- o_clk -----------------------------------
always @(posedge i_clk or negedge i_rst_n)
begin
if(!i_rst_n)
div_cnt <= { {DIV_CNT_DEPTH}{1'b0} } ;
else
div_cnt <= div_cnt + 1'b1;
end
always @(posedge i_clk)
o_clk <= div_cnt[DIV_CNT_DEPTH-1];
//-------------------------------- o_rst_n -----------------------------------
always @(posedge o_clk or negedge i_rst_n)
begin
if(!i_rst_n)
begin
rst_n_temp_0 <= 1'b0;
rst_n_temp_1 <= 1'b0;
o_rst_n <= 1'b0;
end
else
begin
rst_n_temp_0 <= 1'b1;
rst_n_temp_1 <= rst_n_temp_0;
o_rst_n <= rst_n_temp_1;
end
end
endmodule
資源占用估計(jì)
資源 | 類型 | 個(gè)數(shù) | 用途 |
---|---|---|---|
寄存器 | 1bit | 4 | 信號(hào)延拍 |
計(jì)數(shù)器 | DIV_CNT_DEPTH bit | 1 | 分頻計(jì)數(shù)器 |
來(lái)源:馬哥 - Marin
著作權(quán)歸作者所有票渠。商業(yè)轉(zhuǎn)載請(qǐng)聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請(qǐng)注明出處仪吧。