Virtex II Pro -- AC97 codec Help

Discussion in 'Embedded Systems and Microcontrollers' started by Jorgy, Nov 17, 2009.

  1. Jorgy

    Thread Starter New Member

    Oct 10, 2009

    I am currently working on a project using the Virtex II Pro and I am having some trouble with the ac97 codec. I am trying to create a program where I can simply record with a mic at a push of the UP button, and have it output through AMP-OUT with a pair of headphones connected when the DOWN button is pressed. As far as my understanding goes, to record something through the mic you must use the command XAC97_ReadFifo(XPAR_AUDIO_CODEC_BASEADDR), and to play it back the command XAC97_WriteFifo(XPAR_AUDIO_CODEC_BASEADDR). I currently have the following source code:

    #define BTN_RIGHT 0x0001
    #define BTN_LEFT 0x0002
    #define BTN_DOWN 0x0004
    #define BTN_UP 0x0008
    #define BTN_CENTER 0x0010
    #define SAMPLE Xuint32
    #define SAMPLE_SIZE 200000
    #include "xparameters.h"
    #include "stdio.h"
    #include "xbasic_types.h"
    #include "xgpio.h"
    #include "gpio_header.h"
    #include "xio.h"
    #include "xac97_l.h"
    #include "xutil.h"

    void checkmic(void);

    XGpio push;
    int main (void) {

    XGpio_Initialize(&push, XPAR_PUSHBUTTONS_5BIT_DEVICE_ID);
    XGpio_SetDataDirection(&push, 1, 0x0000001F);

    xupv2p_ac97_init(); //Initalizing AC97



    void checkmic(void){
    int i, sampleCnt=0;

    Xuint32 recorded;
    Xuint32 pressed = 0;

    pressed = XGpio_DiscreteRead(&push, 1);

    if (~pressed & BTN_UP){


    print("-- recording --\r\n");
    while(sampleCnt < SAMPLE_SIZE)
    sample[sampleCnt] = XAC97_ReadFifo(XPAR_AUDIO_CODEC_BASEADDR);
    sample[sampleCnt] = recorded;

    print("-- done --\r\n");

    if (~pressed & BTN_DOWN){
    print("--Playing sample -\r\n");
    for(i=0; i< SAMPLE_SIZE; i++){
    XAC97_WriteFifo(XPAR_AUDIO_CODEC_BASEADDR, recorded);

    I am currently able to record, but when I press the DOWN button to playback the recorded data I am just getting noise from the headphones. Could someone please give me a push in the right direction where I am a newbie at this and still learning with FPGA's. Thank you in advance.
  2. Jorgy

    Thread Starter New Member

    Oct 10, 2009
    Basically all I really want to know is where and how the audio input is stored. Below is the block diagram for the LM4550 chip on the board which contains the ac97.


    When I talk into the mic (through MIC1) I can get only get a direct output through Line_out and this is beacuse both the MIC and LINE_OUT are enabled in the xupv2p_ac97_init(); function. Is there a register that the input through the mic is stored, and if so how can I access it? Or does the MIC input get sent out through the SDATA_IN?
    I am sorry if I am being too persistent, but this is for a final class project in which the due date is approaching. If anyone can give me ANY advice on what to do or what to try I would gladly appreciated it.