|
|
CD245x DSP Tutorial

This page will give you an
example of program (firmware) development using a CD2450A evaluation kit.
The free version of the evaluation kit runs on any DOS based PC (Windows9X,ME,2000,NT,XP)
and includes
- CD2450A Assembler/Linker
(Free Version)
- CD2450A BUGSFINDER Program
(Free Version)
The manuals for these CD2450A
related programs can be downloaded from the publication page of this site.
Should you need CD2450A DSP manual or other printed manuals, please contact
Clarkspur Design, Inc. at c s @ c l a r k s p u r . c o m .
One simple sin(wt) wave generator program will be developed using this
evaluation kit through this page. The flow diagram of the development
is shown in fig. 1. First, a program source file will be made using your
favorite ASCII file editor. Then, the file is assembled/linked to get
an object file. This object file can be downloaded to either a CD2450A
emulator board (sold separately) directly for a real time operation, or
BUGSFINDER simulator/debugger on PC. You can check the functions of the
program through the PC screen in either case.
Fig.1
Demo Flow
Program Example (Sine wave
generation)
This example gives a SIN(x) output
to EXT0 register and RAM0:0001 address. A -1 to +1 angle input is projected
to -pi to +pi. In other word, the input values are scaled by 1/pi. There
is a simple and common algorithm to generate a Sin value as in Fig.2.
Fig.2 Sin approximation algorithm.
#
# Sin Pi*x generation example routine
# (c)1994 Clarkspur Design, Inc.
#
#
#
# RAM0:0000 angle -1 to 1
# R2 incremental value
# EXT0, RAM0:0001 output value
# (Sin Routine)
# AH Before:Angle Input After:Result sin(pi*x)
#
ldi st,'h0
ldsi r3,'h3ff #Stack Pointer
ldsi r2,'h3f8
loop:
ldsi r0,'h0
ld ah,(r0)
add a,r2,rs8
ld (r0),ah
modr r4,r2+!
call @sin
call @out
bra @loop
sin:
ld r6,ah
mod rs8
mod rs2
ansi a,'h3e # ~x * 2 -> AH
addi a,@ttop # + Table_Top
ld r1,ah # Pointer R1 for ~x
ld ah,r6
andi ah,'h07ff # delta x
mod ls2 # * 4
ld x,ah
ldi y,'h6487 # * pi/4
ld ah,ph
ld x,ph
ld y,(r1+!)p # * Cos pi*~x
ld ah,ph
ld ah,ph
add a,(r1+!)p # + Sin pi*~x
ret
out:
ldsi r0,'h1
ld (r0),ah
tgl ah,15 # Invert Sign bit
ld ext0,ah # Output to ext0
ret
ds 'h10
trap:
bra @trap
ttop:
DW 'H7D00
DW 'H0000 # 0
DW 'H7A99
DW 'H1863 # 6.25E-002
DW 'H737C
DW 'H2FD6 # .125
DW 'H67EF
DW 'H4572 # .1875
DW 'H5863
DW 'H5863 # .25
DW 'H4572
DW 'H67EF # .3125
DW 'H2FD6
DW 'H737C # .375
DW 'H1863
DW 'H7A99 # .4375
DW 'H0000
DW 'H7D00 # .5
DW 'HE79D
DW 'H7A99 # .5625
DW 'HD02A
DW 'H737C # .625
DW 'HBA8E
DW 'H67EF # .6875
DW 'HA79D
DW 'H5863 # .75
DW 'H9811
DW 'H4572 # .8125
DW 'H8C84
DW 'H2FD6 # .875
DW 'H8567
DW 'H1863 # .9375
DW 'H8300
DW 'H0000 # -1
DW 'H8567
DW 'HE79D # -.9375
DW 'H8C84
DW 'HD02A # -.875
DW 'H9811
DW 'HBA8E # -.8125
DW 'HA79D
DW 'HA79D # -.75
DW 'HBA8E
DW 'H9811 # -.6875
DW 'HD02A
DW 'H8C84 # -.625
DW 'HE79D
DW 'H8567 # -.5625
DW 'H0000
DW 'H8300 # -.5
DW 'H1863
DW 'H8567 # -.4375
DW 'H2FD6
DW 'H8C84 # -.375
DW 'H4572
DW 'H9811 # -.3125
DW 'H5863
DW 'HA79D # -.25
DW 'H67EF
DW 'HBA8E # -.1875
DW 'H737C
DW 'HD02A # -.125
DW 'H7A99
DW 'HE79D # -6.25E-002
Now, try it on the simulator.
First, you need to assemble the
source file. You can use "ASM2450.EXE" assembler program by typing
> ASM2450 sin.s
where "sin.s" is the source
file you have just made. The ASM2450 automatically generates two files
, regardless of whether the assembly was or was not successful. One is
an object file, the other a listing file. You can check the listing file
to see Errors, if any. (But, please remember it does not necessarily mean
your program has no error even if the ASM2450 does not point any error.
Free version of the tools do not check the detailes of syntax error.)
The default file names for those are sin.o and sin.l, though you can specify
any legal name on them if you wish. (Please download Assembler Description
from the "Literature" page.)
As more than one object file
are linked together to form a final executable program in normal case,
successive linkage processing is necessary for this purpose. Even if you
have only one object file, you still need to go through the linkage process
to generate an executable file. In this example, we try to link sin.o
with an interrupt vector description object file. When you start the simulator
later on, you can start your program by giving a reset signal on the net
with this interrupt vector assignment. The CD2450 linker always requires
a linkage spec file describing an output file name, series of input object
file names, absolute program starting address etc..
- sin.l file
#01-31-1996 10:37:51
#
# Sin Pi*x generation example routine
# (c)1994 Clarkspur Design, Inc.
#
#
#
# RAM0:0000 angle -1 to 1
# R2 incremental value
# EXT0, RAM0:0001 output value
# (Sin Routine)
# AH Before:Angle Input After:Result sin(pi*x)
#
0000 0840 0000 ldi st,'h0
0002 7FFF ldsi r3,'h3ff #Stack Pointer
0003 5FF8 ldsi r2,'h3f8
loop:
0004 1C00 ldsi r0,'h0
0005 0210 ld ah,(r0)
0006 9252 add a,r2,rs8
0007 4210 ld (r0),ah
0008 1606 modr r4,r2+!
0009 48F0 000F call @sin
000B 48F0 0024 call @out
000D 4C00 0004 bra @loop
sin:
000F 5312 ld r6,ah
0010 90D0 mod rs8
0011 9090 mod rs2
0012 B83E ansi a,'h3e # ~x * 2 -> AH
0013 8870 003B addi a,@ttop # + Table_Top
0015 5211 ld r1,ah # Pointer R1 for ~x
0016 1312 ld ah,r6
0017 A800 07FF andi ah,'h07ff # delta x
0019 9010 mod ls2 # * 4
001A 0021 ld x,ah
001B 0830 6487 ldi y,'h6487 # * pi/4
001D 0017 ld ah,ph
001E 0027 ld x,ph
001F 0A35 ld y,(r1+!)p # * Cos pi*~x
0020 0017 ld ah,ph
0021 0017 ld ah,ph
0022 8A75 add a,(r1+!)p # + Sin pi*~x
0023 0257 ret
out:
0024 1C01 ldsi r0,'h1
0025 4210 ld (r0),ah
0026 EE1F tgl ah,15 # Invert Sign bit
0027 0081 ld ext0,ah # Output to ext0
0028 0257 ret
0029 0010 ds 'h10
trap:
0039 4C00 0039 bra @trap
ttop:
003B 7D00 DW 'H7D00
003C 0000 DW 'H0000 # 0
003D 7A99 DW 'H7A99
003E 1863 DW 'H1863 # 6.25E-002
003F 737C DW 'H737C
0040 2FD6 DW 'H2FD6 # .125
0041 67EF DW 'H67EF
0042 4572 DW 'H4572 # .1875
0043 5863 DW 'H5863
0044 5863 DW 'H5863 # .25
0045 4572 DW 'H4572
0046 67EF DW 'H67EF # .3125
0047 2FD6 DW 'H2FD6
0048 737C DW 'H737C # .375
0049 1863 DW 'H1863
004A 7A99 DW 'H7A99 # .4375
004B 0000 DW 'H0000
004C 7D00 DW 'H7D00 # .5
004D E79D DW 'HE79D
004E 7A99 DW 'H7A99 # .5625
004F D02A DW 'HD02A
0050 737C DW 'H737C # .625
0051 BA8E DW 'HBA8E
0052 67EF DW 'H67EF # .6875
0053 A79D DW 'HA79D
0054 5863 DW 'H5863 # .75
0055 9811 DW 'H9811
0056 4572 DW 'H4572 # .8125
0057 8C84 DW 'H8C84
0058 2FD6 DW 'H2FD6 # .875
0059 8567 DW 'H8567
005A 1863 DW 'H1863 # .9375
005B 8300 DW 'H8300
005C 0000 DW 'H0000 # -1
005D 8567 DW 'H8567
005E E79D DW 'HE79D # -.9375
005F 8C84 DW 'H8C84
0060 D02A DW 'HD02A # -.875
0061 9811 DW 'H9811
0062 BA8E DW 'HBA8E # -.8125
0063 A79D DW 'HA79D
0064 A79D DW 'HA79D # -.75
0065 BA8E DW 'HBA8E
0066 9811 DW 'H9811 # -.6875
0067 D02A DW 'HD02A
0068 8C84 DW 'H8C84 # -.625
0069 E79D DW 'HE79D
006A 8567 DW 'H8567 # -.5625
006B 0000 DW 'H0000
006C 8300 DW 'H8300 # -.5
006D 1863 DW 'H1863
006E 8567 DW 'H8567 # -.4375
006F 2FD6 DW 'H2FD6
0070 8C84 DW 'H8C84 # -.375
0071 4572 DW 'H4572
0072 9811 DW 'H9811 # -.3125
0073 5863 DW 'H5863
0074 A79D DW 'HA79D # -.25
0075 67EF DW 'H67EF
0076 BA8E DW 'HBA8E # -.1875
0077 737C DW 'H737C
0078 D02A DW 'HD02A # -.125
0079 7A99 DW 'H7A99
007A E79D DW 'HE79D # -6.25E-002
Fatal Errors: 0
Warnings : 0
Notes : 0
---- ASM2450 completed ----
- intv.l file
#01-30-1996 11:14:39
#
# Interrupt Vector Default value.
#
0000 8000 dw 'h8000 # Reset
0001 8000 dw 'h8000 # Int0
0002 8000 dw 'h8000 # Int1
0003 8000 dw 'h8000 # Int2
Fatal Errors: 0
Warnings : 0
Notes : 0
---- ASM2450 completed ----
- sin.k file (Linkage spec. file.)
#
# Sin Generation Program Linkage Spec. File
# (c)1994 Clarkspur Design, Inc.
#
->sin.x
list->sin.ll
org 8000
sin.o
org fffc
intv.o
You type
> LINK2450 sin.k
to get an executable object
file named sin.x. Please note the linker will quit the execution
when it encounters any problem. Most common such problems come from the
address overflow due to labels used in the short Immediate instructions,
or missing designated files.The linked absolute object code can be downloaded
to the CD2450A emulator for a real time execution. Use DNLD sin.x
from the command prompt of the emulator control program (EC2450.EXE),
or use Load sin.x at the command window of the BUGSFINDER to load
the program on the simulator.
Simulation
Now, once you download the program
on either H/W emulator or S/W simulator, you can run them to see the output
waveform. For the simulator, you can set a break point where the output
datum is ready at some register or RAM address, and write the datum into
a file you specify. When break happens, you can check the condition then
proceed to several action menus including collect data, plot on screen etc.
Also, you can simulate interrupt generation by setting the break at every
N cycles etc.. The Evaluation version of the BUGSFINDER is limited in its
program size to 128 words, and the data memory size to 64 words each. All
other functions are basically same as the full version except that the revision
generation may be one year+ older than the latest version. You can set up
the BUGSFINDER so that your output data from the program are accumulated
in a file for the later analysis, or If you want see the output on-the-fly,
you can set the BUGSFINDER to show it graphically, etc.. A very powerful
break point function of the BUGSFINDER allows I/O simulation, waveform probing.
up to your best imagination.
More Training
- Actually, the example program
generates a "sweep" sin wave. (The angle speed parameter stored in R2
is incremented every time a new output data is computed.) Try to generate
a single frequency sin wave by eliminating MOD R2 instruction in address
8. You can also change the frequency.
- If you have one hour free
time, try to improve this program. You can minimize the distortion error
by using bigger course sin table. You can eliminate cos table by knowing
sin(x+pi/2) = cos(x). You can place the table on the data RAM to minimize
the table look up time.
- Please refer to the test.l
file from the assembler diskette, when you check the mnemonic of the
assembler. As the free version of the assembler was made far before
the development of the chip, some of the description differ from the
CD2450A reference manual.
|