Design of the I2S transmitter
Let´s start with the basic design of a I2S transmitter in VHDL.
Last updated
Let´s start with the basic design of a I2S transmitter in VHDL.
Last updated
In the first part, I would like to show how a simple I2S transmitter can be designed and used to output a constant sound via a loudspeaker using a CS4344 stereo D/A converter.
The sound to be output is to be stored in the block memory of the FPGA and read out by the transmitter which sends the data to the D/A converter.
The entire project is divided into three sections, which I will discuss gradually:
A Top design which integrates the system clock and an I2S module
The I2S module which integrates the ROM and the I2S transmitter
The I2S transmitter
The bottom end of the design should be the I2S transmitter, which has the task of sending the individual data words over the I2S interface.
The block diagram results in the following entity of the transmitter:
The size of a data word is defined via the parameter WIDTH
.
A three-stage state machine controls the transmitter and is described as follows:
During a reset, the output signals are deleted and the clock for SCLK is deactivated. After the reset, the machine changes from the State_Reset
state to the state State_TransmitWord
. In this state, the machine transmits the content of the buffer Tx_Int
via the I2S interface.
As soon as the transmission of the last data bit is started, Ready
is set to signal the end of a transmission and the readiness to accept new data. The machine then changes to the state State_LoadWord
state, where the send buffer is filled with a new data word and a new transfer is started.
The I2S transmitter is used by the higher-level I2S module to transfer data from a ROM to the D/A converter.
With the following entity:
The parameters RATIO
and WIDTH
define the ratio of SCLK to MCLK and the width of a data word per channel.
In addition to the I2S transmitter, the module uses a ROM, which can be created via the block memory generator and filled with data. Both can be done using Vivado's IP integrator.
Finally, the ROM is initialized with a sine signal coe file via Other Options.
The I2S module uses a state machine to read data from the ROM and transfer it to the I2S transmitter.
The first process is used to generate the clock signal SCLK required for the transmitter from MCLK.
The second process takes care of the processing of the state machine. After leaving the state State_Reset
, the machine waits in the State_WaitForReady
state until the transmitter signals readiness with the Ready
signal.
As soon as the transmitter is ready, the machine changes to the State_WaitForStart
state. In this state, the current data word is read from the ROM and transferred to the transmitter.
The ROM is shown here only contains the information from one channel. The data must be expanded accordingly for the second channel.
As soon as the transmitter clears the ready signal and begins transmitting the data, the state machine changes to the State_IncreaseAddress
state. In this state, the ROM address is increased by one and then switched back to the State_WaitForReady
state.
The last component is the top design that includes the I2S module and a clocking wizard.
This example uses the following parameters to control the CS4344:
The Clocking Wizard is used to generate the 12.288 MHz clock from the oscillator frequency of the programmable logic. For this purpose, the clocking wizard is inserted via the IP integrator and instantiated together with the finished I2S module in the VHDL code.
The design can now be implemented, transferred to the FPGA and tested. Ideally, the D/A converter outputs a 480 Hz sine signal, since the signal pattern from the ROM has a length of 100 samples and the sampling frequency is 48 kHz. The communication and the signal can be checked with an oscilloscope:
Also, the audio signal can be checked. The FFT function of an oscilloscope is the ideal tool to do it.
Signal
Description
Clock
Input clock for the audio interface
nReset
Reset input for the audio interface (active low)
Ready
Ready signal to indicate a new data transmission
Tx
Transmission data
SCLK
Serial clock for the I2S interface
LRCLK
Left/Right clock (WS) for the I2S interface
SD
Serial data for the I2S interface
Signal
Description
MCLK
Master clock for the audio interface
nReset
Reset input for the audio interface (active low)
SCLK
Serial clock for the I2S interface
LRCLK
Left/Right clock (WS) for the I2S interface
SD
Serial data for the I2S interface
Parameter
Value
MCLK
12.288 MHz
SCLK
1.536 MHz
LRCLK
48 kHz
RATIO
8
WIDTH
16