Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
INDEX
Serial No
1 2 3 4 5
Experiment
Programming In DSP TMS320C54X Addressing Modes Number Sorting And Sequence Generation Convolution Using Overlap and Add Method Wave Pattern Generation FIR Filters
Date
13/9/2012 17/9/2012 4/10/2012 8/10/2012 12/10/2012
.mmregs .text ld #2000h,A ld #3000h,B ld #24h,DP add #100h,A sub #200h,B STM #100h,T mpy #2h,A STM #100h,T ld #500h,B LD #10H,A STM #1200H,AR0 mac *AR0,#2H,B ld #2000h,A STM #1200H,AR0 AND #3H,A ANDM #3H,AR0 ld #2000h,A ORM #3H,AR0 ld #2000h,A XOR #3H,A XORM #3H,AR0 ld #20h,DP ST #1200h,2 .end
STM #00h, AR0 ADD 00H,A ADD 01H,A ADD 02H,A ADD 03H,A ADD 04H,A ADD 05H,A ADD 06H,A ADD 07H,A ADD 08H,A ADD 09H,A ADD 0AH,A ADD 0BH,A ADD 0CH,A ADD 0DH,A ADD 0EH,A ADD 0FH,A .end
.mmregs .text STM #1200h, AR1 STM #1500h, AR2 STM #15h, AR0 Loop LD *AR1+,A STL A,*AR2+ BANZ Loop,*AR0-r
.end
.mmregs .text
Experiment 1
Programming in DSP TMS320C54X Addressing Modes
Aim: To write an assembly language program for various addressing modes. Tools Required: Code Composer Studio CCS v3.1 Algorithm: Write an assembly language program using immediate addressing for all possible arithmetic, logical and data handling instructions in C54X
Arithmetic instructions: ADD, SUB, MPY, MAC Logical Instructions: AND, ANDM, OR, ORM, XOR, XORM Data handling Instructions: LD, ST, STM Load the accumulator using syntax LD #value, A Implement each instruction using immediate addressing mode by using the syntax Instruction #immediate value, A
Write an assembly language problem to move a block of data from 1200H to 120FH to 1500H t 150FH using indirect Addressing mode
Load 1200H to AR0 and 1500H to AR1 Store in accumulator ST *AR0+,A Load from accumulator LD A, *AR1+ Repeat previous 2 instructions 16 times
Write an assembly language program to access even no address data and odd no address data using indirect addressing mode
Load 1000H in AR0 and 1001H in AR1 Load 2H in index register ADD *AR0+0,A ADD *AR1+0,B Repeat the loop
Write an assembly language program to access data values from 1000H to 100FH using direct addressing modes
Load the value DP in DP register. Move 0 to accumulator Move AR0 to A Increment A Repeat previous 2 steps 16 times
STM #1200h, AR2 STM #1201h, AR3 STM #02h,AR0 STM #07h,AR4 Loop LD *AR2+0,A LD *AR3+0,B BANZ Loop,*AR4.end
.mmregs .text STM #1Fh, BK STM #1200h, AR1 STM #3FFh, AR2 Loop LD *AR1+%,A BANZ Loop,*AR2.end
.mmregs .text stm #0fh,ar0 stm #1000h,ar1 stm #1010h,ar2 ld *ar1,a loop SUBC *ar2,a BANZ loop,*ar0.end
Write an assembly language program to divide the value in 1000H by the value in 1010H
Load dividend and divisor in 1000H and 1010H Quotient: N->performs n division steps Division steps: Subtract D-d and put result in accumulator If A is non-zero, add 1 to the quotient Repeat above 2 steps till A becomes 0
Geometric Sequence .mmregs .text n .set 10 stm n-2,AR0 stm #1200h,AR1 st #1h,*ar1 stm #0000h,AR2 ld #1h,B stm #1h,T loop ld *AR1+,A mpy #3,a stlm A,T stl A,*AR1 add a,b banz loop,*AR0sth b,*+AR1 stl b,*+AR1 .end Bubble Sort .mmregs .text n .set 5 stm n-1,AR0 stm n, AR4 Loopout stm #1200h, AR1 stm #1201h, AR2 stm #1500h, AR3 stm n-1,AR0 Loopin ld *AR1,A ld *AR2,B n n
max A stl A,*AR3 ld *AR1,A min B stl B,*AR2+ ld *AR3,A stl A,*AR1+ BANZ Loopin, *AR0BANZ Loopout, *AR4.end Triangular Sequence Generation .mmregs .text .set 10 stm n-1,AR0 stm #1200h,AR1 st #1h,*ar1 stm #1500h,AR2 ld #0h,B ld #0h,A loop add #1,b add b,a stl a,*ar2 add *AR2+,16,A banz loop,*AR0sth A,*Ar2+ .end Square Generation .mmregs .text .set 10
Experiment 2
Number Sorting and Sequence Generation
Aim: To write an assembly language program to generate
Bubble Sort Geometric Sequence Triangular Number Sequence Square No Sequence Fibonacci Sequence
Tools Required: Code Composer Studio CCS v3.1 Algorithm: Bubble Sort
Load the values to be sorted in a particular location onwards Load the memory address of the location in AR1 Compare 2 neighbouring values and sort themin required order using *AR1+%, *AR1+% ie using post dma increment and circular buffer After the buffer is over once, repeat the loop n-1 times ie total of n times where n=number of values to be stored
Geometric Sequence
Load value 1 in a particular address and store that address in particular ARn Specify the length of the sequence using .set Increment dma by *ARn+ and every loop multiply it by the constant and store it in the address by dma Repeat the loop
stm n-1,AR0 stm #1200h,AR1 st #1h,*ar1 stm #1500h,AR2 ld #0h,B ld #0h,A stm #1h,T loop squr *ar1,b stl b,*AR2+ addm #1,*Ar1 add b,a banz loop,*AR0sth A,*Ar2+ stl A,*Ar2 .end Fibonacci Sequence .mmregs loop n
.text .set 10 stm n-2,AR0 stm #1200h,AR1 st #1h,*ar1 stm #1201h,AR2 st #1h,*ar2 stm #1202h,AR3 ld *Ar1,A ld *Ar2,B stlm A,T Add B,A stl A,*Ar3+ ldm T,B banz loop,*AR0.end
Store the alternate values in 2 different accumulators Add value from one to other accumulator and do it again so that in 1 loop, we get 2 values. Restore them in the address locations Repeat the loop again
*Overlap add using mpy .mmregs .text stm #02h,ar1 stm #1000h,ar4 stm #2000h,ar6 stm data2,ar3 lp1: stm data1+2,ar2 stm #04h,ar5 lp2: ld #00h,a ld #00h,b stm #02h,ar7 lp3: mpy *ar2-,*ar3+,a add a,b banz lp3,*ar7mar *+ar2(+4) mar *+ar3(-3) stl b,*ar6;Storing values ld #00h,b add *ar6,b add *ar4,b stl b,*ar4+ banz lp2,*ar5mar *+ar3(+3) mar *+ar4(-2) banz lp1,*ar1nop nop
*Overlap add using mac .mmregs .text stm #02h,ar1 stm #1000h,ar4 stm #2000h,ar6 stm data2,ar3 lp1: stm data1+2,ar2 stm #04h,ar5 lp2: ld #00h,a rpt #02h mac *ar2-,*ar3+,a mar *+ar2(+4) mar *+ar3(-3) stl a,*ar6;Storing values ld #00h,a add *ar6,a add *ar4,a stl a,*ar4+ mar *+ar3(+3) mar *+ar4(-2) banz lp1,*ar1nop nop
Experiment 3
Convolution Using Overlap and Add Method
Aim: To write an assembly language program for convoluting 2 sequences of numbers using the
following instructions by overlap and add method: MPY and ADD MAC MACP MACD
Find which method takes minimum no of clock cycles and use that to convolve using overlap and save method.
Tools Required: Code Composer Studio CCS v3.1 Algorithm: Using MPY and ADD
Get and store the 2 sequences in 2 ARn registers say AR2 and AR3 Clear both the accumulators Perform linear convolution between 2 datas by multiplying 2 datas by MPY and adding the resultant of MPY stored in A to B and repeat for next elements Value of resultant B is then moved to another array in dma *ARn register Content of AR6 and AR4 are added and stored in AR4+ Loop 2 is repeated for all elements of block from data 2 This whole process from storing starting address in AR2 and AR3 register is repeated by mapping Ar3 to point to starting point of next block of data and AR4 to point to starting point of next block of data 2 and Ar4 to point to start of last (m-1)th elements
Using MAC
Define an array of l numbers using word say data 2 and save store in an array whose Define another sequence of m numbers whose starting address is in AR2 using STM operation Both Accumulator A and B are initialized to 0 Data 1 and 2 are MACD by using RPT instruction to get say n number of elements Pointer is made to point to next element in data 1 and 2 using MAC Accumulator value is stored in new memory location given by AR6 A is again reset to zero value To overlap and add do the same operation as performed in MPY and ADD Repeat the whole process required no of times
Using MACP
Define 2 sequences say data 1 and 2 and another sequence of length L+M-1 with all elements 0 Move these elements from data 2 to coefficient using MVDP and increment address at AR3 and storing it in next element of coefficient using coeff+k
.data data1 .word 0,0,1,2,3,0,0 data2 .word 1,2,3,4,5,6,7,8,9 nop nop .end
nop nop coeff .word 0,0,0,0,0 .data data1 .word 0,0,0,0,1,2,3,0,0,0,0,0 data2 .word 0,0,1,2,3,4,5,6,7,8,9,0,0,1 nop
*Overlap add using macp .mmregs .text stm #03h,ar1 stm #1000h,ar4 stm #00h,ar6 stm data2,ar3 lp1: mvdp *ar3+,coeff mvdp *ar3+,coeff+1 mvdp *ar3+,coeff+2 mvdp *ar3+,coeff+3 mvdp *ar3+,coeff+4 stm data1+6,ar2 stm #02h,ar7 lp2: ld #00h,b rpt #04h macp *ar2-,coeff,b stl b,*ar4+ mar *+ar2(+6) banz lp2,*ar7mar *+ar3(-2) banz lp1,*ar1lp1:
nop .end
*Overlap add using macd .mmregs .text stm #dt1+9,ar2 stm #2000h,ar3 stm #07h,ar5
ld #0h,b rpt #06h macd *ar2-,coeff,b delay *ar2 stl b,*ar3mar *+ar2(7) banz lp1,*ar5coeff .word 1h,2h,3h,4h,5h .word 0,0,0,0 .data dt1 .word 0,0,0,1h,2h,3h .word 0,0,0,0 nop .end
The next address or starting address of next block is stored in AR2 Reset accumulator B Use MACP to multiply and accumulate coefficient and data in B using MACP *AR2, coeff, B The above process is repeated required no of times AR2 is made to point to (l+m)th element using MAX The process is repeated required no of times
MACD
Define 2 sequences data 1 and 2 Now, define another sequence coeff of L+M-1 elements with all values 0 B is reset to 0 Convolve data 2 and coeff array using MACD and store in Accumulator B Store smem->smem+1 using delay Repeat the process required no of times Pointer is made to point at 2nd last element of data 2 using MAX Repeat the process required no of times Store B in *AR4 and increment it Move next block of element to coeff array and repeat process for overlap and add
*Overlap and save using macd .mmregs .text stm #dt1+9,ar2 stm #2000h,ar3 stm #07h,ar5 lp1: ld #0h,b rpt #06h macd *ar2-,coeff,b delay *ar2 stl b,*ar3mar *+ar2(7) banz lp1,*ar5coeff .word 1h,2h,3h,4h,5h .word 0,0,0,0 .data dt1 .word 0,0,0,1h,2h,3h .word 0,0,0,0 nop nop .end
SawTooth .mmregs .text stm #800h,ar2 inf: st #20h,BRC ld #0h,a rptb loop stl a,*ar2+ add #1,a loop: nop nop b inf .end inf: Square
Sine .mmregs .text sine: .word 0,19,38,55,70,83,92,98,100 .word 100,98,92,83,70,55,38,19,0 .word 0,-19,-38,-55,-70,-83,-92,-98,-100 .word -100,-98,-92,-83,-70,-55,-38,-19,0 stm #2000h,ar3 stm #800h,ar2 inf: stm sine,ar2 loop1:
Experiment 4
Wave Pattern Generation
Aim: To generate following wave patterns for specified frequency and amplitude
Sawtooth Triangular Square wave Sine wave
Tools Required: Code Composer Studio CCS v3.1 Calculation of Machine Cycles:
Required frequency = f ; t=1/f ; t=1/108*10-6
Frequency of processor = 108MHz Number of steps = t/t Saw Tooth Triangle Pulse wave
Number of steps = f-1/0.01*3 Number of steps = f-1/0.01*4 Freq1= ON Time * (0.01*f)-1 Freq2= OFF Time * (0.01*f)-1
Triangle
Set step size Set number of steps Load 0 to A Load 1 to B Load number of steps in AR2 Loop3:
Triangle .mmregs .text stm #200h,ar2 inf: st #20h,BRC ld #0h,a rptb loop stl a,*ar2+ add #1,a loop: nop nop st #20h,BRC rptb loop1 sub #1h,a stl a,*ar2+ loop1 nop nop b inf .end
Loop1: Store the value in A to *AR1+ Add A,B BANZ Loop1, *AR2Load the number of steps 1 to AR2 Loop2: Store the value in A in *AR1+ Subtract B from A BANZ Loop2, *AR2Branch to Loop3
Pulse Wave
Set amplitude, frequency1 and frequency 2 Load the starting address in AR1 Load the frequency in AR2 Load the amplitude in A Loop3: Loop1: Store the value in A to *AR1+ BANZ Loop1, *AR2Load the freq2- freq 1 in AR2 Load 0 to A Loop2: Store the value in A in *AR1+ BANZ Loop2, *AR2Branch to Loop3
Sine Wave
Set number of step cycles = 3124 Load 1000H in AR1 Load 3000H in AR3 Load the hexadecimal values to *AR1+ Load 2000H to AR2 Loop: Load the values from 1000H to 1008H in AR2+ Loop 3124 NOP cycles Load values from 1008H to 1000H in AR2+ Loop 3124 NOP cycles Load negative values to AR3 Load the values from 3000H to 3008H in AR2+ Loop 3124 NOP cycles Load values from 3008H to 3000H in AR2+ Loop 3124 NOP cycles Put Loop in Branch
Sine Wave Look-Up Table (Theta) 0 /16 2/16 3/16 4/16 5/16 6/16 7/16 8/16 17/16 18/16 19/16 20/16 21/16 22/16 23/16 24/16 Sin() 0 0.195 0.382 0.555 0.707 0.831 0.924 0.98 1 -0.195 -0.382 -0555 -0.707 -0.831 -0.924 -0.98 -1 Multiply by 100 0 19 38 55 70 83 92 98 100 -19 -38 -55 -70 -83 -92 -98 -100 Hexa 0 13 26 37 49 53 5C 62 64 FFED FFDA FFC9 FFBA FFAD FFA4 FF9E FF9C
.mmregs .text stm #16,bk stm #filter,ar3 stm #input2,ar2 stm #1000h,ar1 stm #15,ar5 ld *ar2+,b ld *ar2,a loop: rptz a,#14 mac *ar3+0%,*ar2+,a mac *ar3+0%,*ar2,a stl a,*ar1+ banz loop,*ar5.data
.end
Experiment 5
FIR Filters
Aim: To obtain FIR filter response given an input signal of sine waveform havu=ing window of any
choice for limiting the impulse response (filter coefficients )