Professional Documents
Culture Documents
Chapter 3
Chapter 3
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
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.
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.
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.
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.
; 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.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
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.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
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:
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
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.
loop1:
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.
loop:
SUB #1
; 1 cycle.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
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.
[2 + (ACC-1) x 5 + 1 + 2] x 0.4s
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
.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:
B start
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
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.
; 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.
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.
.setsect .text, 8800h LDP #225 ; Data page 225. Gain access to data
; memory addresses 7080h to 70FFh.
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.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
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.
start:
loop:
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
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.
loop:
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
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.
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.
OCRA GPTCON
T1CNT T1CMP T1PR T1CON
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
.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.
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.
loop:
LDP #DP_ADC ; Page 224 ADC LACC ADCFIFO1, 10 ; Load accumulator with
; result of ADC conversion ; but shifted 10 places to ; the left.
; 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.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
Mohammed Yousef Abd El ghany, Faculty of Eng., Comm. Dep. , 3rd year.
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.