AN2007 APPLICATION NOTE Sound Generation using the upsd Sound Studio On upsd32xx and Turbo upsd33xx

AN2007 APPLICATION NOTE Sound Generation using the uPSD Sound Studio On uPSD32xx and Turbo uPSD33xx The uPSD32xx and Turbo uPSD33xx devices, from STMi...
0 downloads 0 Views 172KB Size
AN2007 APPLICATION NOTE 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

AN2007 - APPLICATION NOTE

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

AN2007 - APPLICATION NOTE

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:

f OSC f O SC ⁄ 512 f PWM = -------------------------------------------------------------- = --------------------------------prescaler + 1 ( prescaler + 1 ) × 2 × 256

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

uPSD32xx (prescaler = 0)

Turbo uPSD33xx

fOSC (MHz)

fPWM (kHz)

20.000

39.1

22.118

43.2

32.000

62.5

36.000

70.3

40.000

78.1

20.000

78.1

22.118

86.4

32.000

125.0

36.000

140.6

40.000

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

AN2007 - APPLICATION NOTE The cutoff frequency is given by fcutoff=1/(2πRC). So, for a 4kHz cutoff frequency with a 1kΩ resistor, we need a capacitor of about 40nF. When some low-cost ceramic capacitor is used, its capacitance can be between 22 and 47nF. Figure 1. Simple Audio Out Design using uPSD

Audio-Out (amplifier) PWMx R

R

µPSD

C

C

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

100µF PWMx

+

µPSD Headphones or Loudspeaker (Z >= 50 ohm)

AI09793

4/12

AN2007 - APPLICATION NOTE

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

AN2007 - APPLICATION NOTE Figure 4. describes the main parts of the main window of the uPSD Sound Studio version 1.0 application. Each part provides its own help or hint message, which can be obtained by pointing the mouse cursor at the appropriate point on the screen. Figure 4. uPSD Sound Studio – Description of the Main Parts of the Main Window Number (order) of sound item, passed as a parameter to the playback function.

List of all the included WAV files, their format, size, duration, source file, and start address in virtual Flash Memory.

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.

6/12

Additional signal processing applied to all the loaded WAV files.

Additional signal processing can be applied to the selected (highlighted) item (use the right mouse button).

Final version of the HEX files, loaded into the appropriate Flash Memory sectors.

AN2007 - APPLICATION NOTE The user’s application can be started by clicking on the “Load project” button, or from the menu item to load and modify an existing project. Any WAV item can be modified, deleted, moved, or a new item added. The main window shows the current state of the virtual uPSD Flash Memory, and the memory locations of all the constituent items. The information is refreshed and/or recounted after each operation. If some of items cannot be fitted into the uPSD’s memory, they are automatically highlighted in red. It can be deleted or modified (re-sampled), to try to make it fit in the internal Flash Memory, using any internal or external tools. The final HEX files can be generated only when all of the items fit in the Flash Memory. Once added, each WAV file is automatically stored in the project file. It is not needed to be distributed separately with the user’s program files. Figure 5. uPSD Sound Studio – Flash Memory Data Space Overflow

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 user’s 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

AN2007 - APPLICATION NOTE Sound Studio Library The uPSD Sound Library consists of two files: a C source file, and a header file. It uses Timer2, of the uPSD, for the generation of interrupts. It allows all the sounds to be played as a background task, while executing the main application program. The full source code is included in the distribution pack, and can be modified to use any of other suitable facilities of the uPSD, Turbo uPSD or Turbo uPSD, or to meet any other customer application needs. Because of an equidistant sample distribution has been used, Timer2 interrupts should have the highest priority and global interrupt flags should be set all the time. Any delay can cause interruption to, and distortions of, the generated sound. The CPU load depends on the uPSD’s oscillator frequency, and the WAV source file sampling frequency. Normally, it is below 10%. The value of FREQ_OSC, in the upsd_hardware.h file, should be changed to corresponding to actual oscillator frequency of the user’s hardware. Failure to do so will cause the audio output to be played at a different speed. Table 2. shows the duration of audio output that can be stored in the uPSD device, assuming that it has 256KByte of main Flash Memory. In some special cases, depending on the compression used, up to two minutes of sound can be stored. Table 2. Approximate Length of Sound Files, Stored in the Internal uPSD Flash Memory Sampling Frequency (kHz)

Pure WAV (s)

Modified (IMA) ADPCM Compression (s)

Special Compression (speech) (s)

8.000

32.8

65.5

114.7

11.025

23.8

47.6

83.2

12.000

21.8

43.7

76.5

16.000

16.4

32.8

57.3

22.050

11.9

23.8

41.6

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

AN2007 - APPLICATION NOTE The following routines are proprietary: static void MAIN_INT_ISR (void) - The main interrupt routine. void uPSDSoundStudio_PlayItemSpec(unsigned char ItemOrder, unsigned int UserData) This is the main playback routine. It is called by each of the previously mentioned routines. ItemOrder points to the desired WAV file or item. A zero means silence, with UserData indicating the duration, in milliseconds. If ItemOrder is equal to, or higher than 128, the routine starts playback, and returns to the beginning. Otherwise, it waits until the end of playback. As an example, the following demonstration will say, ‘00420’. uPSDSoundStudio_Init(); uPSDSoundStudio_PlayItem(0 +1); uPSDSoundStudio_Silence(200); uPSDSoundStudio_PlayItem(0 +1); uPSDSoundStudio_Silence(200); uPSDSoundStudio_PlayItem(4 +1); uPSDSoundStudio_Silence(200); uPSDSoundStudio_PlayItem(2 +1); uPSDSoundStudio_Silence(200); uPSDSoundStudio_PlayItem(0 +1); DATA Memory Map Figure 6. shows the memory map of the data space that is required for proper functioning of the uPSD Sound Studio Library. The data space is divided into an upper and lower part (each with a 32KByte address space). The upper part is dedicated to the sound source data area (256KBytes in total), each page being selected by the Page Register in the uPSD. Figure 6. Data Space, Memory Map

Page 0

Page 1

Page 2

fs1

fs2

Page 3

Page 4

Page 5

Page 6

Page 7

FFFFh

fs0 32KBytes uPSD (data) Main Flash

32KBytes 32KBytes uPSD uPSD (data) (data) Main Flash Main Flash

fs3

fs4

32KBytes 32KBytes uPSD uPSD (data) (data) Main Flash Main Flash

fs5

fs6

32KBytes 32KBytes uPSD uPSD (data) (data) Main Flash Main Flash

fs7 32KBytes uPSD (data) Main Flash

8000h 7FFFh

SRAM and CSIOP (user application dependent)

0000h AI09794

9/12

AN2007 - APPLICATION NOTE For proper functioning of the uPSD Sound Studio, only the upper half of the memory address space (32KByte) should be allocated as shown in Figure 6.. The lower half is completely user application dependent, and free for use by the application. The uPSD sound demonstration and libraries do not use any XDATA RAM. All variables are present in the register data address area. CODE Memory Map The memory map of the code space is fully user-application dependent. In the uPSD sound demonstration, the code space memory map is as shown in Figure 7.. Figure 7. Code Space, Memory Map – uPSD Sound Demonstration

FFFFh

(32KBytes Free)

8000h 7FFFh (16KBytes Free) 4000h 3000h 2000h 1000h 0000h

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

AN2007 - APPLICATION NOTE

REVISION HISTORY Table 3. Document Revision History Date 25-Aug-2004

Version 1.0

Revision Details First Issue

11/12

AN2007 - APPLICATION NOTE

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