0

I am trying to write a verilog code for FPGA which will output sound from the embedded "line out" pin. I use Quartus II and Altera DE1.

I am new to hardware programming, therefore it just takes too much time for me to catch up with basics. Apparently I need to initialize the wolfson chip and need to write something to communicate with it, as discussed here: http://www.alteraforum.com/forum/showthread.php?t=6005

It uses wolfson WM8731 codec, manual is in here: http://www.rockbox.org/wiki/pub/Main/DataSheets/WM8731_8731L.pdf

and an example I found but couldnt figured out how to use it is in here: https://code.google.com/p/vector06cc/wiki/SoundCodec

I have found bunch of examples about how to generate sounds using GPIO pins, but barely anything about the usage of WM8731. I would really appreciate any guidance or experience you might share.

ozgeneral
  • 6,079
  • 2
  • 30
  • 45
  • But I am looking for a verilog code for it, hardware is already there. Should I still move the question? – ozgeneral May 29 '15 at 01:32
  • @OE1 - are you using a Nios II CPU (and SOPC/Qsys) or working only in hardware? – wilcroft May 29 '15 at 02:14
  • Yes Altera DE1 uses Nios II CPU. I am programming an FPGA and trying to test my code using headphones to "line out" port of the FPGA. – ozgeneral May 29 '15 at 02:18

1 Answers1

3

Assuming you're using Nios II and either SOPC Builder or Qsys, the Altera University Program offers an IP core to control the Audio CODEC on the DE-Series boards.

If you don't already have it, you can download it here (at the bottom of the page, listed as University Program Installer): https://www.altera.com/support/training/university/materials-ip-cores.html

Once you install it, check the <altera-directory>/University_Program\NiosII_Computer_Systems\DE1\DE1_Media_Computer directory. app_software and app_software_HAL both give example methods to write to the audio output (using C code running on the Nios II), and the verilog or vhdl folder show example systems on connecting the core to a NIOS II using your preferred HDL.

The core itself can be found in <altera-directory>\ip\University_Program\Audio_Video. See also ftp://ftp.altera.com/up/pub/Altera_Material/14.1/University_Program_IP_Cores/Audio_Video/Audio.pdf for some (potentially) helpful reading/reference.


Addendum: All of the FPGA inputs and outputs use the "Digital Audio Interface" of the WM8731 chip. The pins available on the FPGA are as follows:

  • PIN_A6 : AUD_ADCLRCK
  • PIN_B6 : AUD_ADCDAT
  • PIN_A5 : AUD_DACLRCK
  • PIN_B5 : AUD_DACDAT
  • PIN_A4 : AUD_BCLK
  • PIN_B4 : AUD_XCK (MCLK on WM8731)

Output is sent to the CODEC on the AUD_DACDAT pin. The chip is configured using the I2C_SDAT and I2C_SCLK pins on I2C address 0x34 for read, and 0x35 for write. No other pins are available to the FPGA - some are used for external connections (like the mike or line-in), or are not connected at all. For a full list of pin assignments for the DE1 (which can be directly imported to Quartus) see: ftp://ftp.altera.com/up/pub/Altera_Material/12.1/Boards/DE1/DE1.qsf

wilcroft
  • 1,580
  • 2
  • 14
  • 20
  • Can I combine this method with quartus? I already have an existing project with VGA interface and the LUT for audio. So I just need to send the frequencies to "line out". Is it impossible to do with pin assignments or something similar? – ozgeneral May 29 '15 at 03:16
  • If you're using a Nios-based system, I'd recommend using the IP cores - they're easy to use, and will work for sure. Also, I've amended my answer (see above) to provide some more info about the pins - only some of the ports of the CODEC are connected to the FPGA - if the one you want to use isn't listed, then the FPGA can't access it. Hopefully that helps. – wilcroft May 29 '15 at 04:26
  • So, would it work if I only assign the output music to `AUD_DACDAT` , clock to `I2C_SCLK` and 0x35 on `I2C_SDAT` ? I am not sure if I understood correctly. – ozgeneral May 29 '15 at 04:53
  • The I2C is used to configure the CODEC, setting values for various parameters within it. I suggest reading the datasheet for more information. On the Digital Audio Interface, you need to provide, `AUD_DACDAT` (your output sound), `AUD_DACLRCK` (the DAC LR clock), `AUD_BCLK` (the bitstream clock), and `AUD_XCK` (the chip clock). – wilcroft May 29 '15 at 14:15