/**********************************************************************/ Practical DSP By: Ron Robinson /**********************************************************************/ Tools for use on the Motorola 56001 DSP. //// Much of the following first appeared in the June/July issue of //// Atari Advantage Magazine and is reproduced here with the //// permission of the author. Permission is NOT granted for //// reproduction in any form other than this issue of AEO-PJ. Telling people what DSP is and can do shares many of the problems Alexander Graham Bell faced when first describing the telephone. "You talk into this end and it does what???" One could suspect many of the best applications for this breakthrough technology haven't even been dreamed of yet. DSP provides capabilities previously not possible in electronic systems. The development of DSP is estimated to have a technological impact similar to the effect the microprocessor had on computing. Sophisticated music systems, automated voice mail, speech synthesis, translating machines and seeing aids for the blind are becoming possible. The AT&T DSP phone answering system and DSP based toys such as the Texas Instruments "Speak and Spell" are common place. Or keyboards such as the Yamaha DX 7 digital keyboard incorporates custom DSP chips for music synthesis. Digital Signal Processing (DSP) has recently become feasible with a new series of specialized microprocessors that are designed to carry out digital signal processing algorithms. From the engineering side, this is characterized by multiply/accumulate computational sequences used to perform digital filtering and spectral analysis of signals. For the rest of us side, DSP is "heavy duty" math -- the process of evaluating signals and then processing that information to generate some kind of useful output. The processor to do this must be good, very good, at high speed math operations on large groupings of data. The Atari Falcon030 uses a Motorola DSP known as the DSP 56001. Motorola DSP 56001 Digital Signal Processor (DSP) Specs The DSP56001 Digital Signal Processor used in the Falcon offers many high performance advanced processor features. A few key points from the Motorola data sheets follow: ù Speed - 32 MHz operation, yields 16 MIPS. ù Precision - 24 bit internal and external data paths, yielding 144 dB dynamic range. 56 bit accumulators can range over 336 dB. ù Parallelism - Programming model is three execution units operating in parallel. ù Instruction Set - 62 instructions. The following operations can be executed in parallel in one instruction cycle: 24 x 24 bit multiply 56bit addition Two data moves Two address pointer updates Instruction prefetch ù Integration - six on-chip memory arrays, three communication channels, and seven buses. 512 x 24 bits of on chip ROM used for Mu-Law, A-Law and four quadrant Sine wave table data. Probably the best way to gain an appreciation for what DSP is all about is to take a look at a wide range of real world examples. //// DSP APPLICATIONS EXAMPLES: Digital Audio and Music Processing Analysis of musical instrument sounds Music synthesizers Digital recording studio and digital home reproduction Voice mail Phone answering machines (AT&T) Educational toys (TI Speak & Spell) Hi-Fi compression; error correction; dynamic noise reduction Reverb and ambience enhancement; pitch transposers Noise cancellation Communications High-speed modems Adaptive equalizers; digital repeaters of analog signals Video phone PCM companding: u/A law conversion Modulation/demodulation: amplitude, frequency, phase Data encryption and scrambling Linear-phase filtering; echo cancellation Spread-spectrum communication Signal Analysis Pulsed-echo acoustic hologram (bat sonar) Radar and sonar processing; electronic countermeasures Speech Processing Speech analysis Speech synthesis; vocoders...; speech compression Speech recognition/speaker authentication Voice store and forward Language translation Speech enhancement, noise cancellation Image Processing Image enhancement, pattern recognition; computer vision Reconstruction: CAT, PET, MRI tomography Radar and sonar image processing Digital TV-video DSP processors Satellite images; earth resource survey Graphic Image Generation Image management: Shapes, sizes, contours, shading, highlights Vector manipulation; graphics "engines" CAD/CAM workstations; 3-D image generators Flight (and other transportation) simulators; arts and film sequences Real-time Measurement Instrumentation Digital filters; fixed and adaptive Spectrum analyzers and estimators Phase-locked loops; coherent detectors; correlators Transient digitizers and analyzers Signal averagers, exponential smoothers Time domain reflectometry and pulse analysis Signal generation Chemical instrumentation: mass spectrometers, chromatograhs, etc. Observational astronomy: multiple-mirror telescope Search for extra-terrestrial intelligence (SETI) Thermography: IR imaging of temperature maps High-Speed Control Servo links; position and rate control; guidance: missiles, etc. Robotics; remote sensing and feedback "Skid-eliminator" adaptive and context-sensitive control Disk-drive head positioners Engine control-iterated with smart sensors Wheel balancing Number-Crunching Array processors for mainframes Floating-point accelerators for microcomputers Vector and matrix processors for supercomputers Sparse matrix algorithm processors Transcendental functions, iterative-solution architectures Artificial intelligence: Lisp machines, parallel processors Seismic earth and sonar sea-floor mapping Weather prediction and atmospheric modelling Real-World Interface Applications Transducer linerization; dynamically linearized loudspeakers "Smart sensors:" Intelligent transducers Solid-state camera with DSP enhancement or preprocess Flat panel display with local pixel-region processing Medical and Biotechnology Ultrasonic Imaging; digital x-ray: enhanced image allows lower dose. Patient monitoring (intensive care, EKG...) Prosthetic IC Implants (Artificial ear...) CAT, PET, MRI tomography (see under image processing) Fourier-transform IR spectrometer Integrative Applications Antibiotic susceptibility Pulse fluorescence analysis Time domain reflectometry DNA sequencing analysis Other Printed-text-to-voice converter for the blind Multilingual translating telephone The intelligent pilot's assistant (DARPA thrust area) Unmanned mobile watchdog or armored weapon ("Think-Tank") ___________________ References: "Digital Signal Processing", R.J.Higgins, Prentice Hall "DSP56001 Reference Manual", Motorola "Digital Signal Processing", McQuilken and LeBlanc, Motorola [ Editor's note: Atari FALCON030 software/hardware examples: MPEG - MPEG de-coder (video) by BrainStorm DIAMOND BACK III - DSP data compression for backups by Oregon Research DAME - Direct to Disk recorder with DSP effects (audio) BLACKMAIL - Voice Mail system WINREC - Direct to Disk recorder (audio) D2D - Direct to Disk recorder (audio) by D2D MUSICOM - Digital Audio, DSP effects (audio) by Compo DIGITAPE - Direct to Disk recorder (audio) by Codehead Technology AUDIO FUN MACHINE (audio) by SDS and many others ... In the next issue we hope to have some sample code for programming the DSP. ] /**********************************************************************/ Practical DSP By: BrainStorm /**********************************************************************/ Falcon030: Programming the 56001 Reprinted from "Passerelle nø2" published by Atari France. Translation and Adaptation: Albert Dayes One of the most outstanding features of the Falcon030 is its DSP 56001 installed as standard. Well used, this processor offers some impressive speed gains in various tasks like compression/ decompression, 3D calculations, video or audio effects. Taking full advantage of the 68030/56001 on the Falcon030 is often faster than a 486DX2/66. However two rules have to be followed: 1) Attempt to use both processors in parallel, dividing parts of the task between the 68030 and the 56001. 2) Write "true" DSP code in the 56001's native tongue. It is stupid to take a 68030 routine and convert it line by line into 56001 assembly because in this case you will not take advantage of the highly parallel architecture of the DSP. We will not explain DSP programming theory. For that just purchase the "DSP 56001 User's Guide" from Motorola. What we want to show with practical examples, are some subtleties of the Motorola DSP 56001. And to illustrate the correct method to utilitize/program the DSP to its greatest potential. Example 1: Copy a memory block ================== The following assembly source copies a block of 32 bytes into memory. ; source pointer move #INBuffer,r0 ; destination pointer move #OUTBuffer,r1 ; loop 32 times do #$20,_EndLoop ; read a word move X:(r0)+,a ; write a word move a,X:(r1)+ _EndLoop This program is fast but does not take advantage of the DSP. Now, we will try to change the destination register R1 to R4, as well as the type of RAM used (remember the DSP uses two RAMs: X and Y). [ Editor's Note: A basic block diagram of the Motorola 56001 DSP ---| | |------------| | | [A][B][C] | <----------------------------------| |------------| ======================================================================== |--------------------------| | program memory | | program controller | <------ contents of [A] | Address Generation Unit | |--------------------------| |--------------------------| | X memory | | Y memory | <------ contents of [B] | MAC (Multiply/Accumulate)| |--------------------------| |--------------------------| | | | input/output | <------ contents of [C] | | |--------------------------| ======================================================================= ] The previous routine can be rewritten like this: ; source move #INBuffer,r0 ; destination move #OUTBuffer,r4 ; read 1 word move X:(r0)+,a ; repeat 31 times rep #$1f ; write a word and read next one move X:(r0)+,a a,Y:(r4)+ ; write last word move a,Y:(r4)+ With this little optimization the speed has been increased by a factor of three! This optimization uses instructions in parallel that allows one to read AND write at the same time! NOTE: To be executed in parallel, two memory moves have to be done in different memories and use registers from two different banks. The DSP56001 uses two banks of registers: Bank number 1 includes: R0, R1, R2, R3 Bank number 2 includes: R4, R5, R6, R7 [ Editor's Note: These registers are located in Address Generation Unit ] For example: In one instruction, it is possible to read from RAM X and write to RAM Y. But you cannot read from RAM Y and write into RAM Y. In the same way, you can associate the same instruction registers R2 and R7, but not R1 and R3. Example 2: Invert a memory bloc ================== In this sample we will try to invert 32 DSP words, using the NEG operation. The easiest way to do that is in the example below: ; ptr source move #INBuffer,r0 ; ptr destination move #OUTBuffer,r1 ; 32 loops do #$20,_EndLoop ; read a word move X:(r0)+,a ; invert it neg a ; write the inverted word move a,Y:(r1)+ _EndLoop Here again, the algorithm choice is not the best one for the DSP. Each loop includes 1 read from memory, 1 arithmetic operation, and 1 write of the data. ON THE DSP, ALL THIS CAN BE DONE IN ONE INSTRUCTION!! Here is how to achieve this goal: ; ptr source move #INBuffer,r0 ; ptr destination move #OUTBuffer,r4 ; read a word move X:(r0)+,a ; invert it, and read the next one. neg a X:(r0)+,b ; repeat 16 times do #$10,_EndLoop ; invert current word(b), read next one(a), write previous one neg b X:(r0)+,a a,Y:(r4)+ ; invert current word (a), read next one (b), write previous one neg a X:(r0)+,b b,Y:(r4)+ _EndLoop This new routine does the job in one instruction instead of three. Because we are dealing with two words at the same time. While one is inverted, the previous one is written down and the next one is read from memory. As you can see, even with simple operations, the DSP can provide an incredible increase in speed. For the next step we will try to avoid the "MOVE" instruction as a memory move can (most of the time) be done in parallel with an arithmetic instruction. Example 3: Memory shift ============= On the DSP, instructions ASL and ASR shift the specified register of only one bit (68030 can shift multiple bits). However one can easily avoid this problem. One has to remember what a shift [left] is... it is just a multiplication by a power of 2. The following routine will shift a register 4 times: ; ptr source move #INBuffer,r0 ; ptr destination move #OUTBuffer,r1 ; loop 32 times do #$20,_EndLoop ; read 1 word move X:(r0)+,a ; shift 4 times to the right rep #4 asr a ; write the shifted word move a,Y:(r1)+ _EndLoop It takes 7 instructions, which is definitely quite a bit for a small DSP job. We can do much better using multiply instructions as detailed below. ; ptr source move #INBuffer,r0 ; ptr destination move #OUTBuffer,r1 ; multiplier move #$80000,y0 ; loop 32 times do #$20,_EndLoop ; read 1 word move X:(r0)+,x0 ; right shift of 4 bits mpy x0,y0,a ; write shifted word move a,Y:(r1)+ _EndLoop This routine only uses 3 instructions. This is much better! But one can do exactly the same job in ONE instruction in the same manner as example 2. ; source move #INBuffer,r0 ; destination move #OUTBuffer,r4 ; multiplier move #$80000,y0 ; read 1 word move X:(r0)+,x0 ; shift it and read the next one mpy x0,y0,b X:(r0)+,x0 ; repeat 31 times the next instruction rep #$1f ; shift the current word, read the next one, write the previous one mpy x0,y0,b X:(r0)+,x0 b,Y:(r4)+ ; write last word move b,Y:(r4)+ Isn't this easy? The art of DSP programming is based on the clever choice of the registers and the combination of memory accesses with arithmetic operations. The DSP can replace the 68030 for many calculations with a speed gain of over 10 times. And do not forget that on the Falcon, the DSP clock is twice the clock of the 68030! That is 32Mhz for the 56001 DSP versus 16mhz for the 68030 cpu. [ Editor's Note: The above article is Copyright 1993 Atari France and BrainStorm. Permission is denied for reproduction in any form other than this issue of AEO-PJ. References: DSP 56000/DSP 56001 Digital Signal Processor User's Manual Author/Publisher: Motorola USA: Motorola Literature Distribution PO Box 20912 Phoenix, Arizona 85036 EUROPE: Motorola Ltd.; European Literature Center; 88 Tanners Drive Blakelands, Milton Keynes MK14 5BP, England Atari Compendium ISBN: 0-9638331-0-3 DSP related sections: XBIOS Overview : 4.7 - 4.10 XBIOS Reference : 4.33 - 4.54 Memory Map : B.24 - B.26 XBIOS Opcodes : A.10 - A.11 ]