FPGARelated.com
Blogs

MyHDL FPGA Tutorial II cont. (Echo, Audio Interface)

Christopher FeltonSeptember 13, 201210 comments

Introduction

To demonstrate the echo on an FPGA board an interface to an audio ADC/DAC chip will be used. The following will explain the connection to the audio codec and the HDL module used to interface.

Audio Codec Interface

I have two boards with TI AIC23b audio codecs. The AIC23 has a configuration interface (ability to program the registers) and a streaming audio interface. The SPI mode will be used to configure the codec and the I2S interface is used to send and receive audio samples.

aic_intf

SPI Configuration Interface

The AIC23 has a collection of registers that are used to configure / program different settings, including the sample rate, number of bits in a sample, and other settings related to the codec. The SPI has a basic method for programming the registers. The register address and data are sent via the SPI bus.

The following timing diagram illustrates the SPI transfer.

aic_intf_spi

The MyHDL simulation of the SPI configuration.

spi_xfr

 

I2S Audio Interface

The audio sample interface is a I2S serial connection. The I2S is a full-duplex communication path and supports left and right (stereo) samples. The I2S interface has source synchronous clock, data in, data out, and a sync signal (edges indicate beginning of sample and high / low that indicates left or right channels).

aic_intf_i2s
 
 
 The MyHDL simulation.
 

i2s_xfr

The sample bit widths can be configured to be 32, 24, and 16 bits. The audio codec only supports max 24 bits so the 32 bit setting simply sign extends the samples.

AIC Module

The HDL module used to interface to the AIC23 will drive the SPI configuration bus at start-up. It will take a static configuration, provided by the Aic23Config object, and create the register settings required. The following is an example of setting the AIC23 configuration values for the module. The module will take the settings and create the register settings.

cfgopt = Aic23Config()
cfgopt.input_len = 16
cfgopt.sample_rate = 48

# Instantiate the AIC23 interface module
g_aic23 = aic23(clock=clk96MHz,
                reset=reset,
                au_bus=au_bus,
                aic23_bus=aic23_bus,
                tst_pts=tst_pts,
                ConfigOpt=ConfigOpt)

The above code snip demonstrates how to set the configuration of the audio codec. Printing the string of the object (print(cfgopt)) will have the following output

input_len .......................... 16
right :
   hp_lock ......................... False
   mute ............................ False
   lock ............................ False
   hp_volume ....................... 121
   volume .......................... 23
   hp_zero_cross ................... True
sample_rate ........................ 48
left :
   hp_lock ......................... False
   mute ............................ False
   lock ............................ False
   hp_volume ....................... 121
   volume .......................... 23
   hp_zero_cross ................... True

The AIC module will decode the samples from the I2S bus and provide the samples via a parallel bus and a sample valid strobe (Ts). The sample valid strobe is named Ts because it will match the sample rate period. The AIC module will accept a similar input. It will take a parallel bus input, it will take the samples in at the generated Ts. The sample rate and synchronization is driven by the AIC23 codec.

au_bus

To wire up a loopback is simple:

@always(clk96MHz.posedge)
def hdl_loopback():
    au_out_r.next = au_in_r
    au_out_l.next = au_in_l

The testbench will simply increment the right channel and decrement the left channel. And the aic23_top module will loopback the audio samples. The testbench will drive the DIN port with the serial samples. The au_in_r and au_in_l will be the received samples. The samples will be looped back to the au_out_r and au_out_l. The AIC23 module will drive the DOUT port with the serial samples.

Using the AIC23 module, it will be extremely easy to use the audio interface and modify the settings, if required.



[ - ]
Comment by stephanebSeptember 18, 2012
[ - ]
Comment by muneebziaaSeptember 22, 2012
hi can you help in Xilinx Virtex4 ML403 board???
[ - ]
Comment by cfeltonSeptember 22, 2012
That is a fairly generic request and not related to this post? Is there something specific @muneebziaa is looking for? Does the ML403 have an audio codec?
[ - ]
Comment by muneebziaaSeptember 22, 2012
yes i know but i am tired of finding detail about this on the internet. yes it have an AC97 codec. please if you can help me I'll be thank full to you.
[ - ]
Comment by cfeltonSeptember 22, 2012
I plan on posting a similar information for an AC97 compatible audio codecs in the next post. That might be of use.
[ - ]
Comment by cfeltonSeptember 22, 2012
The idea is the simple audio effect that is being created can be used on a plethora of hardware development systems.
[ - ]
Comment by muneebziaaSeptember 22, 2012
k can you tell me where I can find detail about this board????
[ - ]
Comment by muneebziaaSeptember 22, 2012
"The idea is the simple audio effect that is being created can be used on a plethora of hardware development systems." CAN YOU BE MORE SPECIFIC?

actually i want to use this broad for my final year project, and i am tired of finding about the procedure used for audio processing.
[ - ]
Comment by cfeltonSeptember 22, 2012
I think I know what you are talking about. If you search/google AC97 you usually find information about PC software drivers etc. I don't know what a refined search might find, e.g. "FPGA AC97". In either way the post with the AC97 information will be a couple days/weeks away. But you can get information about the specific chip from Analog devices.
[ - ]
Comment by muneebziaaSeptember 23, 2012
i dont have that much time, well thank you bro for your help :)

To post reply to a comment, click on the 'reply' button attached to each comment. To post a new comment (not a reply to a comment) check out the 'Write a Comment' tab at the top of the comments.

Please login (on the right) if you already have an account on this platform.

Otherwise, please use this form to register (free) an join one of the largest online community for Electrical/Embedded/DSP/FPGA/ML engineers: