Download as pps, pdf, or txt
Download as pps, pdf, or txt
You are on page 1of 46

Digital Signal Processor

The Heart of Modern Real-Time Control Systems

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Chapter 3 Examples In Using The F243 DSK

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Learning Objectives

Writing The First Program. Example 1 : Flashing The XF Led. Example 2 : Flashing The XF Led More Brighter. Example 3 : Flashing The XF Led Equally. Example 4 : Generating A Time Delay Example 5 : Generating A Longer Time Delay. Example 6 : Saving The ACCUMULATOR At The Data Memory. Example 7 : Reading A Value From A Mixed I/O Port. Example 8 : Filling A Block Of Memory With A Particular Value. Example 9 : Generating 100 kHz Signal Using Timers. Example 10 : Controlling The Duty Cycle Of Timers Output By A/DC Result.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Writing The First Program

First draw the corresponding flow chart of the desired program . Choose a suitable text editor to write your program (a suitable text editor is supplied as standard with Microsoft Windows, namely Notepad). Write your program using any supported programming language as Assembly, C, or C++, depending on the compiler you use. Save the program in the project folder. Compile it to generate the DSK file which is comprehensible to the DSP. Now, your program is ready to run.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Example 1 : Flashing The XF Led

It is a simple example which defines the main principles of writing a program using the assembly language. On the TMS320F243 DSK there are two light emitting diodes (LEDs). One is for the power-supply and is always on. The second is available to the user and can be controlled by software. This is the XF LED. The XF LED on the DSK is driven from a physical pin on the TMS320F243 device.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Program Source Code

start:

.setsect .text, 8800h SETC XF ; Turn on XF LED. CLRC XF ; Turn off XF LED. B start ; Go round again.

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

The Program In Cycles


.setsect .text, 8800h start: SETC XF CLRC XF B start

; Turn on XF LED. 1 cycle. ; Turn off XF LED. 1 cycle. ; Go round again. 4 cycles.

One cycle equals 400 ns. The XF led will be ON for one cycle and OFF for five cycles. The result is that the XF led will appear DIM. The signal period= 1 x 400 + 5 x 400 = 2400 ns The signal frequency is approximately 416.66 kHz.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

The Output Taken From The XF Pin

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Example 2 : Flashing The XF Led Brighter

As the pervious example we will make a loop to control the XF led, but this time we will reverse the order in which the SETC XF and CLRC XF instructions occur.

start:

.setsect .text, 8800h CLRC XF ; Turn OFF XF LED. 1 cycle SETC XF ; Turn ON XF LED. 1 cycle. B start ; Go round again. 4 cycles

The led will be OFF for one cycle, and ON for five cycles. The result is that the led appears Brighter. The signal period still 2400 ns. The frequency is 416.66 kHz.

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

The Output Taken From The XF Pin

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Example 3 :Turning The XF Led ON and OFF Equally

We need to equal the number of cycles for each operation. The NOP instruction will do so.
.setsect .text, 8800h CLRC XF ; Turn off XF LED. 1 cycle NOP ; No operation. 1 cycle. NOP ; No operation. 1 cycle. NOP ; No operation. 1 cycle. NOP ; No operation. 1 cycle. SETC X ; Turn on XF LED. 1 cycle B start ; Go round again. 4 cycles
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

start:

The Output Taken From The XF pin

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Example 4 : Generating a Time Delay

The Accumulator is a 32 bit long R/W register which is used as a storage for the arithmetic results. LACC is the instruction used for storing an immediate value in the accumulator. SUB means subtract a value from the accumulator contents. BCND is a conditional looping instruction.

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Program Source Code


setsect .text, 8800h start:

SETC SXM SETC XF LACC #7FFFh SUB #1 BCND loop1, NEQ

loop1:

CLRC XF LACC #7FFFh


loop2:

SUB #1 BCND loop2, NEQ

B start

; Turn on sign-extension mode. ; Turn on XF LED. ; Load initial value of 7FFFh into the ; accumulator. The accumulator ; now contains 00007FFFh. ; Decrement the accumulator. ; Test the accumulator. If the accumulator ; does not contain zero (the condition NEQ ; evaluates to TRUE) then branch to the ; label loop1. ; Turn off XF LED. ; Load initial value of 7FFFh into the ; accumulator. The accumulator ; now contains 00007FFFh. ; Decrement the accumulator. ;Test the accumulator. If the accumulator ; does not contain zero (the condition NEQ ; evaluates; to TRUE) then branch to the ; label loop2. ; Go round again from beginning.

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Calculating The Delay Time


.setsect .text, 8800h
LACC #7FFFh
; 2 cycles.

loop:

SUB #1

; 1 cycle.

BCND loop, NEQ ; 4 cycles when TRUE.

; 2 cycles when FALSE.

The delay loop

The execution time will be (2 + 32766 x 5 + 1 + 2) x 0.4s = 65535 s = 0.0655 seconds.

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

The Generated Waveform

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Example 5: Generating Longer Time Delay

Just, turn off the Sign Extension mode, and load the accumulator with a value more than 7FFFh ( less than FFFFFFFFh ). Now your delay loop more longer than the previous example.

The execution time will be

[2 + (ACC-1) x 5 + 1 + 2] x 0.4s
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Program Source Code


start:

.setsect .text, 8800h CLRC SXM ; Turn off sign-extension mode. SETC XF ; Turn on XF LED. LACC #0FFFFh ; Load initial value of FFFFh into the SUB #1 BCND loop1, NEQ
; accumulator. The accumulator ; now contains 0000FFFFh. ; Decrement the accumulator. ; Test the accumulator. If the accumulator ; does not contain zero (the condition NEQ ; evaluates to TRUE) then branch to the ; label loop1. ; Turn off XF LED. ; Load initial value of FFFFh into the ; accumulator. The accumulator ; now contains 0000FFFFh. ; Decrement the accumulator. ;Test the accumulator. If the accumulator ; does not contain zero (the condition NEQ ; evaluates; to TRUE) then branch to the ; label loop2. ; Go round again from beginning.

loop1:

CLRC XF LACC #0FFFFh


loop2:

SUB #1 BCND loop2, NEQ

B start

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

The Generated Waveform

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Example 6: Saving The ACCUMULATOR at The Data Memory

DSP memory is divided into Pages, every Page contains 128 addresses and every address contains a 16 bit long word.
In other words the DSP memory locations are 16 bits Mapped Registers.

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Program Source Code


start: .setsect .text, 8800h LDP #6h ; Data page 6. Gain access to data memory
; addresses 300h to 37Fh.

SETC SXM LACC #0FEDCh SACH 0h

; Turn on sign-extension mode. ; Load accumulator with the known test value ; FFFFFEDCh. ; Store the high word of the accumulator at ; data memory address 300h + 0h = 300h. ; This data memory address now contains ; FFFFh. ; Store low word of accumulator at data ; memory address 300h + 1h = 301h. This ; data memory address now contains FEDCh. ; Go round again.

SACL 1h

B start

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Program Results

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Example 7: Reading a Value From a Mixed I/O Port

The F243 DSK has a programmable Control Registers which control the data direction.
Using these Registers we can have a mixed I/O ports to communicate with the DSP outside world.

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Program Source Code


start:

.setsect .text, 8800h LDP #225 ; Data page 225. Gain access to data
; memory addresses 7080h to 70FFh.

SPLK #0F0F0h, 1Ch ; Test purposes. Write at known value to


; PCDATDIR at data memory address ; 7080h + 1Ch = 709Ch.

loop:

LACC 1Ch

; Load contents of PCDATDIR at data memory ; address 7080h + 1Ch= 709Ch into the ; accumulator.

AND #000Fh
LDP #6 SACL 20h LDP #225 B loop

; Clear all bits except bit 3 to bit 0. The ; accumulator now contains the input data only
; Data page 6. Gain access to data memory ; addresses 300h to 37Fh. ; Save at 300h + 20h = 320h for later use. ; Data page 255. Page used by PCDATDIR. ; Go round again.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Program Results Shown From The Data Memory Registers

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Program Results Shown From The Data Memory Registers

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Program Results Shown From The Data Memory Registers

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Program Results Shown From The Data Memory Registers

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Program Results Shown From The Data Memory Registers

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Example 8: Filling a Block of Data Memory With a Particular Value.

Another method to access the DSP memory locations, is to use the Indirect Addressing mode. This method make the moving between addresses in data memory more easy than the Direct Method.
Just fill your Auxiliary Registers and go on.

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Program Source Code


.setsect ".text", 8800h MAR *, AR4 ; ARP = 4. Use AR4 for indirect LAR AR4, #3FFh LACC #100h SPLK #55AAh, *; addressing. ; AR4 points to address 300h. ; Number of counts = 256. ; Store the immediate value 0 ; decimal at the data memory ; address pointed to by AR4. ; Increment AR4 to point to next ; data memory address. ; Decrement counter. ; Test if counter has reached ; zero. If not, go round loop again. ; Return to beginning.

start:

loop:

SUB #1 BCND loop, NEQ B start

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Data Memory Targets Have Been Filled

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Example 9: Generating 100 kHz Signal Using Timers

The peripheral set for the F243 device includes:

Event Manager: Timers and PWM generators for Digital Motor Control

The Event Manager module provides a broad range of functions and features that are particularly useful in Motion Control and Motor Control applications.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Program Source Code


start: LDP #DP_DGCR SPLK #1000h, OCRA
; Data Page for OCRA. ; T1PWM output on pin ; IOPC4. LDP #DP_EV ; Data page for timers. SPLK #8142h, T1CON ; Internal clock, GP T1 off. SPLK #42h, GPTCON ; Active high output on ; IOPC4. SPLK #63h, T1PR ; 99 + 1 generates 100kHz. SPLK #32h, T1CMP ; 50% duty cycle. SPLK #0FFFEh,T1CNT ; Timer count value before ; counter starts (-2). SPLK #9142h, T1CON ; GP T1 on. B loop ; Loop forever.

loop:

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Output Waveform Taken From IOPC4 Pin

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Example 10: Controlling The Duty Cycle Of Timers Output By A/DC Result.

The peripheral set for the F243 devices includes:

A/D: 10-bit 1, 1-s conversion, 8 channel,


Analog-To-Digital converter.

Using an analogue input, we can control many functions carried out by the GP Timers.

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Program Source Code


DP_EV DP_DGCR

.setsect ".text", 8800h .set 232 ; Data page for Event


.set 225
.set 10h
; Manager ; Data page for digital ; control registers ; Output Control register ; General-Purpose Timer ; Control Register ; GP Timer 1 Count Register ; GP Timer 1 Compare ; Register ; GP Timer 1 Period Register ; GP Timer 1 Control ; Register

OCRA GPTCON
T1CNT T1CMP T1PR T1CON

.set 0h .set 1h .set 2h .set 3h .set 4h

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Program Source Code


DP_DIGCR OCRA DP_ADC ADCTRL1 ADCTRL2 ADCFIFO1 DP_EV GPTCON T1PR T1CMP T1CNT T1CON

.setsect ".text", 8800h .set 225 ; Data Page for Digital .set 10h .set 224 .set 32h .set 34h .set 36h .set 232 .set 0h .set 3h .set 2h .set 1h .set 4h
; control ; Output control register ; Data Page for ADC ; ADC Control Register 1 ; ADC Control Register 2 ; ADC measured value ; Data Page for Event ; Manager ; GP Timer Control Register ; Timer 1 period register ; Timer 1 compare register

; Timer 1 count
; Timer 1 control register

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Program Source Code


start: LDP #DP_DIGCR
; Data Page for Digital control SPLK #1000h, OCRA ; Configure T1PWM on IOPC4. LDP #DP_ADC ; Data Page for ADC. SPLK #0C03h, ADCTRL1 ; Channel 0. Continuous ;conversion.Start conversion

SPLK #0005h, ADCTRL2 LDP #DP_EV SPLK #8142h, T1CON SPLK #41h, GPTCON SPLK #03FEh, T1PR SPLK #0h, T1CMP SPLK #0FFFEh, T1CNT SPLK #9142h, T1CON CLRC SXM

; Conversion time. ; Data Page for timers. ; GP T1 off. ; PWM active low. ; Output period = 1023. ; Start with output off. ; Set count to negative. ; Enable GP Timer 1. ; Ensure ADCFIFO1 is taken ; as a positive value.

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Program Source Code

loop:

LDP #DP_ADC ; Page 224 ADC LACC ADCFIFO1, 10 ; Load accumulator with
; result of ADC conversion ; but shifted 10 places to ; the left.

LDP #DP_EV SACH T1CMP B loop

; Change to timer page. ; Store new value as duty cycle. ; Go round again.

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Output Waveform Taken From IOPC4 Pin

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Output Waveform Taken From IOPC4 Pin

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Output Waveform Taken From IOPC4 Pin

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Output Waveform Taken From IOPC4 Pin

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

Output Waveform Taken From IOPC4 Pin

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

End of

Chapter 3

Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.

You might also like