DSP Lab
DSP Lab
INDEX
Introduction 2
1. Addition 12
2. Subtraction 13
3. Multiplication 14
4. Multiplication (4.12 format) 15
5. Division
Using SUBC 16
Series of Subtractions Method 17
6. Direct Data Transfer
Transfer 18
7. Indirect Data Transfer 19
8. Min-
Min-Max Program 20
9. Bubble Sorting 22
10. Fibonacci Series 24
11. Move Up & Move Down 25 & 26
12. Triangular Generation 27
13. Ramp Up & Ramp Down 28 & 29
14. Square Root 30
15. I/O Status 31
16. ADC 32
Initialization File
.def REGISTER_INITIALIZATION
.include f2407.h
.text
-------------------------------------------------------------------------------------
; Configure the System Control and Status Registers
-------------------------------------------------------------------------------------
REGISTER_INITIALIZATION:
LDP #DP_PF1; set data page
SPLK #0000000011111101b, SCSR1
; ||||||||||||||||
; FEDCBA9876543210
;* bit 15 0: reserved
;* bit 14 0: CLKOUT = CPUCLK
;* bit 13-12 00: IDLE1 selected for low-power mode
;* bit 11-9 000: PLL x 4 mode
;* bit 8 0: reserved
;* bit 7 1: 1 = enable ADC module clock
;* bit 6 1: 1 = enable SCI module clock
;* bit 5 1: 1 = enable SPI module clock
;* bit 4 1: 1 = enable CAN module clock
;* bit 3 1: 1 = enable EVB module clock
;* bit 2 1: 1 = enable EVA module clock
;* bit 1 0: reserved
;* bit 0 1: clear the ILLADR bit
LACC SCSR2; ACC = SCSR2 register
OR #0000000000001011b; OR in bits to be set
AND #0000000000001111b; AND out bits to be cleared
; ||||||||||||||||
; FEDCBA9876543210
;* bit 15-6 0's: reserved
;* bit 5 0: do NOT clear the WD OVERRIDE bit
;* bit 4 0: XMIF_HI-Z, 0=normal mode, 1=Hi-Z'd
;* bit 3 1: disable the boot ROM, enable the FLASH
;* bit 2 no change MP/MC* bit reflects the state of the MP/MC* pin
;* bit 1-0 11: 11 = SARAM mapped to prog and data (default)
SACL SCSR2; store to SCSR2 register
-------------------------------------------------------------------------------------
; Other setup
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
; Setup the core interrupts
-------------------------------------------------------------------------------------
LDP #0h; set data page
RET
F2407 File
-------------------------------------------------------------------------------------
; Filename: f2407.h
; Author: David M. Alter, Texas Instruments Inc.
; Description: LF2407 DSP register definitions for assembly code
; History: 03/14/01 - Original. (D. Alter)
; 08/12/02 - Fixed addresses of CAP2FBOT, CAP3FBOT, CAP5FBOT, and CAP6FBOT. (D. Alter)
-------------------------------------------------------------------------------------
; Core registers
IMR .set 0004h ; Interrupt mask reg
GREG .set 0005h ; Global memory allocation reg
IFR .set 0006h ; Interrupt flag reg
; System configuration and interrupt registers
PIRQR0 .set 7010h ; Peripheral interrupt request reg 0
PIRQR1 .set 7011h ; Peripheral interrupt request reg 1
PIRQR2 .set 7012h ; Peripheral interrupt request reg 2
PIACKR0 .set 7014h ; Peripheral interrupt acknowledge reg 0
PIACKR1 .set 7015h ; Peripheral interrupt acknowledge reg 1
PIACKR2 .set 7016h ; Peripheral interrupt acknowledge reg 2
SCSR1 .set 7018h ; System control & status reg 1
SCSR2 .set 7019h ; System control & status reg 2
DINR .set 701Ch ; Device identification reg
PIVR .set 701Eh ; Peripheral interrupt vector reg
; Watchdog timer (WD) registers
WDCNTR .set 7023h ; WD counter reg
WDKEY .set 7025h ; WD reset key reg
WDCR .set 7029h ; WD timer control reg
; Serial Peripheral Interface (SPI) registers
SPICCR .set 7040h ; SPI configuration control reg
SPICTL .set 7041h ; SPI operation control reg
SPISTS .set 7042h ; SPI status reg
SPIBRR .set 7044h ; SPI baud rate reg
SPIRXEMU .set 7046h ; SPI emulation buffer reg
SPIRXBUF .set 7047h ; SPI serial receive buffer reg
SPITXBUF .set 7048h ; SPI serial transmit buffer reg
SPIDAT .set 7049h ; SPI serial data reg
SPIPRI .set 704Fh ; SPI priority control reg
; SCI registers
SCICCR .set 7050h ; SCI communication control reg
SCICTL1 .set 7051h ; SCI control reg 1
SCIHBAUD .set 7052h ; SCI baud-select reg, high bits
Vector File
_________________________________________________________________________________
; File name: vector. h
; Interrupt Vector declarations
; This section contains the vectors for various interrupts in the 240x. Unused interrupts are shown to
branch to a "phantom" interrupt service routine which loops to itself. Users should replace the label
PHANTOM with the label of their interrupt subroutines in case these interrupts are used. -------------------
.global START, c_int0
.global PHANTOM
.global GISR1
.global GISR2
.global GISR3
.global GISR4
.global GISR5
.global GISR6
.sect "vectors"
RSVECT B _c_int0 ; Reset Vector
INT1 B GISR1 ; Interrupt Level 1
INT2 B GISR2 ; Interrupt Level 2
INT3 B GISR3 ; Interrupt Level 3
INT4 B GISR4 ; Interrupt Level 4
INT5 B GISR5 ; Interrupt Level 5
INT6 B GISR6 ; Interrupt Level 6
RESERVED B PHANTOM ; Reserved
SW_INT8 B PHANTOM ; Software Interrupt
SW_INT9 B PHANTOM ; Software Interrupt
SW_INT10 B PHANTOM ; Software Interrupt
SW_INT11 B PHANTOM ; Software Interrupt
SW_INT12 B PHANTOM ; Software Interrupt
SW_INT13 B PHANTOM ; Software Interrupt
SW_INT14 B PHANTOM ; Software Interrupt
SW_INT15 B PHANTOM ; Software Interrupt
SW_INT16 B PHANTOM ; Software Interrupt
TRAP B PHANTOM ; Trap vector
NMI B NMI ; Non-maskable Interrupt
EMU_TRAP B PHANTOM ; Emulator Trap
SW_INT20 B PHANTOM ; Software Interrupt
SW_INT21 B PHANTOM ; Software Interrupt
SW_INT22 B PHANTOM ; Software Interrupt
SW_INT23 B PHANTOM ; Software Interrupt
SW_INT24 B PHANTOM ; Software Interrupt
SW_INT25 B PHANTOM ; Software Interrupt
SW_INT26 B PHANTOM ; Software Interrupt
SW_INT27 B PHANTOM ; Software Interrupt
SW_INT28 B PHANTOM ; Software Interrupt
SW_INT29 B PHANTOM ; Software Interrupt
SW_INT30 B PHANTOM ; Software Interrupt
SW_INT31 B PHANTOM ; Software Interrupt
Program No: 1
Addition
Description:
This Program is used for Addition of Three Numbers (X, Y & Z). The Result will be Stored in
Accumulator Lower 16 bits & it will be stored into SUM = X + Y + Z.
Program No: 2
Subtraction
Description:
This Program is used for Subtraction of Three Numbers (X, Y & Z). The Result will be Stored in
Accumulator Lower 16 bits & it will be stored into RES = X - Y - Z.
Program No: 3
Multiplication
Description:
This Program is used for Multiplication of Two Numbers. The Multiplicand will be Stored in T
Register and after Multiplication, The Result will be in P Register & Result is taken in to
Accumulator Using PAC instruction & finally Stored in Result Variable.
Program No: 4
Multiplication (Format 4.12)
4.12)
Description:
This Program is used for Multiplication of Two Numbers which consists of Decimal. The
Multiplicand will be Stored in T Register and after Multiplication, The Result will be in P Register
& Result is taken in to Accumulator Using PAC instruction & finally Stored in Result Variable from
Accumulator Higher 16 bits by Shifting 4 bits.
Program No: 6
Direct Data Transfer
Description:
This Program is used for Direct Data Transfer i.e. it transfers Data from a Table which has been
included to the Memory address of 8000h. It Uses the Command Called TBLR.
Uninitialized Global Variable Definitions:
.bss GPR0, 1
.bss SRCTBL, 1
.bss CNT, 1 ; General Purpose Variable
TABLEB .set 8000h ; Starting Address of the Destination Table
COUNT .set 10 ; Defines the Number of Entries in the Table
Look-Up Table Includes:
.sect ".table"
.label tab_start ; Load Address of Table
TABLEA .include TABLE.dat ; 'TABLEA tab' is the Run Address of Section
.label tab_close ; Load Address of Table Section End
Program Code:
.text
_c_int0
CALL REGISTER_INITIALIZATION
LDP #SRCTBL ; Set Data Page
LACC #COUNT
SACL CNT ; Store the Number of Data Entries in CNT
LARP 1 ; Select AR1 as the Current AR
LAR AR1, #TABLEB ; Load the Starting Address of the TABLEB in AR1
LACC #TABLEA
SACL SRCTBL ; Point the Data Pointer SRCTBL to the Top of the Source Data.
LOOP LACC SRCTBL
TBLR *+ ; Read the Value from Table & Store in Destination Table.
Increment AR1 to Point to the Next Address in Destination Table
ADD #1
SACL SRCTBL ; Increment Source Data Pointer
LACC CNT
SUB #1
SACL CNT ; Decrement Loop Count
BNZ LOOP ; Continue if CNT > 0; i.e. until the End of the Source Data Table
is Reached.
END B END
Program No: 7
Indirect Data Transfer
Description:
This Program is used for Indirect Data Transfer i.e. it transfers Data from one Table to Another
Table by using the Command BLDD.
Uninitialized Global Variable Definitions:
TABLEA .set 8000h ; Starting Address of the Source Table
TABLEB .set 8010h ; Starting Address of the Destination Table
COUNT .set 10 ; Defines the Number of Entries in the Table
Look-Up Table Includes:
.data
.word 01h
.word 02h
.word 03h
.word 04h
.word 05h
.word 06h
.word 07h
.word 08h
.word 09h
.word 0Ah
Program Code:
.text
_c_int0
CALL REGISTER_INITIALIZATION
LARP 2 ; Select AR2 as the Current AR
LDP #0100H ; DP for Addresses 8000H
LAR AR2, #TABLEB ; Load the Starting Address of TABLEB in AR2
RPT #COUNT ; Perform the Following Operation 10 Times
BLDD #TABLEA,*+ ; Transfer Data from TABLEA to TABLEB &
After that Pointers to Data in Both the Tables are Incremented.
END B END
Program No: 8
Finding Min-
Min-Max
Description:
This Program is used for Finding Minimum and Maximum of Three Numbers by Comparison
Technique.
Uninitialized Global Variable Definitions:
.bss X, 1
.bss Y, 1
.bss Z, 1
.bss MIN, 1
.bss MAX, 1
Program Code:
.text
_c_int0
CALL REGISTER_INITIALIZATION
LDP #X
SPLK #0002h, X ; Assigning the Value to the X
SPLK #0003h, Y ; Assigning the Value to the Y
SPLK #0005h, Z ; Assigning the Value to the Z
LACC X
SUB Y
BCND LOOP, LT
BCND LOOP3, UNC
LOOP: LACC Y
SUB Z
BCND LOOP1, GT
LACC X
SACL MIN
LACC Z
SACL MAX
B END
LOOP1: LACC Y
SACL MAX
BCND LOOP2, LT
LACC Z
SACL MIN
B END
LOOP2: LACC X
SACL MIN
B END
LOOP3: LACC X
SUB Z
BCND LOOP4, GT
LACC Z
SACL MAX
LACC Y
SACL MIN
B END
LOOP4: LACC Y
SUB Z
BCND LOOP5, GT
LACC Y
SACL MIN
LACC X
SACL MAX
B END
LOOP5: LACC Z
SACL MIN
LACC X
SACL MAX
END B END
Program No: 9
Bubble Sorting
Description:
This Program is used for sorting the Data in Ascending Order by Comparing & Swapping
Continuously.
Uninitialized Global Variable Definitions:
.bss X1, 1
.bss X2, 1
.bss C1, 1
.bss C2, 1
COUNT .set 10h
DTABLE .set 8000h
Look-Up Table Includes: *The Data to be Sorted is Stored in Look-Up Table*
.data
.word 02h
.word 07h
.word 08h
.word 09h
.word 12h
.word 56h
.word 45h
.word 100h
.word 50h
.word 88h
Program Code:
.text
_c_int0
CALL REGISTER_INITIALIZATION
LDP #C1
SPLK #COUNT, C1
LOOP: LACC C1 ; Load ACC with C1
SUB #01
SACL C1 ; Subtract 1 from C1
BZ END ; if 0 go to End
LARP 1
LAR AR1, #DTABLE
SPLK #COUNT, C2 ; Assign C2=Count
NEXT: LACC *+ ; Load ACC with Table first Data & increment AR
SACL X1 ; Store ACC to X1
LACC C2 ; Load ACC with C2
SUB #01
SACL C2 ; Subtract 1and store to C2
BZ LOOP ; if 0 go to Loop
Program No: 10
Fibonacci Series
Description:
This Program is used for generating Fibonacci Series. The Series is given by (1, 1, 2, 3, 5, 8, 13, …. )
by Adding Current Value to the Previous Value of Table & then Storing it in the Next Location.
Program No: 12
Triangular Wave Generation
Description:
This Program is used for generating Triangular Wave; the amplitude is taken as TRI Variable & is
incremented continuously up to Maximum and during next cycle decremented up to Minimum.
B UP
B DOWN ; Go to DOWN
Program No: 14
Square Root of Positive Integer (Perfect Squares)
Description:
This Program is used for finding Square Root. Firstly Count is incremented & multiplied with same
value later product is compared with the Number & the process repeats until Product becomes
equal to Number. At the end the Square Root of the Number will be in Count.
Program No: 15
I/O Status
Program Code:
.text
_c_int0
CALL REGISTER_INITIALIZATION
LDP #DP_PF2 ; Set Data Page
LACL #0h ; Load Accumulator with 0
SACL MCRA ; Store Accumulator to MCRA Register
SPLK #000Fh, PADATDIR
LACL PADATDIR ; Load Accumulator to PADATDIR Register
END B END
Program No: 16
Analog to Digital Conversion
Program Code:
.text
_c_int0
NOP
; Initialization of I/O Pins
LDP #DP_PF2
LACL #0FFFFh
SACL MCRA
* Initialize ADC registers
LDP #DP_PF2
SPLK #0100000000000000b, ADCTRL1 ; Reset ADC module
NOP
SPLK #0011000000010000b, ADCTRL1 ; Take ADC out of reset
; ||||||||||||||||
; 5432109876543210 ; 15 - RSVD | 14 - Reset (1) | 13, 12 - Soft & Free
; 11, 10, 9, 8 - Acq.prescalers | 7 - Clock prescaler
; 6 - Start/stop mode (0) | 5 - Int. Priority (Hi.0)
; 4 - Seq.casc (0 - dual)
;* Setup a maximum of 01 conversions
SPLK #2, MAX_CONV; Setup for 1 conversions
;* Program the conversion sequence. This is the sequence of channels that will be used for the 16
conversions.
SPLK #03210h, CHSELSEQ1; Convert Channels 0,1,2,3
SPLK #07654h, CHSELSEQ2; Convert Channels 4,5,6,7
SPLK #0BA98h, CHSELSEQ3; Convert Channels 8, 9, 10, 11
SPLK #0FEDCh, CHSELSEQ4; Convert Channels 12,13,14,15
SPLK #0010000000000000b, ADCTRL2; Start the conversions
; ||||||||||||||||
; 5432109876543210
NOP
NOP
NOP
NOP
LOOP:
CHK_EOS1:
BIT ADCTRL2, BIT12 ; Wait for SEQ1 Busy bit to clear
; BIT12 is loaded into TC bit of ST1