NEW DATABASE - 350 MILLION DATASHEETS FROM 8500 MANUFACTURERS
SPRA708 C6000 9754Z 9754Z-1 - Datasheet Archive
SPRA708 - November 2000 TMS320C62x Algorithm: Sine Wave Generation Yao-Ting Cheng C6000 Applications ABSTRACT This application
Application Report SPRA708 SPRA708 - November 2000 TMS320C62x Algorithm: Sine Wave Generation Yao-Ting Cheng C6000 C6000 Applications ABSTRACT This application report shows how to implement the 2nd-order IIR filter that generates a sinusoid signal on the TMS320C62xTM DSP. Contents 1 Design Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 List of Figures Figure 1. 2nd Order IIR Filter for Generating Sine Wave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Figure 2. Location of the IIR Poles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Figure 3. Graphical Display of the Sine Wave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 List of Examples Example 1. Code Listing in Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Example 2. Code Listing in C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1 Design Problem This application report shows how to implement the 2nd-order IIR filter that generates a sinusoid signal on TMS320C62x DSP. 2 Solution There are several ways to implement the sine wave generator on DSP processor such as a lookup table, interpolation, polynomials, etc. One efficient technique is using an IIR filter, making it oscillating by locating its poles in the unit circle of the Argand diagram. A typical 2nd order IIR filter can be established as illustrated in Figure 1. TMS320C62x is a trademark of Texas Instruments. 1 SPRA708 SPRA708 ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ y0 x[n] y[n] Z1 y1 A Z1 y2 B Figure 1. 2nd Order IIR Filter for Generating Sine Wave Give this IIR two initial values as below based on the assumption of 40 samples to make up a complete sine wave, then disconnect the x[n] from the input. At time interval n=2, 2 y2 = x[0] = sin 0 = 0 40 2 . y1 = x[1] = sin 1 0.1564 40 Properly choose filter coefficients A and B, so that this IIR will oscillate by itself. The formal proof can be found in the DSP related text book. You can take a short cut to find the value of A and B simply by solving the difference equations: y[n]=A·y[n1]+B·y[n2] For example: y[2] = A·y[1] + B·y[0], y[3] = A·y[2] + B·y[1]. Substitute y[n] with known values as below: 2 y[0] = sin 0 = 0 40 2 y[1] = sin 1 0.1564 40 2 y[2] = sin 2 0.3090 40 2 y[3] = sin 3 0.4540. 40 2 TMS320C62x Algorithm: Sine Wave Generation SPRA708 SPRA708 That is 0.3090 = A ×0.1564 + B ×0, 0.4540 = A ×0.3090 + B ×0.1564, therefore A=1.9754 and B=1. Examining the behavior of this IIR filter by its transfer function as below: y[n] = 1.9754·y[n1] y[n2] + x[n] Take a Z-transform: Y[Z](1 1.9754Z 9754Z1 + Z2) = X[Z]. The transfer function is Y[Z] 1 = X[Z] 1- 1.9754Z-1 9754Z-1 + Z-2 ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ H(Z) = 0.9877+j0.1564 0.9877j0.1564 Figure 2. Location of the IIR Poles Its has two poles Z=0.9877+j0.1564 and Z=0.9877j0.1564 and are located in the unit circle as shown above. The following program codes show how to program the TMS320C6x using Assembly landuage and C language to implement the IIR Sine wave generator. You can utilize the Probe point feature available in the Code Composer Studio by connecting the varying "output" of the sine wave to a graphical display. TMS320C62x Algorithm: Sine Wave Generation 3 SPRA708 SPRA708 Figure 3. Graphical Display of the Sine Wave 4 TMS320C62x Algorithm: Sine Wave Generation SPRA708 SPRA708 Example 1. Code Listing in Assembly .title "fir.asm" ; .def init int half .equ .equ 4 2 a_half y1 y2 .data .short .short .short 32768*1975/2000 32768*1409/10000 0 .bss .bss output,40*half,half buffer,2*half,2*half .text init: .S1 .S1 .D1 a_half,A0 a_half,A0 *A0,A2 MVK MVKLH MVC .S1 .S1 .S2X 0x0001,A0 0x0001,A0 A0,AMR MVK MVKH MVK STH .S1 .S1 .S1 .D1 output,A3 output,A3 0,A0 A0,*A3+ MVK MVKH MVK MVKH .S1 .S1 .S1 .S1 buffer,A4 buffer,A4 y1,A0 y1,A0 LDH NOP STH STH .D1 *A0+,A1 4 A1,*A4+ A1,*A3+ ; load y1 LDH NOP STH main: MVK MVKH LDH .D1 ; load y2 .D1 *A0,A1 4 A1,*A4+ MVK .S1 40,A1 ; calculate 40 samples .D1 .D1 .M1X .L1 .S1 .S1 .L1 .L2X .D1 .D1 *A4+,B1 *A4,B2 3 A2,B1,A0 A1,1,A1 loop A0,16,A0 A0,A0,A0 A0,B2,B0 B0,*A4 B0,*A3+ ; ; ; ; ld y(n1) to B1, point to y(n2) ld y(n2) to B2, point to y(n2) >15) y[2]; y[2] = y[1]; /* y2