Upload
dan-esenther
View
216
Download
0
Embed Size (px)
Citation preview
8/13/2019 Sound Generation Using the uPSD Sound Studio on uPSD32xx and Turbo uPSD33xx-CD00041580
1/12
1/12August 2004
AN2007
APPLICATION NOTE
Sound Generation using the uPSD Sound StudioOn uPSD32xx and Turbo uPSD33xx
The uPSD32xx and Turbo uPSD33xx devices, from STMicroelectronics, are ideally suited for the devel-
opment 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-mar-
ket.
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, I2C, SPI line or parallel connection.
8/13/2019 Sound Generation Using the uPSD Sound Studio on uPSD32xx and Turbo uPSD33xx-CD00041580
2/12
2/12
AN2007 - APPLICATION NOTE
TABLE OF CONTENTS
HARDWARE ISSUES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Table 1. PWM (8-bit) Frequencies for some Commonly-used Oscillator Frequency Values. . . . . . 3Figure 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
8/13/2019 Sound Generation Using the uPSD Sound Studio on uPSD32xx and Turbo uPSD33xx-CD00041580
3/12
3/12
AN2007 - APPLICATION NOTE
HARDWARE ISSUESThe uPSD Sound Library uses 8-bit PWM (Pulse-Width-Modulation), giving 256 possible levels on chan-
nel 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 fPWMfor some commonly used values of fOSC.
Table 1. PWM (8-bit) Frequencies for some Commonly-used Oscillator Frequency Values
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 low-
pass filter connected to the PWM output, as shown in Figure 1..
fOSC(MHz) fPWM(kHz)
uPSD32xx(prescaler = 0)
20.000 39.1
22.118 43.2
32.000 62.5
36.000 70.3
40.000 78.1
Turbo uPSD33xx
20.000 78.1
22.118 86.4
32.000 125.0
36.000 140.6
40.000 156.3
fPW MfOS C
p re sc a le r 1+( ) 2 256---------------------------------------------------------------
fO SC 512
p re sc al er 1+---------------------------------= =
8/13/2019 Sound Generation Using the uPSD Sound Studio on uPSD32xx and Turbo uPSD33xx-CD00041580
4/12
4/12
AN2007 - APPLICATION NOTE
The cutoff frequency is given by fcutoff=1/(2RC). So, for a 4kHz cutoff frequency with a 1kresistor, 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
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 cur-
rent 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
AI09792
PSD
Audio-Out(amplifier)
C
R
C
R
PWMx
AI09793
PSD
Headphones or Loudspeaker(Z >= 50 ohm)
PWMx
100F
+
8/13/2019 Sound Generation Using the uPSD Sound Studio on uPSD32xx and Turbo uPSD33xx-CD00041580
5/12
5/12
AN2007 - APPLICATION NOTE
SOFTWARE ISSUESuPSD 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 fittedinto 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 oper-
ating systems (Windows95/98/98SE/Millennium/2000/XP). This allows new audio applications to be de-
veloped 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
8/13/2019 Sound Generation Using the uPSD Sound Studio on uPSD32xx and Turbo uPSD33xx-CD00041580
6/12
6/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.
Additional signal processing can be applied to
the selected (highlighted) item (use the right
mouse button).
Additional signal pro-
cessing applied to all
the loaded WAV files.
Waveform of the se-
lected item. In the
case of a selectedheader, its content, in
hexadecimal format, is
displayed.
Final version of the
HEX files, loaded into
the appropriate FlashMemory sectors.
Button for generating
the final HEX files for
PSD Soft Express.
8/13/2019 Sound Generation Using the uPSD Sound Studio on uPSD32xx and Turbo uPSD33xx-CD00041580
7/12
7/12
AN2007 - APPLICATION NOTE
The users 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 uPSDs 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 sep-
arately with the users 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 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
8/13/2019 Sound Generation Using the uPSD Sound Studio on uPSD32xx and Turbo uPSD33xx-CD00041580
8/12
8/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 dis-
tortions of, the generated sound.
The CPU load depends on the uPSDs oscillator frequency, and the WAV source file sampling frequency.
Normally, it is below 10%. The value of FREQ_OSC, in the upsd_hardware.hfile, should be changed to
corresponding to actual oscillator frequency of the users 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
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.
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
8/13/2019 Sound Generation Using the uPSD Sound Studio on uPSD32xx and Turbo uPSD33xx-CD00041580
9/12
9/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.
ItemOrderpoints to the desired WAV file or item. A zero means silence, with UserDataindicating the du-
ration, in milliseconds. If ItemOrderis 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 ad-
dress 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
0000h
Page 0 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7
fs0
32KBytesuPSD(data)
Main Flash
fs1
32KBytesuPSD(data)
Main Flash
fs2
32KBytesuPSD(data)
Main Flash
fs3
32KBytesuPSD(data)
Main Flash
fs4
32KBytesuPSD(data)
Main Flash
fs5
32KBytesuPSD(data)
Main Flash
fs6
32KBytesuPSD(data)
Main Flash
fs7
32KBytesuPSD(data)
Main Flash
8000h
FFFFh
7FFFh
SRAM and CSIOP
(user application dependent)
AI09794
8/13/2019 Sound Generation Using the uPSD Sound Studio on uPSD32xx and Turbo uPSD33xx-CD00041580
10/12
10/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 depen-
dent, 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 demonstra-
tion, the code space memory map is as shown in Figure 7..
Figure 7. Code Space, Memory Map uPSD Sound Demonstration
The entire code memory is fully user application dependent and can be changed. The uPSD sound studio
has no special requirements.
CONCLUSIONThe uPSD32xx and Turbo uPSD33xx devices, from STMicroelectronics, are each highly flexible system-
on-a-chip devices, containing a large internal Flash Memory. Many audio applications can be implement-
ing 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.
7FFFh
0000h
3000h
2000h
1000h
4000h
csboot1(4KBytes uPSD Secondary Flash, User Application Dependent)
csboot0
(32KBytes Free)
8000h
FFFFh
AI09795
(4KBytes uPSD Secondary Flash, User Application Dependent)
csboot3 (4KBytes uPSD Secondary Flash, User Application Dependent)
csboot2 (4KBytes uPSD Secondary Flash, User Application Dependent)
(16KBytes Free)
8/13/2019 Sound Generation Using the uPSD Sound Studio on uPSD32xx and Turbo uPSD33xx-CD00041580
11/12
11/12
AN2007 - APPLICATION NOTE
REVISION HISTORY
Table 3. Document Revision History
Date Version Revision Details25-Aug-2004 1.0 First Issue
8/13/2019 Sound Generation Using the uPSD Sound Studio on uPSD32xx and Turbo uPSD33xx-CD00041580
12/12
12/12
AN2007 - APPLICATION NOTE
Information furnished is believed to be accurate and reliable. However, STMicroelectronics assumes no responsibility for the consequencesof 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 subjectto 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 companiesAustralia - 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 Americawww.st.com