Sound Generation using the uPSD Sound Studio On uPSD32xx and Turbo uPSD33xx
The uPSD32xx and Turbo uPSD33xx devices, from STMicroelectronics, are ideally suited for the development and support of many commercial audio applications. Because of the high speed and performance of the uPSD, and the size of its internal Flash Memory, many audio applications can be designed as a one-chip solution, with all the advantages of very short development times, rapid prototyping, and low chip-count final designs, thereby saving development and production costs, and minimizing time-to-market. Typical applications include:
Answering machines Talking clocks Helpers for blind or disabled people Entrance Systems Automatic public information systems Fire-protection systems and fire-alarms Speech output from washing machine, freezer, and other white goods Toys
This application note deals with hardware and software issues, presenting the basic functions of the uPSD Sound Studio Library for the uPSD32xx and uPSD33xx. It also describes a Windows application for easy development, modification and generation of user source files. Notably, uPSD supports the technique of In Application Programming. Software and data can be equally easily updated, in the field, via a serial, USB, I 2C, SPI line or parallel connection.
August 2004
1/12
TABLE OF CONTENTS
HARDWARE ISSUES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Table 1. PWM (8-bit) Frequencies for some Commonly-used Oscillator Frequency Values. . . . . . 3 Figure 1. Simple Audio Out Design using uPSD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Figure 2. Direct Connection to the Speaker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 SOFTWARE ISSUES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 uPSD Sound Studio Windows Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Figure 3. uPSD Sound Studio Windows Application Main Window . . . . . . . . . . . . . . . . . . . . . . 5 Figure 4. uPSD Sound Studio Description of the Main Parts of the Main Window . . . . . . . . . . . . 6 Figure 5. uPSD Sound Studio Flash Memory Data Space Overflow . . . . . . . . . . . . . . . . . . . . . . . 7 Sound Studio Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Table 2. Approximate Length of Sound Files, Stored in the Internal uPSD Flash Memory . . . . . . . 8 DATA Memory Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Figure 6. Data Space, Memory Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 CODE Memory Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Figure 7. Code Space, Memory Map uPSD Sound Demonstration. . . . . . . . . . . . . . . . . . . . . . . 10 CONCLUSION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 REVISION HISTORY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Table 3. Document Revision History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2/12
HARDWARE ISSUES
The uPSD Sound Library uses 8-bit PWM (Pulse-Width-Modulation), giving 256 possible levels on channel 0 (or channels 0 and 1, in the case of stereo or bridge-type applications). The PWM unit is included as a feature of all uPSD3xxx devices. This module allows very easy implementation, high quality output, and low CPU utilization. Nearly everything is done by hardware; the CPU only has to set a new signal level at the appropriate time. The frequency of the PWM output, of the 8-bit PWM channels of the uPSD32xx, is:
For the highest PWM output frequency we choose prescalervalue = 0, giving fPWM=fOSC/512. Turbo uPSD33xx does not have the addition factor of 2. That is, the overall prescaling value on the uPSD33xx can be any value in the range, while that on the uPSD32xx ends up being restricted to even numbers. Consequently, the maximum PWM input frequency on the uPSD33xx can be twice as high as that on the uPSD32xx, namely fPWM=fOSC/256. Therefore the sound generation using Turbo uPSD33xx is potentially much better. Table 1. shows the value of fPWM for some commonly used values of fOSC. Table 1. PWM (8-bit) Frequencies for some Commonly-used Oscillator Frequency Values
fOSC (MHz) 20.000 22.118 uPSD32xx (prescaler = 0) 32.000 36.000 40.000 20.000 22.118 Turbo uPSD33xx 32.000 36.000 40.000 fPWM (kHz) 39.1 43.2 62.5 70.3 78.1 78.1 86.4 125.0 140.6 156.3
So, a Turbo uPSD33xx device, with a 40MHz oscillator, will give better than a 150kHz PWM frequency. So, when generating signals at fs = 8kHz, a very high quality signal can be obtained, using a simple lowpass filter connected to the PWM output, as shown in Figure 1..
3/12
AI09792
In fact, because of the high-current capability of the PWM port, in uPSD devices, the final design can be simplified to that shown in Figure 2.. The capacitor is present simply for DC decoupling, to avoid high current consumption and power-dissipation in the uPSD when the PWM port remains at logic High for a long time. However, the designer needs to check, first, whether this arrangement is suitable; normally, the use of a low-pass filter and audio amplifier, such as that of Figure 1., is recommended. Figure 2. Direct Connection to the Speaker
AI09793
4/12
SOFTWARE ISSUES
uPSD Sound Studio Windows Application Version 1.0 supports any uPSD32xx or uPSD33xx that has at least 256KBytes of Main Flash Memory. A uPSD with 128KBytes of Main Flash Memory can be used, if the application is small enough to be fitted into this space, provided that pairs of 16KByte pages are configured, in PSDsoft, to act as single 32KByte pages. PC and uPSD drivers have been developed, by ST, for supporting audio applications on Windows operating systems (Windows95/98/98SE/Millennium/2000/XP). This allows new audio applications to be developed extremely quickly, using a convenient and user-friendly graphic interface. It allows collections of WAV files to be assembled with ease, and allows for their signal processing, and generates the resultant HEX files for the Flash Memory sectors. Figure 3. shows the main window of the interface. Figure 3. uPSD Sound Studio Windows Application Main Window
5/12
Waveform of the selected item. In the case of a selected header, its content, in hexadecimal format, is displayed.
Button for generating the final HEX files for PSD Soft Express.
Final version of the HEX files, loaded into the appropriate Flash Memory sectors.
6/12
The program generates eight HEX files, named (HEX-file name)_B0 up to (HEX-file name)_B7. It also generates one text header file, (HEX-file name)_Bx.h, containing information about the stored items. This forms a base for the users playlist, and orientation, when any items are chosen to be played. It is also used as a header file. An example: // 0 - Address: 0,0x8000 - HEADER, Size:170 Bytes // 1 - Address: 0,0x80AA,Sampl.freq.: 11025Hz, size:7368 B(668ms), source filename:C:\upsd\TalkingClock\00.wav #define uPSD_SoundItem_00_WAV 1 // 26 - Address: 5,0xA6D1,Sampl.freq.: 11025Hz, size:11561 B(1048ms), source filename:C:\upsd\TalkingClock\the time is.wav #define uPSD_SoundItem_THE_TIME_IS_WAV 26
7/12
The uPSD Sound Library consists of the following main routines: void uPSDSoundStudio_Init(void) // Initializes sound studio, chiefly PWM and Timer2 void uPSDSoundStudio_PlayItem(unsigned char ItemOrder) // Plays selected item (order in Windows application) and waits until playback is finished. void uPSDSoundStudio_Silence(unsigned int DurationInMiliSeconds) // No playback for given time (also Item number 0). void uPSDSoundStudio_NoSound(void) // Stops playback immediately.
8/12
Page 0
Page 1
Page 2
Page 3
Page 4
Page 5
Page 6
Page 7
FFFFh
fs0
32KBytes uPSD (data) Main Flash
fs1
fs2
fs3
fs4
fs5
fs6
fs7
32KBytes uPSD (data) Main Flash
32KBytes 32KBytes uPSD uPSD (data) (data) Main Flash Main Flash
32KBytes 32KBytes uPSD uPSD (data) (data) Main Flash Main Flash
32KBytes 32KBytes uPSD uPSD (data) (data) Main Flash Main Flash
8000h 7FFFh
0000h
AI09794
9/12
FFFFh
(32KBytes Free)
csboot3 (4KBytes uPSD Secondary Flash, User Application Dependent) csboot2 (4KBytes uPSD Secondary Flash, User Application Dependent) csboot1 (4KBytes uPSD Secondary Flash, User Application Dependent) csboot0 (4KBytes uPSD Secondary Flash, User Application Dependent)
AI09795
The entire code memory is fully user application dependent and can be changed. The uPSD sound studio has no special requirements.
CONCLUSION
The uPSD32xx and Turbo uPSD33xx devices, from STMicroelectronics, are each highly flexible systemon-a-chip devices, containing a large internal Flash Memory. Many audio applications can be implementing as a one-chip solution. This makes for rapid prototyping, and a low chip-count for the final design. Thus, both development costs and production costs are minimized, and also the time-to-market. This application note has dealt with the main hardware and software issues, and has presented the basic functions of the uPSD Sound Studio Library. A Windows application was also briefly described, that has been written as a tool to facilitate the easy development, modification and generation of user source files.
10/12
REVISION HISTORY
Table 3. Document Revision History
Date 25-Aug-2004 Version 1.0 First Issue Revision Details
11/12
Information furnished is believed to be accurate and reliable. However, STMicroelectronics assumes no responsibility for the consequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. No license is granted by implication or otherwise under any patent or patent rights of STMicroelectronics. Specifications mentioned in this publication are subject to change without notice. This publication supersedes and replaces all information previously supplied. STMicroelectronics products are not authorized for use as critical components in life support devices or systems without express written approval of STMicroelectronics. The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners 2004 STMicroelectronics - All rights reserved STMicroelectronics group of companies Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan Malaysia - Malta - Morocco - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America www.st.com
12/12