Add an AXI-Stream Interface
In this part of the I2S tutorial for FPGAs, I would like to show how the can expand the I2S transmitter with an AXI stream interface.
Last updated
In this part of the I2S tutorial for FPGAs, I would like to show how the can expand the I2S transmitter with an AXI stream interface.
Last updated
For this purpose, a new top design called AXIS_I2S
is created. This design should have the following interface:
This block design results in the following entity:
The ratio of SCLK to MCKL is defined via the parameter RATIO
and the width of a data word per channel via the parameter WIDTH
.
This implementation only supports 16-bit data words per channel (i.e. 32 bit for stereo). The following code must be adapted for larger bus widths.
The following components must be implemented in the design:
A clock prescaler to create the input clock for the I2S transmitter
An AXI-Stream slave interface
The control logic for the I2S transmitter
A process is created for the divider, which counts up a counter on the rising clock edge of MCLK and switches the signal SCLK_Int
after half the period.
The next step is to implement the AXI-Stream interface. A state machine is used for this:
After a reset, the machine changes from the State_Reset
state to the State_WaitForTransmitterReady
state, where it waits for the ready signal from the I2S transmitter. As soon as the transmitter is ready, the TREADY_RXD
signal of the AXI-Stream interface is set, whereby the master is informed that the slave is ready to receive data. The slave then changes to the State_WaitForValid
state.
In this state, the slave waits for the master to set the TVALID_RXD
signal to mark valid data. As soon as the signal is set, the data is written to an internal FIFO. The machine then changes to the State_WaitForTransmitterBusy
state.
Now the state machine waits for the I2S transmitter to start transmitting the data and to delete the ready signal. As soon as this is done, the machine switches back to the State_WaitForTransmitterReady
state and waits again until the I2S transmitter is ready.
With that, the AXI-Stream Interface would be finished in theory. Unfortunately, it gets a bit tricky at the end, since the current circuit design uses two different clock domains:
The clock domain for ACLK
The clock domain for MCLK
In general, these two clock signals cannot be generated from a clock source (e.g. via a clock divider), since the AXI interface typically runs at 100 MHz and the audio interface requires clock rates that can be neatly divided down to the sampling frequency, such as e.g. 12.288 MHz. As a result, timing errors occur during implementation due to excessive worst negative slack (WNS) and total negative slack (TNS):
Also, the risk of incorrect data due to the metastability of the flip-flops occurring with different clock domains is very high. Metastability occurs a. then when a flip-flop switches and the data changes at that very moment.
Therefore, the signals that are used by the individual clock domains must be transferred to the other clock domain in each case via corresponding circuits. Xilinx describes corresponding macros in document UG953 that can be used for this purpose.
The examples of the macros can be used directly for the VHDL code:
Finally, the I2S transmitter must be inserted and the generated signals passed on.
The AXI-Stream Interface for the I2S transmitter is now ready and ready for use. The complete code should now look like this:
The created AXI-Stream I2S transmitter can now be created as an IP core for Vivado if required, whereby I will omit the necessary steps here. Alternatively, the finished IP core can also be downloaded from the project's GitLab repository.
Macro
Function
xpm_cdc_gray
This function block uses Gray code to transfer a data bus from one clock domain (src) to another clock domain (dest).
xpm_cdc_single
Converts a single signal from one clock domain (src) to another clock domain (dest).
Signal
Descritpion
MCLK
Master Clock
nReset
Reset input for the audio interface (active low)
ACLK
Clock input for the AXI-Stream interface
ARESETn
Reset input for the AXI-Stream interface (active low)
TDATA_RXD
Data inputs for the AXI-Stream Interface
TREADY_RXD
Ready signal for the AXI-Stream Interface
TVALID_RXD
Valid signal for the AXI-Stream Interface
SCLK
Serial clock for the I2S interface
LRCLK
Left/Right clock (WS) for the I2S interface
SD
Serial data for the I2S interface