ECE 354 Spring 2006 - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

ECE 354 Spring 2006

Description:

Write both Verilog modules and C code. Use custom Verilog modules ... Play time elapsed indicator?? Be creative! This board has a lot of options. 23. ECE 354 ... – PowerPoint PPT presentation

Number of Views:151
Avg rating:3.0/5.0
Slides: 24
Provided by: bendo9
Category:
Tags: ece | playtime | spring

less

Transcript and Presenter's Notes

Title: ECE 354 Spring 2006


1
ECE 354Spring 2006
  • Lab 5 Using the WM8731
  • Developed by Ben Doherty

2
In this lab, you will
  • Use a simple solid-state, flash memory file
    system (ZipFS)
  • Operate the WM8731 audio CODEC chip
  • Write both Verilog modules and C code
  • Use custom Verilog modules along side the NIOS
    core
  • Use C to interact with external Verilog modules

3
System Overview
4
Overview
  • Create a design that can play tones using sine
    waves and the math.h library
  • Use the switches to change the frequencies
  • Press a button to play tone
  • Volume control using buttons
  • Interface with the WM8731 Audio CODEC
    (Encoder/Decoder)
  • MPU interface
  • Audio Interface

5
Using the WM8731 Audio CODEC
  • Configured via Software Control Interface
  • MPU Interface
  • There is no SOPC component to drive the
    interface, so it must be done in software (using
    PIO,) or with a custom Verilog module
  • Audio samples are sent via the Audio Interface
  • No SOPC component for this either
  • USB/Normal mode master clock (AUD_XCLK, from
    which AUD_BCLK is generated)
  • USB mode must have a FIXED AUD_XCLK of 12MHz,
    which can be easily obtained from a PLL in the
    SOPC system
  • Normal mode requires AUD_XCLK clocks of either
    12.288MHz (8kHz, 32kHz, 48kHz, 96kHz) or
    11.2896MHz (44.1kHz, 88.2kHz)

6
Audio Stream Format
  • Serial bit stream, I2C format
  • Format is software configurable, but I2C is
    default (and has the easiest timing)
  • Sampling data is interleaved, selected by DACLRCK
  • AUD_BCLK and AUD_DACLRCK is generated by the
    CODEC (in MASTER mode,) or by your system (CODEC
    in SLAVE mode)
  • Period of AUD_DACLRCK is 1/sampling_rate
  • Period of AUD_BCLK is fixed. Try to get as close
    as possible to one of 11.2896MHz, 12.288MHz,
    16.9344MHz or 18.432MHz(Normal mode) and
    12MHz(USB mode) Sampling rate is derived from
    these clocks
  • Use a PLL!

7
Audio Stream Format (cont.)
  • Your Audio Interface module should
  • Convert N-bit wide sample from PIO into I2C
    serial format
  • The value of N is up to you 32 is probably best
    (two 16-bit wide channels)
  • The WM8731 always plays 16-bit samples, padding
    or truncating differing sample widths
  • Either generate AUD_BCLK and AUD_DACLRCK (CODEC
    in SLAVE mode,) or accept AUD_BCLK and
    AUD_DACLRCK from CODEC (CODEC in MASTER mode)

8
Audio Stream Considerations
  • How do you know the module is ready for a new
    sample?
  • AUD_DACLRCK accepts on sample per period
  • How should your module generate the proper
    clocks?
  • Generating and multiplexing multiple clocks is a
    very useful Verilog technique
  • You wont always be dividing by factors of 2!!
  • Thus you cant just pull a clock from some bit in
    a counter
  • It may be possible to write the audio driver in
    software but it needs to have very precise timing
    which is not guaranteed!

9
A Bigger Picture (Audio Interface)

BCLK DACLRCK DACDAT
BCLK DACLRCK DACDAT
10
WM8731 MPU Interface
  • The WM8731 is a WRITE-ONLY device, any requests
    to read are ignored
  • Device is configured by writing data to registers
  • Transfer initiated by pulling MPU_DATA low while
    MPU_CLK is high
  • 3-byte transfers
  • Byte 1 ADDR7..0
  • ADDR7..0 is DEVICE ADDRESS, which is ALWAYS
    0x34
  • Last bit is R/W bit, which is always 0 (write,)
    since WM8731 is write-only
  • Byte 2 REG6..0,DATA8
  • REG6..0 is 7-bit register address, DATA8 is
    MSB of 9-bit DATA
  • Byte 3 DATA7..0
  • Lower 8 bits of 9-bit DATA

11
WARNING USERS MANUAL IS WRONG!!

12
WM8731 MPU Interface (cont.)
  • MPU_DATA is driven low by the CODEC between bytes
    as confirmation
  • This will require a bi-directional pin
  • Verilog Hint
  • wire MPU_DATA SDIN ? 1'bz 0
  • Pin is wired to VCC via a pull-up resistor on the
    DE2 What does setting MPU_DATA to Z do?
  • The SPI-2-MPU module should convert 2 one-byte
    SPI messages into the MPU format
  • Store and forward Register/Data values
  • First byte is always fixed!
  • The SPI HAL cant support SPI transfers greater
    than 8 bits, so two messages must be sent

13
WM8731 Configuration
  • Use wm8731.h from website for register name
    definitions
  • What needs to be configured?
  • Reset device Write 0x00 to AUDIO_RESET
  • Power up device AUDIO_POWER_DOWN_CTL
  • Activate interfaces AUDIO_ACTIVE_CTL
  • Disable Line IN -gt Line OUT bypass, select DAC on
    Line OUT AUDIO_ANALOG_PATH_CTL
  • Disable DAC soft mute AUDIO_DIGITAL_PATH_CTL
  • Turn on MASTER mode AUDIO_INTERFACE_FMT
  • Headphone Out (i.e., line out,) volume
    AUDIO_LEFT,RIGHT_HP_OUT
  • Can be set simultaneously by setting LRHPBOTH bit

14
Tips for Starting
  • MPU interface first
  • Need to be able to control the CODEC before you
    can test the audio stream
  • Make it easy on yourself
  • Generate as few signals as you can
  • Mono might be easier at first
  • Use sufficient ACKs
  • One way to know your verilog module works is if
    it ACKs to you on a PIO
  • Use GPIO pins
  • Monitor lines via these pins then use go logic to
    trace them
  • Dont try for the wav player until you can play
    sine waves
  • Having a file system doesnt do much good if you
    cant play it

15
Optional - Flash File System
  • Requires CFI Flash and Avalon Tri-State bridge
    SOPC Builder components
  • Simple file system based on uncompressed ZIP
    files
  • Allows for easy access to files using ANSI C file
    routines
  • FILE wav fopen(/mnt/zipfs/foobar.wav, r)

16
Optional - Setting up ZipFS
  • Create an UNCOMPRESSED .zip file from the set of
    files of your choice
  • In the file explorer, select your files/folders,
    click on Add to Zip
  • Specify filename
  • Set compression level to None
  • Move .zip file to the system library folder of
    your Nios II IDE project. One way you can do
    this
  • Right-click on the _syslib top level folder of
    your project
  • Select Import
  • Select File System and click Next
  • Browse to containing folder of .zip file
  • Select .zip file from list in right hand pane
  • Click Finish

17
Optional - Setting up Zip FS (cont.)
  • Enable the Zip FS in the System Library
  • Open System Library Properties (In Properties
    dialog)
  • Click on Software Components
  • Choose Altera Zip Read-Only File System
  • Select Add this software component
  • Specify zip file and mount point
  • Mount point is root of files, leave as
    /mnt/rozipfs or /mnt/zipfs if you choose
  • Select OK, go back to main screen

18
Optional - Writing Zip FS to Flash
  • Make sure your zip file is UNCOMPRESSED, and is
    in the system library directory
  • Go to Tools-gtFlash Programmer
  • Select ONLY Program a file into flash memory
  • Select your zip file
  • Click Program Flash
  • Files can now be accessed using ANSI C fopen()
    and fread() functions

19
Optional - Parsing .wav files
  • Wav files are a modified version of the RIFF
    standard
  • First 4 bytes are RIFF,
  • Next 4 bytes are length of file
  • Next 4 bytes are WAVE
  • File divided into chunks
  • Chunk Header 4 byte name, 4 byte length
  • fmt (notice space) defines format of wav file
  • Usually, but not required to be first chunk
  • See wave.h for relevant structures
  • data chunk contains audio data

20
Optional - Parsing .wav files (cont.)
  • Algorithm
  • Verify RIFF file header denotes WAVE file
  • Read in Chunk Header
  • fread(header, 1, sizeof(struct chunk_head),
    wav)
  • Check if fmt chunk
  • if(strncmp(header.ChunkID, fmt , 4) 0)
  • Read in format chunk structure
  • struct fmt_chunk fmt
  • fread(fmt, 1, sizeof(struct fmt_chunk), wav)
  • Determine sampling rate, number of channels and
    sample width. Calculate sample frame size and
    allocate memory for sample frame buffer
    (malloc())
  • Read chunks until data chunk found (Usually
    next)
  • Read in sample frames and feed to CODEC
  • CODEC requires stereo input if only one channel
    in file, duplicate left and right channels

21
Experiments
  • The WM8731 can not play all the sampling rates
    you are likely to find in .wav files from the
    internet (Like 11.25kHz)
  • What happens if you play an audio stream at a
    greater sampling rate?
  • What about at a lesser sampling rate?
  • Sample resolutions also affect the sound of your
    files
  • How does 8-bit sound differ from 16-bit sound?
  • Gotcha Bit clock may need to be inverted for
    some sample widths (BCLKINV ON for 8-bit, BCLKINV
    OFF for 16-bit)

22
Optional - Caveats
  • The Avalon bus used on the NIOS II is relatively
    slow, and its certainly not fast or wide enough
    to play a stream at a sampling rate over 8kHz
  • Ways around this include
  • Creating your own SOPC component
  • Creating a separate component to pipe the data
    directly from the Flash memory unit
  • Therefore, your design must be able to play at
    least 8KHz audio streams
  • Bonus points if you can get higher sampling rates
    to play correctly!
  • UI is unimportant, but a sleek interface will win
    bonus points
  • Asynchronous volume control is essential
  • File selection using LCD screen?
  • Flashing lights? Play time elapsed indicator??
  • Be creative! This board has a lot of options.

23
References
  • Wolfson Micro WM8731 Audio CODEC
    Datasheethttp//www.wolfsonmicro.com/uploads/docu
    ments/en/WM8731.pdf
  • Nios II Software Developers Handbookhttp//www.im
    it.kth.se/courses/2B1448/docs/n2sw_nii5v2.pdf
  • Nios II Peripherals and Interfaceshttp//www.alte
    ra.com/products/ip/processors/nios2/features/ni2-p
    eripherals.html
  • Wave file formathttp//www.borg.com/jglatt/tech/
    wave.htm
  • Newlib LibC Referencehttp//vmlinux.org/crash/mir
    ror/www.objsw.com/docs/libc_toc.html
  • Terasic DE2 Discussion Forumhttp//www.terasic.co
    m.tw/cgi-bin/page/forum.pl?LanguageEnglishNo1
Write a Comment
User Comments (0)
About PowerShow.com