I2S簡介

I2S_RX.png
如上圖所示:
- SCLK :位時鐘,數(shù)據(jù)單bit反轉(zhuǎn)。 頻率=2 * 采樣頻率 * 采樣位寬
- LRCK :幀時鐘,左右聲道標志位。 頻率=采樣頻率
- SDATA :串行音頻數(shù)據(jù)BIT位。圖中表示音頻數(shù)據(jù)為8bit,即采樣位寬=8
- sdata在sclk的下降沿變化,上升沿采集。且在lrck發(fā)生反轉(zhuǎn)后的第二個上升沿采集音頻數(shù)據(jù)的最高位。音頻數(shù)據(jù)的最低位是lrck再次反轉(zhuǎn)的第一個上升沿。
I2S詳介
功能簡介
將音頻數(shù)據(jù)經(jīng)過存儲后,進行并傳串處理,按照I2S協(xié)議輸出。
模塊端口

i2s_tx.png
接口描述
| signal_name | direction | width | description |
|---|---|---|---|
| i_clk | input | 1 | FPGA內(nèi)部系統(tǒng)時鐘 |
| 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 | 音頻樣本有效標志 |
| o_aud_sclk | output | 1 | I2S位時鐘 |
| o_aud_lrck | output | 1 | I2S幀時鐘 |
| o_aud_sdata | output | 1 | I2S串行音頻數(shù)據(jù) |
| o_rd_req | output | 1 | 向上級模塊發(fā)出音頻數(shù)據(jù)請求,若上級模塊無存儲則忽略該信號 |
參數(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 |
實現(xiàn)方案

i2s_tx方案簡略圖.png
- i_dsp_clk經(jīng)過分頻模塊divdreq_clk分頻出lrck和sclk。
- 將左右聲道位拼接后寫入FIFO中。
- 利用lrck上升沿讀取FIFO數(shù)據(jù),配合I2S時序移位輸出。
電路圖描述

i2s_tx電路圖.png
注:綠色為wire型,藍色為reg型,紫色是邏輯計算
資源占用估計
| 資源 | 類型 | 個數(shù) | 用途 |
|---|---|---|---|
| 寄存器 | 1bit | 3 | 信號延拍 |
| 寄存器 | 2*SAMP_BITS bit | 2 | 數(shù)據(jù)流 |
| FIFO | 深度:FIFO_DEPTH;位寬:2*SAMP_BITS | 1 | 跨時鐘域變化 |
子模塊(div_freq)
功能簡介
- i_clk根據(jù)parameter進行2^N分頻得到o_clk。(N為parameter)
- 根據(jù)i_rst_n進行異步復(fù)位同步釋放處理得到與o_clk相匹配的o_rst_n。
接口描述
| signal_name | direction | width | description |
|---|---|---|---|
| i_clk | input | 1 | FPGA內(nèi)部系統(tǒng)時鐘 |
| i_rst_n | input | 1 | 異步復(fù)位,低電平有效 |
| o_clk | output | 1 | 分頻得到的時鐘 |
| o_rst_n | output | 1 | 分頻得到的復(fù)位信號 |
參數(shù)定義
| Paramter | description |
|---|---|
| DIV_CNT_DEPTH | o_clk 是 i_clk 的2^X分頻,取值為X |
代碼實現(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
資源占用估計
| 資源 | 類型 | 個數(shù) | 用途 |
|---|---|---|---|
| 寄存器 | 1bit | 4 | 信號延拍 |
| 計數(shù)器 | DIV_CNT_DEPTH bit | 1 | 分頻計數(shù)器 |
來源:馬哥 - Marin
著作權(quán)歸作者所有。商業(yè)轉(zhuǎn)載請聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請注明出處。