Conception of a FM transmitter for the TMS320C6211DSP Starter Kit

Computing a discrete convolution is the most simple solution. We have a .... the following temporal representation shown in figure 3.6. Figure 3.6. ..... The “C6211dsk.h” file gives the correspondence between variables and addresses for each.
801KB taille 12 téléchargements 323 vues
Lionel Lafarge Elève Ingénieur ENSERB Ecole Nationale Supérieure d’Electronique et de Radioélectricité de Bordeaux – France

Conception of a FM transmitter for the TMS320C6211DSP Starter Kit

Universität Hannover – Germany Institut für Allgemeine Nachrichtentechnik Prof. Dr. – Ing. H.-P. Kuchenbecker Supervisor : Dipl. – Ing. Denis Bederov Mars – August 2000

Contents

INTRODUCTION............................................................................................................................4

A.

SIMULATION OF A FM TRANSMITTER ...........................................................................5

1

FREQUENCY MODULATION..............................................................................................5 1.1 1.2

2

DISCRETE SIGNAL PROCESSING......................................................................................7 2.1 2.2

3

BASIC NOTIONS..................................................................................................................................................................5 THE EQUIVALENT LOWPASS SIGNAL ...............................................................................................................................6

THE SAMPLING THEOREM (SHANON THEOREM) ...........................................................................................................7 DESIGN OF A LOW PASS FILTER........................................................................................................................................8

CONCEPTION OF THE MONO FM TRANSMITTERS.....................................................10 3.1 ORGANISATION ................................................................................................................................................................10 3.2 THE USED FUNCTIONS .....................................................................................................................................................11 3.2.1 The Low pass filter .............................................................................................................................................. 11 3.2.2 SI Interpolation and decimator......................................................................................................................... 12 3.2.3 Integrator.............................................................................................................................................................. 13 3.2.4 The preemphase filter ......................................................................................................................................... 14 3.3 THE TEST SYSTEM ............................................................................................................................................................16

B.

PROGRAMMING WITH THE C6211 DSP .........................................................................17

4

PRESENTATION ..................................................................................................................17 4.1 4.2 4.3

5

TMS320C6211 DSP STARTER KIT ..............................................................................................................................17 A RCHITECTURE OF C6211 DSP.....................................................................................................................................18 TLC320AD535 CONVERTER ........................................................................................................................................18

PROGRAM WITH C AND ASSEMBLER FILES ONLY...................................................19 5.1 FILES ORGANISATION ......................................................................................................................................................19 5.2 THE MEMORY MAPPING...................................................................................................................................................19 5.3 DECLARATION OF HARDWARE INTERRUPTS................................................................................................................20 5.4 THE PERIPHERIES CONTROL ...........................................................................................................................................22 5.4.1 The Multichannel Buffered Serial Port (McBSP) .......................................................................................... 22 5.4.2 The timer ............................................................................................................................................................... 24 5.4.3 The User LED and SWITCH.............................................................................................................................. 24

6

USING THE DSP/BIOS SYSTEM ........................................................................................25 6.1 6.2 6.3 6.4

INTEREST AND FILES ORGANISATION ............................................................................................................................25 PROGRAM AN INTERRUPT (SOFT /HARD W ARE INTERRUPT).....................................................................................25 U SE OF A PIPE..................................................................................................................................................................26 REAL TIME CONSIDERATIONS ........................................................................................................................................28

2

C.

CONCEPTION AND TEST IN REAL TIME OF A FIR FILTER .......................................29

7

CONCEPTION OF A FIR FILTER.......................................................................................29 7.1 7.2 7.3

PRESENTATION.................................................................................................................................................................29 COMPUTING THE COEFFICIENTS.....................................................................................................................................29 U SING A BLOCK CONVOLUTION .....................................................................................................................................30

8 THE CONVERTER 44,1 KHZ → 8 KHZ.................................................................................33 8.1 8.2 8.3

9

CONCEPTION AND GENERATION OF THE C-CODE WITH COSSAP.............................................................................33 GENERATING THE DATA..................................................................................................................................................35 INSERTION AND USING OF THE PROGRAM WITH COMPOSER STUDIO.......................................................................36

OPTIMISATION FOR THE IMPLANTATION OF THE FM TRANSMITTER................41 9.1 9.2 9.3

INSERTION OF AN EXTERN D/A CONVERTER ...............................................................................................................41 THE EDMA INTERRUPT .................................................................................................................................................41 FURTHER ADAPTATION ...................................................................................................................................................42

CONCLUSION..............................................................................................................................44

ANNEXE 1 : USING A FAST CONVOLUTION.........................................................................45 ANNEXE 2 : MATLAB SCRIPT FOR THE PREEMPHASE FILTER.......................................48 ANNEXE 3 : GENERIC C CODE OF THE FIR FILTER............................................................50 ANNEXE 4 : C CODE OF THE CONVERTER PROJECT.........................................................53 ANNEXE 5 : THE EDMA CONTROLLER..................................................................................62 ANNEXE 6 : ORGANISATION OF EXAMPLES.......................................................................64 BIBLIOGRAPHY..........................................................................................................................65

3

Introduction

The Institut für Allgemeine Nachrichtentechnik is within the Department of Electrical Engineering and Information Technology of the University of Hanover. The Institute is divided into two sections : Transmission Systems and Communication Networks. Research in Transmission Systems deals with the following domains : Mobile Communication. Acoustic signal processing Transmission of signals via optical fibre. Research in Communication networks deals with the following domains : Interfaces between networks Optimisation of networks Combination of different networks The present work has been undertaken in the Transmission Systems section of the Institute. The program COSSAP is used to design modulation and demodulation techniques. This program simulates off-line, without real time constraints. But a design can only be exploitable when it works in real time on a portable system. Mr. Bederov was eager to develop a system to implement designs developed with COSSAP into a Digital Signal Processor (DSP). So the ability of the system to work in real time can be measured. Hence, the Institute has bought Texas Instrument TMS320C6211 DSP Starter Kits. Therefore the aim of the present work is to study the possibility of the kits through the implementation of a FM sender. A Real Time analysis of the kit has to be proceeded so that Algorithms running in Real Time on the DSP platform can be developed in COSSAP modules. So COSSAP can be used to design a system and to program the TMS320C6211 DSP.

The first step of the work entailed the development of a FM transmitter with COSSAP. Then I had to study the architecture of the TMS320C6211 DSP Starter kit and develop a system in order to exploit data from COSSAP in Real Time. And then the last part of the work was writing modules for COSSAP adapted for the final implementation of the FM transmitter.

4

A. Simulation of a FM transmitter 1

Frequency Modulation 1.1

Basic Notions

The frequency modulation allows a high quality transmission. The following equation represents the transmitted signal : g(t ) = A(t ) cos[Φ(t )] As far as the frequency modulation is concerned, A(t), which represents the amplitude of the signal, is a constant and φ(t) can be split up into the following equation : Φ ( t ) = ω 0 t + ϕ (t ) where ω0 represents the pulsating value of the carrier and ϕ(t), the phase deviation of the signal. dΦ (t ) = α ⋅ f (t ) + ω0 dt This phase deviation actually carries the information. where f(t) represents the input modulating signal and α, the modulation coefficient. So, the transmitted signal can be written as the following equation : t

g ( t ) = A ⋅ cos[ ω0 t + α ⋅ ∫ f (τ ) dτ + φ0 ] 0

Where φ 0 represents the value of the phase at the temporal origin. We consider that the signal g(t) is a band-pass signal. In theory, a FM signal contains an infinite number of side frequencies so that the bandwidth required to transmit such a signal is infinite. But, according to Carson’s rule, only a limited bandwidth can be used to transmit a FM signal. The frequencies outside are negligible. The width of the used bandwidth is : B = 2 ⋅W = 2 ⋅ (η+ 2) f m = 2 ⋅ (∆F + 2 f m ) where, fm is the maximal frequency of the modulating signal, η is the modulation index and ∆F represents the hub. The maximum value of frequency deviation ∆F is fixed at 75 kHz. So, the Fourier transform is non negligible only in a band of frequencies centred on the carrier frequency, as illustrated in figure 1.1.

G(fc)

-fc-W -fc

-fc+W

0

fc-W

fc

fc+W

Figure 1.1. : Amplitude spectrum of the real signal g(t)

5

1.2

The equivalent lowpass signal

The complex envelope gT of the signal g(t) can be easily obtained from the pre-envelope g+(t). g+(t) = g(t) + j

(t)

+∞ where (t) represents the Hilbert Transform of g(t) H {g ( t )} = gˆ ( t ) = 1 g (τ ) dτ : π −∫∞ t − τ The Fourier Transformation gives :

G+(jω) = G(jω) + j

(jω)

(jω) = HH(jω).G(jω) where HH(jω) represents the Fourier transform of the Hilbert transform of a Dirac Impulse δ(t) : h H (t ) =

1 πt for t ≠ 0 1 + ∞ δ (τ) d τ =  π ∫− ∞ t − τ  0 for t = 0

We obtain the following Fourier transform : H H ( jω) = − j.sign (ω) So, the Fourier transform for the analytic signal is :

G+ ( j ω) = G ( j ω).[1 + sign (ω)]

The complex envelope gT (jω) results from the following multiplication :

gT (t) = g+ (t) ⋅ e − jω0t = A ⋅ e j( Φ( t) −ω0t ) = A ⋅ e jϕ ( t ) The Fourier transform gives : GT(jω) = G+( jω + jω0 ) In fact, this operation eliminates the carrier and translates the spectrum of the signal as shown in figure 1.2. G +(f)

GT(f)

2 G(fc)

2 G(fc)

0

f c-W

fc

fc +W

-W

0

W

Figure 1.2. : Amplitude spectrum of pre-envelope g +(t) and complex envelope g T(t)

The complex envelope gT (t) is a complex-valued quantity : g T (t ) = g I (t ) + jgQ (t ) = A ⋅ cos(ϕ (t )) + A ⋅ j ⋅ sin(ϕ (t ))

We can define the canonical form of the signal g(t) : g ( t ) = Re( g T (t ) e jω 0 t ) = g I (t ) cos( 2πf c t ) − g Q (t ) sin( 2πf c t ) We refer to gI(t) as the in-phase component and to gQ(t) as the quadrature component of the equivalent low-pass signal. 6

2

Discrete signal processing 2.1

The sampling theorem (Shanon Theorem)

The signal is sampled, so the signal is a discrete signal. Therefore, if we want to shape the continuous signal from the discrete signal, we have to respect Shanon’s Theorem : the used sampling frequency fs have to be at least two times bigger than the limit frequency fl which is the maximal frequency that the signal can have. In fact, we take fl = 2.fs to avoid “over samlping” signals. So, for a signal f(t), we have : ∞

f (t ). ∑ δ (t − kts ) = k =−∞



∑ f (kt ).δ (t − kt ) s

s

k = −∞

The Fourier transform gives : ∞

1 ∞ F ( j ω − jlωs ) ∑ t s l∑ k = −∞ =−∞ If we want to reconstruct, the continuous signal from the discrete signal, we have to use an ideal low pass filter (figure 2.1.) : f ( kts ).e − jω kts =

G(jw)

1 ω < ωl G( jω) =  0 otherwise

1

The reverse Fourier Transform gives the temporal form: g (t) =

ωl SI (ωl t ) π

SI ( x ) :=

where

sin( x ) x

- wl

wl

Figure 2.1. : Transfer function for an ideal filter

We can obtain the Fourier transform of the continuous signal thanks to a low-pass filter as the figure 2.2. shows : F ( j ω) = t s



∑ f (nt

s

).e − jω nt s .G( j ωl )

n =−∞

1/ts.F(jw) Low-Pass filter

fl fs 0 Figure 2.2. : Spectrum of a discrete signal

- 2.fs

- fs

- fl

2.fs

And thus, the inverse Fourier transform gives : f (t ) =



∑t

n = −∞

s

⋅ f (nt s ).

∞ 2π ⋅ f l SI [ωl ( t − nt s )] = ∑ f (nt s ) ⋅ SI [ωl ( t − nt s ] π n = −∞

7

2.2

Design of a low pass filter

An ideal low pass filter has the following temporal form : ωcutoff f (n ) = t s ⋅ f ( n ⋅ t s ) = t s ⋅ ⋅ SI (ωcutoff ⋅ n ⋅ t s ) where π Where, ts is the sampling period and fcutoff is the cut off frequency.

ωcutoff = 2π ⋅ f cutoff

We use a Finite Impulse Response Filter (FIR Filter) to approximate a low pass filter. In fact the impulse response of an ideal low pass filter is infinite. To delimit this response, we multiply the impulse response by a window function. The approximation is all the better as the window is long. A Blackman window is appropriate : h (n ) = f ( n) ⋅ w( n) 1 H ( j ω) = F ( jω) * W ( jω) 2π Where 0.42 − 0.5 ⋅ cos( 2π ⋅ n / M ) + 0.08 cos( 4π ⋅ n / M ) 0 ≤ n ≤ M w( n) =  0 otherwise  The length for the impulse response of an FIR filter is (M+1).The bigger M is, the more precise the filter is, because with a bigger M, we consider a larger part of the SI function. but the bigger M is, more time is needed to compute the response of the filter. With a Blackman Window, we obtain the following impulse response and transfer function for a symetric low pass filter. Figure 2.3. represents it with M = 512, fs = 44100 Hz and fcutoff = 15000 Hz.

Figure 2.3. : Impulse response and function transfer for a low pass filter multiplied by a Blackman Window

8

Now, we consider the following system which represents a FIR filter : x(n) input

y(n) output

h(n)

{y n } = {x n } * {hn }

Where

We have two possibilities to compute the response y(n) : - Computing a discrete convolution. - Using a fast convolution which uses a Fast Fourier Transform (cf. Annexe 1). Computing a discrete convolution is the most simple solution. We have a finite discrete convolution between the input and the output : yn =

n

∑h

n− k

xk = a0 . x0 + a1 .x1 + ... + aM −1 . xM −1 + a M x M

where

a i := hn −i

k =n −M

We compute all the coefficient ai, and we operate M+1 multiplication and M addition. In fact M+1 is the length of the filter. We can also write : M

y n = ∑ hk x n − k k =0

We define X(Z) and Y(Z) as the z transform of w(n) and y(n) : X (Z ) =



∑ x (n) ⋅ Z − n

Y (Z ) =

n =−∞



∑ y (n ) ⋅ Z

−n

n =−∞

Thus : H (Z ) =

Y (Z ) M = ∑ h( k ) ⋅ Z − k X (Z ) k = 0

The figure 2.4. represents the structure of a FIR filter. The branches labelled with Z-1 correspond to a delay.

x(n)

Z-1 h(0)

Z -1 h(1)

Z-1 h(2)

h(M-2)

h(M-1) y(n)

Figure 2.4. : Structure of a FIR filter

9

3

Conception of the mono FM transmitters 3.1

Organisation

The program COSSAP has been used to design a Mono FM transmitter. This transmitter exploits a 44,100 kHz sampled signal which can be written in the C6211 Kit RAM. This FM transmitters delivers the complex envelope gT (t) of the pass-band signal g(t) : the in-phase component gI(t) and the quadrature component gQ(t). The resulting complex envelope is a digital signal sampled with a frequency of 300 kHz. A D/A converter has to be adapted on the C6211 Kit RAM in order to convert this signal. The figure 3.1. gives the COSSAP diagram developed with COSSAP : RSTI

Stereo Source

Left Right

SUMI

MI2R

+

Conversion INT to REAL

MULS

x 1/2

MULS

ILPF

x 1/32767

Low Pass Filter 15 kHz

Fs = 44100 Hz

Pre-process Fs = 44100 Hz

FIR_QC

Preemphase Filter

MULS

CLIP

SIIN

Limitator

SI interpolator up 7

Fs = 44100 Hz

x 1/308700

INT1

MULS

Integrator

x 2.pi.75000

AP2QC

X

cos(X) sin(X)

Fs = 308700 Hz

FM Transmiter

Test system

DMPNI

MUXI

Data

Multiplexor

MR2I

MULS

Conversion REAL to INT

x 32767

MR2I

MULS

Conversion REAL to INT

x 32767

In-phase component I(t) g

Quadrature component Q(t)g

Figure 3.1. : Diagram of the FM transmitter

Three parts can be identified : the first part represents the pre-process, the second is the FM transmitter which delivers the complex envelope and this complex envelope is formatted and written in a file to be exploited by a test system. According to Shanon’s Theorem, only a signal which has a maximum frequency less than half of the sampling frequency, can be properly sampled. So, this configuration allows us to modulate a signal with a maximal frequency of 15 kHz. The source is stereo music sampled with a 44,1 kHz frequency and coded on 16 bits so the frequency values are between -215 (-32768) and 215 -1 (32767). The two outputs (Left and Right) are added, then divided by 2, then by 32767 to obtain values between –1 and 1. The bandwidth of the signal is limited in function of the used sampling frequency : a cut-off frequency of 15 kHz for a sampling frequency of 44,1 kHz. 10

In the FM transmitter, a preemphase filter is used. In fact, the noise is more important for high frequencies than for low frequencies. The level for high frequencies is emphasised at the transmission and it is de-emphasised at the reception. So the noise are equal for all frequencies. An interpolation by 7 is carried out to obtain a sampling frequency of 308,7 kHz. Then, the frequency of the modulated signal is integrated thanks to an integrator and a multiplication by the sampling period (1/308700). Multiplication by α gives the phase. A “hub” of 75 kHz is used. Since the value of the frequency for the modulating signal is between –1 and 1, we obtain : α = 2π ⋅ ∆F = 2π.75000 The in-phase component and the quadrature component are easily obtained by the calculation of cos(x) and sin(x). The created files contains alternatively values of the in-phase component and of the quadrature component. These values are coded on 16 bits. 3.2

The used functions 3.2.1

The Low pass filter

To simulate this filter, we use a cyclic convolution with a Fast Fourier Transform (cf. Annexe 1). The length of the Fourier Transform corresponds to the length of the used window. The length has to be a power of two. The simulation helps to choose the length. The length should be long enough to assure a good approximation, but too long a length increases computing time. For the parameters of the filter, we choose : Fc = 15 kHz, FS = 44,1 kHz and N = 512. We use a Blackman window and we obtain the transfer function represented in figure 3.2.

Figure 3.2. : Transfer function for the pre-process of the FM transmitter

11

3.2.2

SI Interpolation and decimator

To increase the sampling frequency, we have to use a SI Interpolator. Figure 3.3. shows the principle of a SI Interpolator. Fs

1

W.F s Multiplexor

xW

Low pass filter

W-1 Constant 0

Figure 3.3. : Bloc diagram for a SI interpolator

In fact, thanks to a multiplexor, we add null samples to the signal. We want to increase the sampling frequency by a factor of W. For example W=3 for the figures. After the multiplexor, we have the following temporal representation in figure 3.4. for the signal : x(n)

1/Fs

2/Fs

3/Fs

t

Figure 3.4. : Temporal representation after the multiplexor

Figure 3.5. shows modifications on the spectrum : Low pass filter

X(jw)

Fs/2

3.Fs/2

f

Figure 3.5. : Spectral representation after the multiplexor

Then, thanks to a low pass filter, we can select only the appropriate spectrum. And so we have the following temporal representation shown in figure 3.6. x(n)

1/Fs

2/Fs

3/Fs

t

Figure 3.6. : Temporal representation after the low pass filter

12

To determinate the length of the FFT for this second low pass filter, many simulations have been done. We have the following results : W = 7 and N = 512. To decrease the sampling frequency, we use a decimator. In fact, as figure 3.7. shows, it is only a demultiplexor. 1

Fs

Fs/W

Demultiplexor W-1

Kill module

Figure 3.7. : Bloc Diagram for a decimator

3.2.3

Integrator

To differentiate, the following formula is used :

y(k ) = ( x(k + 1) − x(k)) / Ts Where x(k) represents the input signal (the frequency), y(k), the output signal and Ts the sampling period. The Fourier transform gives : j ωTs

Y ( j ω) =

X ( jω) ⋅ e

jω Ts

− X ( jω)

Ts

=

X ( jω) ⋅ e Ts

2

j ωTs

  e  

j ωTs 2

− jω Ts

−e

2

 X ( j ω) ⋅ e   = Ts  

2

ω⋅ Ts   2 j ⋅ sin( ) 2 

The module of the transfer function is : H ( jω) =

2 ω ⋅ Ts sin( ) Ts 2

For a frequency of 308700 Hz, we have the following functions. Between –15 kHz and 15 kHz, it is almost a line. This function approximates the differentiation function Hd(ω) = jω as we can notice in figure 3.8.

Figure 3.8. : Transfer function of H(ejω)

But, we have to integrate the frequency so the differentiation formula is easily adapted to obtain the integrated formula :

y(k ) = y(k − 1) + x(k) ⋅ Ts

The module Integrator computes : y(k) = y(k-1) + x(k). And we have to add another module to multiply by Ts = 1/308700. 13

3.2.4

The preemphase filter

In fact the high frequency components are more affected by the noise so they are amplified thanks to a preemphase filter. The Bode diagram of this preemphase filter is presented in figure 3.9.

20 log/dec

0 dB fc1= 3.18 kHz

fc2

f

Figure 3.9. : Bode diagram of the preemphase filter

The frequency fc 1 is fixed thanks by conventions. And fc 2 should be chosen bigger than 20 kHz which represents the limit frequency of the audio spectre. The circuit which can realise such a filter is presented in figure 3.10. R1

R2

C

Figure 3.10. : preemphase filter

The transmit function for this filter is : jω + H ( j ω) =

1 R1C

 1 1  jω +  +   R1 C R2 C 

So, we have : 1 1 = 2π ⋅ R1C 2π ⋅τ R1 + R2 R + R2 f2 = = f1 ⋅ 1 = k ⋅ f1 2π ⋅ R1 R2 C R2 f1 =

The norm in main countries imposes that the value of the constant τ is 50 µs.

14

This preemphase filter is simulated thanks to a FIR filter. The output is computed thanks to a discrete convolution. yn =

n

∑h

n −k

x k = a 0 .x 0 + a1 . x1 + ... + a M −1 .x M −1 + a M x M

where

ai := hn −i

k =n − M

The ai coefficients are computed thanks to a Matlab script (cf. Annexe 2). In this script, we compute the Fast Fourier Transform for a lowpass filter delimited by a Blackman windows and multiplied by the transfer function 1 + j.τ.ω, with τ = 50 µs. The cut off frequency of the lowpass filter is set higher than 15 kHz because the audio spectrum is limited to 15 kHz in the music configuration. This script creates a file which contains the value of this coefficients. COSSAP used this file to operate a discrete convolution. The length of this discrete convolution is 128. Figure 3.11. shows the impulse response for this filter, in fact the values of the ai coefficients, and the transfer function of the preemphase filter.

Figure 3.11. : Impulse response and transfer function of the preemphase filter

We can check that the filter amplifies the values for the high frequencies.

15

3.3

The test system

To test the file created by COSSAP, we use the system shown in figure 3.12. In phase Component PC with a Labview program

Digital/ Analogue Converter

cos(wct) g (t).cos(w.t) I c

+

Low pass filter Fc=F s/2 Quadrature Component

FM receiver

sin(wct)

gQ (t).sin(wc .t)

Figure 3.12. : System to test the file from COSSAP

A Labview program exploits the file created with COSSAP to give the In phase-Component and the Quadrature Component. These numeric signals (Fs = 308,7 kHz) are interpolated by a Digital/Analogue Converter. It is a linear interpolation, so we have to use a low pass filter in order to have the appropriate spectrum. Then we add a carrier (107 MHz).

Now, we have the complied system under COSSAP. This system works. But this system can not be used directly to implement the DSP. To create a C-program with COSSAP, the whole module have to be written in C. We can easily write the C the module which performs mathematical operations such as multiplication. In fact, the real problem is that the FIR filter used by COSSAP is not written in C and is not optimised for the DSP. But, first it would be interesting to study how the C6211 DSP can be programmed.

16

B. Programming with the C6211 DSP 4

Presentation 4.1

TMS320C6211 DSP Starter Kit

We use the TMS320C6211 DSP Starter Kit from Texas Instrument. It is a new product, so we have to study this product before we can use it. The picture 4.1. shows the different elements of the kit.

Figure 4.1. : TMS320C6211 DSP Starter Kit

This kit includes : - C6211 DSK Board which is connected to a PC through a parallel port cable. - C6211 DSP from Texas Instrument. - 4 MB External SDRAM and 128 KB External Flash. - TLC320AD535 which is 16 bit Data Converter (both A/D and D/A Converter). - TPS56100 Power Management Device. - JTAG Controller which provides easy emulation and debugging. - Expansion Daughter Card Interface To program this kit, we use the Code Composer Studio application (version 1.05). This application contains the necessary tools to develop an application : C-compiler, assembler and linker. It manages the link between the PC and the DSP.

17

4.2

Architecture of C6211 DSP

The architecture of the DSP can be devised in three parts : Peripherals, Intern Memory and Data Memory. The figures 4.2. gives the block diagram of the C6211 : Host Port

External Memory

Internal Memory

EMIF

McBSPs

EDMA

CPU

Timer/Count

Figure 4.2. : Block diagram of the C6211 DSP

The CPU can only do one thing : Sum of Products. It is the core of the DSP. The Internal Memory can be divided in two levels : - L1 cache with 4 KB for program and 4KB for date - L2 with four 16 KB blocks, each block can be configured as RAM or as Cache. The Host Port is a bus which enables connection with the PC. The External Memory Interface (EMIF) interfaces to external memory (SDRAM, Flash). The Multi-Channel Buffered Serial Port (McBSP) enables the communication with external peripheries such as data converters. The C6211 DSP has two McBSPs. The Enhanced Direct Memory Access (EDMA) controls transfers data between regions in the memory without intervention by the CPU. The Timer/Counter can be very useful to launch a periodic task. The C6211 has two independant timers. The timers, the EDMA and the McBSPs can generate interrupts to the CPU. 4.3

TLC320AD535 Converter

The TLC320AD535 is both an Analogue/Digital Converter and a Digital/Analogue Converter. The Analogue/Digital converter is a 16-bit converter which uses a sampling frequency of 8 kHz. The Digital/Analogue converter receives a 16-bit word from the host. In fact the data use only 15 bits because, the last bit is used as a bit control. When this bit is at 1, it means that the next data should program one of the register in the converter. The converter has got six registers. So the data should indicate the register address and the register data. For more information about the TLC320AD535 Converter, refer to TLC320AD535 Data Manual.

18

5

Program with C and assembler files only 5.1

Files organisation

To compile a C-program, some files are needed to indicate how mange the interrupts, the peripheries and the memory. File Name Vectors.asm C6211dsk.cmd RTS6021.lib C6211interrupts.h C6211dsk.h McBSP_AD535_INIT.c Program.c Header.h

5.2

Function Declares interrupt vectors Manages sections in memory Standard library for C-code. Declares interrupt functions Defines addresses to exploit peripheries Enables the initialisation to use the converter of the kit Main Program which exploits interrupts Declare the functions used by the program

Code Assemblor cmd file library

C-code

The memory mapping

The file “C6211dsk.cmd” shown on the figure 5.1. indicates to the compilator where the data should be memorised, it maps sections to memory. MEMORY { VECS : org = 0h, len = 0x220 IRAM : org = 0x00000240, len = 0x0000FDC0 SDRAM : org = 0x80000000, len = 0x01000000 FLASH : org = 0x90000000, len = 0x00020000 } SECTIONS { vectors :> VECS .text :> IRAM .bss :> IRAM .cinit :> IRAM .stack :> IRAM .sysmem :> SDRAM .const :> IRAM .switch :> IRAM .far :> SDRAM .cio :> SDRAM } Figure 5.1. : example of a C6211dsk.cmd file

The IRAM is the L2 which can be used either as cache or as RAM. Access to the IRAM is quicker than to the SDRAM, but the SDRAM (4 MBytes) is larger than the IRAM (64 KBytes ). So to have enough space to save the signal from the Analogue/Digital converter, we should use the SDRAM memory and thus, we should declare the used table as a far variable in the Cprogram. The FLASH memory which can store up to 128 Kbytes, can retain data.

19

The following table represents the different sections : Sections Vectors .text .bss .cinit .stack .sysmem .const .switch .far .cio

Functions Created by the file “vectors.asm”, data for the interrupts vectors Contains executable code Contains used variables Tables for initialising variable and constant For the stack Reserves place for the dynamic memory (malloc, calloc, realloc) Contains variables which are declared as constant Reseves place for switch structure Reserves place for variables which are declared as far Reserved

Place VECS IRAM IRAM IRAM IRAM SDRAM IRAM IRAM SDRAM SDRAM

We can also create our own sections. To create a section and to insert a symbol, we have to use a pragma which indicates to the compiler how the data should be treated. For more information about pragma functions, refer to chap 7.6. TMS320C6000 Optimizing C Compile User’s Guide. 5.3

Declaration of Hardware Interrupts

An interrupt is an event that stops the current process in the CPU so that the CPU is able to effectuate the required task. These interrupts are external to the core of the CPU, the source can be a timer or a serial port. Serving an interrupt involves : - Saving the content of the current process - Completing the interrupt task - Restoring the registers - Resuming the original process There are three types of interrupts : Reset Interrupt, nonmaskable interrupts and maskable interrupts. The Interrupt Service Table contains the interrupt vectors which indicate the sources of the different interrupts. Vector INT0 INT1 – INT3 INT4 – INT15

Type Reset Interrupt Nonmaskable Interrupts Maskable Interrupts

Function Return to a known state Managed by the system Managed by the user

A nonmaskable interrupt can interrupt a maskable interrupt, but neither a nonmaskable interrupt nor a maskable interrupt can interrupt a nonmaskable interrupt. The interrupt sources are identified by an identification number : Event PC to DSP interrupt Timer 0 interrupt Timer 1 interrupt EMIF SDRAM timer interrupt External interrupt pin 4/5/6/7 EDMA interrupt 8/9/10/11 McBSP0 transmit event McBSP0 receive event McBSP1 transmit event McBSP1 receive event

Name DSPINT TINT0 TINT1 SD_INT EXT_INT4/5/6/7 EDMA_INT XINT0 RINT0 XINT1 RINT1

Id Number 0x0 0x1 0x2 0x3 0x4/5/6/7 0x8/9/A/B 0xC 0xD 0xE 0xF

20

To declare a maskable interrupt, we have to assign it an interrupt vector. This vector has a priority number. The higher this number, the more prioritised is the interrupt. We have to proceed as indicated in figure 5.2. Declaration of the interrupt vectors vectors.asm

Initialise the used peripherals mcbsp0_init(); TLC320AD535_INIT()

Declaration of the used interrupt config_Interrupt_Selector(INTnumber,INTsource)

Enable Interrupts enableSpecificINT(INTnumber), enableNMI(), enableGlobalINT()

Figure 5.2. : steps to declare an interrupt

The interrupt vectors have to be declared in the “vectors.asm”. It is an assemblor files which makes it possible to save the system registers before the interrupt, to launch the interrupted function and to restore the registers after. When we call a function written in C in an assembly file, we have to add an underscore “_” before its name. The function to initialise the peripherals are contained in the “McBSP_AD535_INIt.c”. The other used functions are declared in the file “C6211interrupts.h”. The source for the maskable interrupts are given by two 32-bits registers : Interrupt Multiplexer High (IMH) and Low (IML). These registers give for each vector, the Id number of the source (Figure 5.3.). 0

IML

5 Src int 4

0

IMH

Src int 10

10 Src int 5

5 Src int 11

Src int 6

10 Src int 12

15 16 X

Src int 7

15 16 X Src int 13

21 Src int 8

21 Src int 14

26 Src int 9

26 Src int 15

31 X

31 X

Figure 5.3. : Registers Interrupt Multiplexer High and Low (IMH and IML)

As soon as the interrupts are declared, we have to enable the interrupts. We use the function enableSpecificINT. for each used maskable interrupt. This function edits the Interrupt Enable Register (IER) to enable the declared interrupt. We use the function enableNMI to enable only the declared maskable interrupts : the undeclared maskable interrupts are ignored. And then we have to set the Global Interrupt Enable bit (GIE) in the Control Statut Register (CSR) with the function enableGlobalINT. Addresses for the registers CSR and IER are declared in the “c6x.h” file which belongs to the library, whereas the addresses for the registers IMH and IML are declared in the “c6211dsk.h”. For further information about interrupts, you can refer to Chap 7 TMS320C6000 CPU and Instruction Set Reference Guide.

21

5.4

The peripheries control

The “C6211dsk.h” file gives the correspondence between variables and addresses for each periphery. 5.4.1

The Multichannel Buffered Serial Port (McBSP)

To exploit data from the Analogue/Digital Converter, the Mutlichannel Buffered Serial Port (McBSP) is required. The “McBSP_AD535_INIT.c” declares all the functions used in the main program to control the converter : mcbsp0_init, mcbp0_write, mcbsp0_read and TLC320AD535_Init. The McBSP uses registers to receive data, to transmit data or to configure its operation. The figure 5.4. presents the different registers :

McBSP DR

RSR

DX

XSR

RBR

Compand Expand Compress

CLKX CLKR FSX FSR CLKS

DRR DXR

SPCR Clock generation, frame sync generation and control

RCR XCR

32-bit peripheral bus

SRGR PCR

MCR Multichannel selection

RCER XCER RINT XINT REVT XEVT

Interrupts to CPU

Synchronization events to DMA

Figure .5.4. : Multichannel Buffered Serial Port (McBSP) Internal Block Diagram

22

Data is communicated to devices interfacing to the McBSP via the data transmit (DX) pin for transmission and the data receive (DR) pin for reception. Clock and synchronisation information is communicated via CLKX, CLKR, CLKS (Clock Transmit, Receive, External), FSX and FSR ( Receive Frame synchronisation). The CPU or DMA controller reads the received data from the Data Receive Register (DRR) and writes the data to be transmitted to the Data Transmit Register (DXR). Data written to the DXR is transmitted to DX via the transmit shift register (XSR). Similary, receive data on the DR pin is transmitted into the receive shift register (RSR) and copied into the receive buffer register (RBR). Between the RBR/XSR and the DRR/DXR, we can use the Companding (compressing and expanding) module. This module allows hardware compression and expansion of data either µlaw or A-law format. For more information, refer to Chap. 11.4. TMS320C6000 Peripherals Reference Guide. The remaining registers accessible to the CPU configure the control mechanism of the McBSP. The Serial Port Control Register (SPCR) and the Pin Control Register (PCR) contain McBSP status control bits, whereas the Receive and Transmit Control Registers (RCR and XCR) configure parameters of the receive and the transmit operations (element length, frame length, MSB first,...). For more information, refer to Chap. 11.2. & 11.3. TMS320C6000 Peripherals Reference Guide. The Sample Generator Register controls the operation of the sample rate generator. The sample rate generator delivers two signals : CLKG (Programmable Data Clock) and FSG (Programmable Framing Signal). These signals can be used to deliver the receive or/and transmit clocking CLK(R/X) and framing FS(R/X). For further information, refer to Chap. 11.5. TMS320C6000 Peripherals Reference Guide. Multiple channels can be independently selected for the transmitter and the receiver by configuring the McBSP with a single-phase frame. Each frame represents a time-division multiplexed data stream. The number of elements per frame selected by the (R/X)CR represents the number of channels. The multichannel operation controls are operated thanks to the following registers : the Multichannel Control Register (MCR), the Transmit Channel Enable Register (XCER) and the Receive Channel Enable Register (RCER). For further information refer to Chap. 11.6. TMS320C6000 Peripherals Reference Guide. The receive and the transmit interrupt (R/X)INT signal the CPU that the data is ready to be received or transmitted, whereas the receive and the transmit synchronisation event to the DMA controller (R/X)EVT signal the DMA controller. For further information, refer to Chap. 11.3. TMS320C6000 Peripherals Reference Guide. CAUTION ! In the Starter Kit, the TLC320AD535 is connected to the McBSP0, but it uses the Interrupt for the McBSP1 ! In fact, the serial port interrupt wires have been accidentally crossed.

23

5.4.2

The timer

The timer interrupt can be very useful to make periodical tasks as switch and LED test for example. The device contains two independent timers. Each timer is controlled thanks to three registers : Timer Control (TIMER_CTRL), Timer Period (TIMER_PRD) and Timer Counter (TIMER_COUNT). The Timer Control register controls the timer. If we want to use the timer to generate a timer interrupt, in the initialised phase, we have to deactivate the hold state (/HLD = 0 field in Timer Control). Than, we can adjust the desired period in the period register. And we start the timer by setting the GO and /HLD bits of the timer control register. To use the CPU clock, we have to set the CLKSRC bit of the timer control. Than the frequency of the timer is the quarter of the CPU clock frequency : CPU ( clock ) 150 MHz f (timer ) = = = 37,5MHz 4 4 So to generate a timer interrupt each 100 ms, we have to write 3 750 000 in the period register. And then we have to declare the interrupt. For further information, refer to Chap 12. TMS320C6000 Peripherals Reference Guide. 5.4.3

The User LED and SWITCH

The DSK has three user-LED and three user-switches (the fourth switch TP 14 is not connected). The desired states of the LED are transmitted to the IO_PORT which represents the 0x90080000 address. The position of the Switches are transmitted to the SWITCH which represents the 0x90080003 address. In the original file “c6211dsk.h”, SWITCH is not defined, so we have to define it by adding the following instruction : #define SWITCH 0x90080003 In the following example, the LED are enlighten as the switches are configured. Main() { Int SW, LED While (1) { SW = (*(unsigned volatile int*)SWITCH >> 24); switch (SW) { case 0x3F : LED = 0x0F; break; /* 0 */ case 0x3E : LED = 0x0E; break; /* 1 */ case 0x3D : LED = 0x0D; break; /* 2 */ case 0x3C : LED = 0x0C; break; /* 3 */ case 0x3B : LED = 0x0B; break; /* 4 */ case 0x3A : LED = 0x0A; break; /* 5 */ case 0x39 : LED = 0x09; break; /* 6 */ case 0x38 : LED = 0x08; break; /* 7 */ default : LED = 0x0F; } *(unsigned volatile int*)IO_PORT = (LED 0 Return an empty frame PIP_alloc Get start adress & size of the frame PIP_getWriterAdrr PIP_getWriterSize Fuel the frame

frame full Specify a new size PIP_setWriterSize

Notify the Reader that a frame is full PIP_put

Figure6.2. : Steps to write a frame of a pipe

26

To read a pipe, we have to proceed as shown in figure 6.3. Check the number of full frames PIP_getReaderNumFrames

>0 Get a full frame from the pipe PIP_get Get start adress & size of the frame PIP_getReaderAddr PIP_getReaderSize Read the frame Notify the Reader that a frame is empty PIP_free

Figure 6.3. : Steps to write a frame

For further information on how to use these functions, refer to chap 5.2 & chap 6 (PIP Module) TMS320C6000 DSP/BIOS User’s Guide. To read a pipe, we use the following functions. The “dss_asm.s62” file contains assembler instruction which enable registers to be saved and to launch the HWI. The HWI is the C-function DSS_cirs described in file ”dss_cisr.c”. When a pipe is empty, we have to free the pipe, so we use the C-function DSS_txPrime which is described in file “dss.c”. To write a pipe, we use a SWI. This SWI is in fact a C-function. We can write this function by hand or this function can be generated thanks to COSSAP. This C-code have to give fixed-size packets to write the pipe. In fact, when a program is generated with COSSAP, this program handles “packets” of data. So the pipe is compatible with these “packets”.

27

6.4

Real Time considerations

The DSP/BIOS enables the monitoring of DSP applications in real time. It is possible to measure the time required by a SWI. For further information on how to use this instrumentation, refer to Chap 3 TMS320C6000 DSP/BIOS User’s Guide. Writing a Pipe have to be faster than reading. The Pipe is in general written by a SWI and read by a HWI. The function launched by the SWI needs tfunction to produce N data for the pipe. There is an HWI each tHWI = 0,125 s (fs = 8 kHz). So, first we have to respect the following condition : tfunction < N.tHWI = tSWI Moreover, if a non interruptible routine is used for tnon-interruptible, the following relation has to be considered : tnon-interruptible < tHWI SWI posted

SWI posted

SWI posted

HWI SWI

tfunction tHWI

tSWI

Figure 6.4. : Temporal schedule

So it is really important to optimise this product function. As this product function is written, its execution time should be measured and compared with the time between two SWI. To find advises to optimise the C-code, refer to TMS320C6000 Optimising C Compiler User’s Guide and TMS320C62x/C67x Programmer’s Guide. The loops should use “Software Pipelining”. A “Software Pipelining” enables to launch the next iteration before the iteration has finished. For example, we consider a loop which has four stages represented by A, B, C and D. If the loop is software pipelined, figure 6.5. shows its schedule : A1

Pipelined-loop prolog

B1

A2

C1

B2

D1

C2

B3

A4

D2

C3

B4

D3

C4

time

A3 Kernel Pipelined-loop epilog

D4

Figure 6.5. : schedule for a software pipelined loop

But, “Software Pipelining” can only be used if the loop handles integer values and the next iteration does not need the result of the previous iteration. Assembler macros can be used to speed up the program. But, some Assembler macros are not interruptible ! the execution time for these macros should not be too much important so that the DSP can answer to interrupts. For further information refer to the TMS320C62x DSP Library Programmer’s Reference.

28

C. Conception and test in real time of a FIR Filter 7

Conception of a FIR filter 7.1

Presentation

The modules of the FM receiver use arithmetic and filtering operations. Arithmetic operations are no problem for a DSP ! Do not forget that the core DSP algorithm is the Sum of Products ! So the principal difficulty is computing a filter in real time. There are different ways to simulate a FIR filter in the first part : a FIR filter can be computed thanks to a discrete convolution or with a fast convolution. We have chosen to develop a FIR filter module using a discrete convolution. Moreover, to assure a good optimisation, this FIR filter should handle integer data. This FIR filter has been written in Generic C to program a COSSAP module called FIR_GEN_INT in the C6211DSK library. 7.2

Computing the coefficients

The user has to indicate some parameters : Parameters Impulse length of the filter Sampling time of the signal Cut off frequency of the filter Gain of the filter Non interruptible

Name of the variable ImpLength SAMPLING_TIME CUTOFF_FREQUENCY GAIN Non_interruptible

The filter is symmetric so we compute 2*ImpLength+1 coefficients using a Blackman window as the program presented in figure 7.1. : coeff_float[ImpLength] = GAIN*2*SAMPLING_TIME*CUTOFF_FREQUENCY; for (i=1; i 15) is necessary because a multiplication between two signed shorts (16 bits) is computed. The result is a signed integer (31 bits), so this statement convert this integer into a short (16 bits). 2 .M

In fact we compute :

r j = ∑ hi ⋅ x i + j

where M = ImpLength

i =0

In fact the coefficients are ordered as follow in the h[2M+1] table, moreover they are symmetric : Table Coefficients

h0 c-M=cM

h1 ... c-M+1 =cM-1 ...

hM-1 c-1= c1

hM c0

hM+1 c1

... ...

h2M cM

So, we can write : 2 .M

r j = ∑ c −M + i ⋅ x i + j = i =0

0

∑ c− M −i ⋅ x j−i =

i = −2 M

0

∑ c M + i ⋅ x j− i =

i =− 2 M

M

∑c

i

⋅ x j + M −i = y j + M

i= − M

Where y represents the output. So we do compute the convolution c*x. This computation have to work in Real Time ! The considerations of Real Time programs shown in the previous chapter do not have to be forgotten ! We use functions from the DSP library, but we have to be very careful. These functions are not interruptible and moreover to be fast enough, the input, the output and the coefficient vectors have to be saved in .bss domain and declared as array (short x[nr+nh-1]; and NOT short *x;). So to reduce the non-interruptible time, the idea is to share an execution of the function into many executions. Thus between 2 functions, the DSP is interrupted by an HWI. Moreover, we use two local array tempin and tempout to save parts of the input vector and the output vector in the .bss domain. The coefficients are already saved in the .bss domain So we use the code presented in figure 7.2. to compute the convolution Input*coeff : 31

/* Share the length of the convolution */ Repeat = (4*ImpLength*BlockFactor-2*ImpLength)/non_interruptible; Rest = 4*ImpLength*BlockFactor-2*ImpLength-repeat*non_interruptible; For (i=0; i void init_cossap(void) for ( ; ; ;) -> void cossap(PIP_Obj *pip_out) { { int i, *dst;

In fact, we use a pipe. This program generated by COSSAP is used to writer the pipe. PIP_alloc (pip_out); Dst = PIP_getWriterAddr(pip_out); PIP_setWriterSize(pip_out, 2048); For ( i; i < 2048; i++) { Dst[i] = (dcg_signal_4[i]