AVR270: USB Mouse Demonstration

AVR270: USB Mouse Demonstration
AVR298: USB Audio Demonstration with
ATmega32(16)U4
Features
•
•
•
•
•
Runs with ATMega32U4 Microcontrollers at 8MHz
USB Low Power Bus Powered Device (less then 100mA)
Supported by any PC running Windows® (98SE or later), Linux® or Mac OS®.
Less than 14Kbytes of Code Required
USB device with audio speaker and audio microphone
8-bit
Microcontrollers
Application Note
1. Introduction
This document describes a simple audio project. It allows to quickly test USB hardware using the ATMega32U4 without any driver installation.
The reader should be familiar with USB Software Library for AT90USBxxx Microcontrollers (doc 7675, included in the CD-ROM & Atmel website) and the AUDIO
specification (http://www.usb.org/developers/devclass_docs/audio10.pdf).
7820A–AVR–11/08
2. Hardware Requirements
The USB audio application requires the following hardware:
• AVR USB evaluation board (ATEVK527)
• AVR USB microcontroller
• USB cable (Standard A to Mini B)
• PC running on Windows® (98SE, ME, 2000, XP), Linux ® or MAC® OS with an USB 1.1 or 2.0
host
• headset
3. In-System programming and Device Firmware Upgrade
To program the device you can use the following methods:
• The JTAG interface using the JTAGICE mkII
• The SPI interface using the AVRISP mkII and JTAGICE mkII
• The USB interface thanks to the factory DFU bootloader and FLIP(1) software
• The parallel programming using the STK®500 or STK®600
Please refer to the hardware user guide of the board you are using to see how to program the
device using these different methods.
Please refer to FLIP(1) help content to see how to install the USB driver and program the device
through the USB interface.
Note:
2
1. FLIP is software provided by atmel to allow the user to program the Atmel devices through the
USB interface (No external hardware required) thanks to the factory DFU bootloader.
AVR298
7820A–AVR–11/08
AVR298
4. Quick Start
Once your device is programmed with EVK527-ATMega32U4-usbdevice_audio.a90 or EVK527ATMega32U4-usbdevice_audio.hex file, you can start the audio demonstration. Check that your
device is enumerated as an audio controller (see figure 11), then you can use the kit as an audio
speaker and audio microphone.
Figure 4-1.
Audio Enumeration
The figure below shows the ATEVK527 used for the demo:
Figure 4-2.
Demonstration Board
USB
Board power = 3V
Microphone
Speakers
3
7820A–AVR–11/08
5. Application Overview
The USB audio application manages the data exchange between the PC and the PWM hardware (speaker) and ADC hardware (microphone). When a sound is played on the PC, the USB
device receives a periodic unsynchronized OUT endpoints, and when the record microphone is
running then the USB device receives a periodic unsynchronized IN endpoints.
Figure 5-1.
Application data exchange
OUT endpoint
PC play
PWM
PCM 16bits mono at 32KHz
Speaker
9bits mono at 32KHz
IN endpoint
PC record
ADC
PCM 16bits mono at 8KHz
Microphone
8bits mono at 8KHz
During the USB enumeration, the USB device describes the frequency and the formats of the
audio data. In the demo, the data format used is the PCM, the speaker uses 16-bit mono at
32KHz, and the microphone uses 16-bit mono at 8KHz.
4
AVR298
7820A–AVR–11/08
AVR298
6. Firmware
As explained in the USB Software Library for AT90USBxxx Microcontrollers document (doc
7675) all USB firmware packages are based on the same architecture. This section is dedicated
to the audio module only. The customization of the files described hereafter allows the user to
build his own audio application.
Figure 6-1.
USB Audio Firmware Architecture
5
7820A–AVR–11/08
6.1
audio_task.c
This file contains :
• timers initialization
• timers interrupts
• routines which collect and put audio data
Speaker
The main audio task gets the audio samples from endpoint OUT and put it in the RAM buffer.
The OSC value tolerance doesn't allow to have an exact 32KHz frequency for the speaker, so
the main loop adjusts the timer 1 interrupt to avoid losing a sample or underrun.
Timer 1 interrupt transfers the audio data from RAM to PWM (high speed timer). Timer 1 is
responsible for adjusting data flow with PWM bits resolution and volume requested by USB host.
Note:
We use only 9 bits out of the 10 bits from PWM to avoid saturation of Operational Amplifier.
Microphone
Timer 0 interrupt is used to get the ADC value each 125µs (8KHz) and if the “endpoint IN” is
requested by the USB host, the value is put in this endpoint.
Figure 6-2.
USB
Speaker
OUT endpoint
USB
Microphone
6.2
Application data exchange
Audio task
RAM buffer
Interrupt
Timer 1
IN endpoint
Interrupt
PWM
timer high speed
ADC
Timer 0
evk_527.c.
This file contains all the routines to manage the EVK527 board ressources (Joystick, LEDs...).
The user should not modify this file when using the EVK527 board. Otherwise, he has to build
his own hadware management file.
6.3
usb_specific_request.c
This file contains the routine which receives the audio control requests, like volume level and
mute control.
6
AVR298
7820A–AVR–11/08
AVR298
6.4
usb_descriptor.c
The audio topology, which is put in USB descriptor, is explained in the AUDIO specification
(http://www.usb.org/developers/devclass_docs/audio10.pdf). The audio topology chose for this
demo is described in the following figure.
Figure 6-3.
Input Terminal N°1
Audio Function Topology from demo
Feature Unit N°2
Ouput Terminal N°3
1 channel
USB stream
Control volume and mute
Input Terminal N°4
Feature Unit N°5
Speaker
Ouput Terminal N°6
1 channel
Microphone
Control volume and mute
USB stream
7. PC Software
The USB audio application does not require any PC software. Under Windows®, you can use the
standard recorder “Sound Recorder” to try the microphone feature.
8. Limitations
If the speaker is running at 32KHz then recording and playback can’t be running at same time,
due to linited CPU bandwidth when clocked at 8MHz.
9. Related Documents
AVR USB Datasheet (doc 7766)
USB Software Library for AT90USBxxx Microcontrollers (doc 7675)
USB Audio class specification (www.usb.org)
7
7820A–AVR–11/08
Headquarters
International
Atmel Corporation
2325 Orchard Parkway
San Jose, CA 95131
USA
Tel: 1(408) 441-0311
Fax: 1(408) 487-2600
Atmel Asia
Room 1219
Chinachem Golden Plaza
77 Mody Road Tsimshatsui
East Kowloon
Hong Kong
Tel: (852) 2721-9778
Fax: (852) 2722-1369
Atmel Europe
Le Krebs
8, Rue Jean-Pierre Timbaud
BP 309
78054 Saint-Quentin-enYvelines Cedex
France
Tel: (33) 1-30-60-70-00
Fax: (33) 1-30-60-71-11
Atmel Japan
9F, Tonetsu Shinkawa Bldg.
1-24-8 Shinkawa
Chuo-ku, Tokyo 104-0033
Japan
Tel: (81) 3-3523-3551
Fax: (81) 3-3523-7581
Technical Support
[email protected]
Sales Contact
www.atmel.com/contacts
Product Contact
Web Site
www.atmel.com
Literature Requests
www.atmel.com/literature
Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any
intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL’S TERMS AND CONDITIONS OF SALE LOCATED ON ATMEL’S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY
WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT
OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no
representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications
and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided
otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel’s products are not intended, authorized, or warranted for use
as components in applications intended to support or sustain life.
© 2008 Atmel Corporation. All rights reserved. Atmel®, Atmel logo and combinations thereof, AVR® STK® and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Windows® and others are registered trademarks of Microsoft Corporation. Other terms and product names may be trademarks of others.
7820A–AVR–11/08
Mouser Electronics
Authorized Distributor
Click to View Pricing, Inventory, Delivery & Lifecycle Information:
Atmel:
ATMEGA32U4-MUR
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement