最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

ATmega32U4 USB音频示例说明书

IT圈 admin 23浏览 0评论

2024年10月30日发(作者:严新林)

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

uction

This document describes a simple audio project. It allows to quickly test USB hard-

ware using the ATMega32U4 without any driver installation.

The reader should be familiar with USB Software Library for AT90USBxxx Microcon-

trollers (doc 7675, included in the CD-ROM & Atmel website) and the AUDIO

specification (/developers/devclass_docs/).

8-bit

Microcontrollers

Application Note

7820A–AVR–11/08

re 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

-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: 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.

2

AVR298

7820A–AVR–11/08

AVR298

Start

Once your device is programmed with EVK527-ATMega32U4-usbdevice_audio.a90 or EVK527-

ATMega32U4-usbdevice_ 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 Enumeration

The figure below shows the ATEVK527 used for the demo:

Figure tration Board

USB

Microphone

Speakers

Board power = 3V

7820A–AVR–11/08

3

ation Overview

The USB audio application manages the data exchange between the PC and the PWM hard-

ware (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 ation data exchange

OUT endpoint

PC play

PCM 16bits mono at 32KHz

PWM

Speaker

9bits mono at 32KHz

IN endpoint

PC record

PCM 16bits mono at 8KHz

ADC

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

re

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 Audio Firmware Architecture

5

7820A–AVR–11/08

6.1audio_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 ation data exchange

USB

Speaker

OUT endpoint

Audio taskRAM buffer

Interrupt

Timer 1

PWM

timer high speed

USB

Microphone

6.

IN endpoint

Interrupt

Timer 0

ADC

This file contains all the routines to manage the EVK527 board ressources (Joystick, ).

The user should not modify this file when using the EVK527 board. Otherwise, he has to build

his own hadware management file.

6.3usb_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.4usb_descriptor.c

The audio topology, which is put in USB descriptor, is explained in the AUDIO specification

(/developers/devclass_docs/). 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°2Ouput Terminal N°3

1 channel

USB streamControl volume and muteSpeaker

Input Terminal N°4Feature Unit N°5Ouput Terminal N°6

1 channel

MicrophoneControl volume and muteUSB stream

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.

tions

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.

d Documents

AVR USB Datasheet (doc 7766)

USB Software Library for AT90USBxxx Microcontrollers (doc 7675)

USB Audio class specification ()

7

7820A–AVR–11/08

Headquarters

Atmel Corporation

2325 Orchard Parkway

San Jose, CA 95131

USA

Tel: 1(408) 441-0311

Fax: 1(408) 487-2600

International

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-en-

YvelinesCedex

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

Product Contact

Web Site

Technical Support

*************

Sales Contact

/contacts

Literature Requests

/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

intellectualproperty right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL’S TERMS AND CONDI-

TIONS 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 INCIDEN-

TAL 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

representationsor 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 sustainlife.

© 2008 Atmel Corporation. All rights reserved. Atmel®, Atmel logo and combinations thereof, AVR® STK® and others are registered trademarks or trademarks of Atmel Cor-

poration 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

2024年10月30日发(作者:严新林)

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

uction

This document describes a simple audio project. It allows to quickly test USB hard-

ware using the ATMega32U4 without any driver installation.

The reader should be familiar with USB Software Library for AT90USBxxx Microcon-

trollers (doc 7675, included in the CD-ROM & Atmel website) and the AUDIO

specification (/developers/devclass_docs/).

8-bit

Microcontrollers

Application Note

7820A–AVR–11/08

re 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

-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: 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.

2

AVR298

7820A–AVR–11/08

AVR298

Start

Once your device is programmed with EVK527-ATMega32U4-usbdevice_audio.a90 or EVK527-

ATMega32U4-usbdevice_ 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 Enumeration

The figure below shows the ATEVK527 used for the demo:

Figure tration Board

USB

Microphone

Speakers

Board power = 3V

7820A–AVR–11/08

3

ation Overview

The USB audio application manages the data exchange between the PC and the PWM hard-

ware (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 ation data exchange

OUT endpoint

PC play

PCM 16bits mono at 32KHz

PWM

Speaker

9bits mono at 32KHz

IN endpoint

PC record

PCM 16bits mono at 8KHz

ADC

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

re

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 Audio Firmware Architecture

5

7820A–AVR–11/08

6.1audio_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 ation data exchange

USB

Speaker

OUT endpoint

Audio taskRAM buffer

Interrupt

Timer 1

PWM

timer high speed

USB

Microphone

6.

IN endpoint

Interrupt

Timer 0

ADC

This file contains all the routines to manage the EVK527 board ressources (Joystick, ).

The user should not modify this file when using the EVK527 board. Otherwise, he has to build

his own hadware management file.

6.3usb_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.4usb_descriptor.c

The audio topology, which is put in USB descriptor, is explained in the AUDIO specification

(/developers/devclass_docs/). 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°2Ouput Terminal N°3

1 channel

USB streamControl volume and muteSpeaker

Input Terminal N°4Feature Unit N°5Ouput Terminal N°6

1 channel

MicrophoneControl volume and muteUSB stream

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.

tions

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.

d Documents

AVR USB Datasheet (doc 7766)

USB Software Library for AT90USBxxx Microcontrollers (doc 7675)

USB Audio class specification ()

7

7820A–AVR–11/08

Headquarters

Atmel Corporation

2325 Orchard Parkway

San Jose, CA 95131

USA

Tel: 1(408) 441-0311

Fax: 1(408) 487-2600

International

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-en-

YvelinesCedex

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

Product Contact

Web Site

Technical Support

*************

Sales Contact

/contacts

Literature Requests

/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

intellectualproperty right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL’S TERMS AND CONDI-

TIONS 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 INCIDEN-

TAL 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

representationsor 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 sustainlife.

© 2008 Atmel Corporation. All rights reserved. Atmel®, Atmel logo and combinations thereof, AVR® STK® and others are registered trademarks or trademarks of Atmel Cor-

poration 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

发布评论

评论列表 (0)

  1. 暂无评论