Auto Code Generation for F2803x Target

PSIM Tuto
orial
Auto Code Genera
G
ation fo
or F2803x Ta
arget
Jaanuary 20155
Powersim Inc.
www
w.powersimtecch.com
Au
uto Code Geneeration for F2 803x Target
PSIM’s SimCoder
S
Module,
M
comb
bined with th
he F2803x H
Hardware Taarget, can generate readyy-torun code from a PSIM
M control scchematic for hardware baased on TI F
F2803x series fixed-poinnt
DSP.
This tuto
orial describees, step by sttep, how to generate
g
codde in PSIM, ccompile andd upload the code
in CodeC
ComposerStu
udio, and run
n it on F2803
3x DSP harddware.
To illustrrate the proccess, we use the circuit “D
DC_DC Bucck 1_ch.psim
msch” as an eexample. Thhis
example is located in
n the sub-fold
der “Examples\SimCodeer\F2803x T
Target\TI 1-C
Ch DC-DC w
with
SCI” in the
t PSIM dirrectory.
To keep the
t original example uncchanged, wee will copy thhe folder to “C:\ F280355 DC-DC”, aand
use this folder
f
as the working follder in this tu
utorial.
1.
PSIM
M Setup forr Code Geneeration
In PSIM,, load the example schem
matic file “D
DC_DC Buckk 1_ch.psimssch” as show
wn below.
-2-
Powersim Inc.
www
w.powersimtecch.com
Au
uto Code Geneeration for F2 803x Target
mple generaates the code for the TI 2-Channel DC
C/DC Buck Converter K
Kit
DCDC2KIT)) with a Piccolo F28035 controlCAR
RD. Only onee channel is implementeed in
mple. One caan simulate th
his circuit by
y selecting S
Simulate >>
> Run Simullation.
d-point code generation, a circuit mu
ust contain ellements from
m the F2803x Hardware
brary. The liibrary is locaated at Elem
ments >> Sim
mCoder >> F
F2803x Tarrget. A list oof the
s shown belo
ow.
mulation Co
ontrol Param
meters
he code is geenerated, Sim
mCoder paraameters mustt be properlyy set in Simuulation Contrrol
Double click on the Simu
ulation Contrrol block (thhe clock imagge). Click onn the SimCooder
set the param
meters as sho
own below.
-3-
Powersim Inc.
www
w.powersimtecch.com
Au
uto Code Geneeration for F2 803x Target
The settin
ngs are:
Hardware
H
Ta
arget: Set to F2803x and
d RamDebugg. RamDebugg is selected in this exam
mple
for debugg
ging.
CPU
C
Version
n: Select F28
8035 (80pin).
Check
C
Fixed--Point Rangee: Check thiss box to checck the fixed--point range for overflow
w.
Default
D
Data Type: Selecct IQ24 for th
his example..
Please no
ote that checcking the fixeed-point range for overfl
flow requiress additional ccomputationnal
effort. It is recommen
nded that on
ne performs this
t check affter the circuuit is close too be finalizedd.
Currently
y, PSIM can generate pro
oject files fo
or CCS v3.3 only. If onee uses a versiion newer thhan
v3.3, onee can use “Im
mport Legacy
y v3.3 Projeect” functionn.
1.2
Deefining F280
03x Target Elements
E
In this cirrcuit, severaal F2803x Taarget library elements arre used. All tthese elemennts must be
properly configured according
a
to
o the specificc target hardw
dware settinggs.
F2803x Hardware
H
Configuration
C
n: This element defines tthe I/O portss of the F28003x hardwarre.
One musst unlock thiss element to change the designation
d
of the I/O poort, and musst lock it
afterward
ds. In this ex
xample:
o A0 is desiignated as an
n A/D input channel for voltage meaasurement;
o GPIO2 is designated as
a PWM outtput;
o GPIO28 and
a GPIO29 are designaated for SCI communicattion; and
o GPIO39 is
i used as a digital
d
outpu
ut.
DSP Clock: Specify the
t DSP clocck parameteers for this prroject as folllows:
o DSP Clocck Source:
Internal oscillator 1
o External Clock
C
(MHzz): 10
o DSP Speeed (MHz):
60
SCI Conffiguration: Specify
S
the I//O pins, the speed, and pparity checkk of the SCI pport. The output
buffer sizze is determiined by the desired
d
waveeform resoluution and avaailable mem
mory space. T
The
SCI communication provides
p
a convenient
c
way
w to utilizee PSIM’s DS
SP Oscilloscope functionn.
The DSP
P Oscilloscop
pe is used to control the buck converrter’s outputt voltage andd monitor thee
values in
nside the DSP
P. The SCI input
i
allows the referencce value to bbe changed bby the DSP
Oscillosccope in real time,
t
and SC
CI outputs arre used to dissplay signalss it the DSP Oscilloscoppe in
real time.
A/D Converter (16 ch
hannel): Speecify the mod
de and gain of ADC chaannels. For thhis example,,
Channel A0 is in DC
C mode with a gain of 2.0
0
PWM Mo
odule (singlee phase): Speecify the PW
WM module source, the ooutput modee, switching
frequency
y, and many
y other settin
ngs of a singlle-phase PW
WM module. For further ddetailed
informatiion, please refer
r
to the SimCoder
S
Usser Manual.
1.3
Deefining Fixed
d-Point Positions
In the F2
2803x Targett code, Texaas Instrumentts' IQmath liibrary is useed for fixed-ppoint calculaation.
As shown
n in the figu
ure below, eaach of the no
on-hardware--related elem
ments can bee set as Defauult,
Integer, or
o fixed poin
nt with the IQ
Q number frrom 1 to 30.
-4-
Powersim Inc.
www
w.powersimtecch.com
Au
uto Code Geneeration for F2 803x Target
xample, the Default
D
fixed
d-point posittion is selectted for the ddigital filter bblock
_D2, which means that the
t output off this block w
will use the ffixed-point pposition of IQ20
ed in Defaultt Fixed-Point Position in
n Simulationn Control.
point calculaation, the sellection of thee fixed-poinnt position is an importannt issue. If thhe
int range is too
t low, the variable valu
ue may overrflow. But iff the fixed-pooint range iss too
calculation resolution will
w suffer. To
T address thhis problem, PSIM provides the funcction
oint range fro
om simulatio
on results, annd give indiccation if a paarticular outtput
the fixed-po
o overflow or
o already ov
verflow, or is too conserrvative in thee fixed-pointt position settting.
xample, afterr the simulattion, if the bo
ox Check Fiixed-Point R
Range under Simulation
>> SimCod
der is checkeed, the follow
wing dialog w
window will appear.
og window shows
s
that, for
f example, the output oof the digitall filter FILTE
ER_D2 is seet to
d the requireed setting is IQ30, which
h is more thaan sufficientt in the data rrange.
-5-
Powersim Inc.
www
w.powersimtecch.com
Au
uto Code Geneeration for F2 803x Target
Howeverr, as an exam
mple, if the default
d
fixed--position is sset to IQ29, it will not bee sufficient aas
some of the
t variabless will overflo
ow and others are close to overflow.. The fixed-ppoint range
check ressults are shown below:
The resullts show thatt the Summeer and A/D converter
c
out
utputs will ovverflow, andd the digital ffilter
and limitter outputs arre close to overflow.
PSIM's range check function
f
pro
ovides a conv
venient way to handle fixxed-point poositions.
1.4
Geenerating Co
ode
To generrate code, sellect Simulatte >> Generrate Code. T
The generateed code will be displayedd in a
separate window, as shown below
w.
ubfolder insiide the foldeer containingg the PSIM ccircuit file annd is named the
PSIM wiill create a su
same as the
t PSIM cirrcuit but with
h (C code) added
a
at the end. For thiss example prroject, this
subfolderr is C:\F2803
35 DC_DC\D
DC_DC Bucck 1_ch (C ccode).
In additio
on to the C code
c
file, PSIM also gen
nerates projecct files, link command fi
files, as well as
all other files necessaary for four different
d
pro
oject buildingg configurattions: RAM Debug, RAM
M
Release, Flash Release, and Flash
h RAM Releease. All theese files are sstored in the newly creatted
subfolderr C:\F28035 DC_DC\DC
C_DC Buck 1_ch (C codde).
-6-
Powersim Inc.
www
w.powersimtecch.com
Au
uto Code Geneeration for F2 803x Target
2.
CCS
S Setup
The PSIM
M generated project is fo
or CCS v3.3,, the Code C
Composer Stuudio from T
TI should be
version 3.3
3 or higherr. If you are using
u
CCS v3.3,
v
the projject can be oopened direcctly. For CCS
S4
or higherr, you must use
u the Impo
ort Legacy v3
3.3 Project ffunction in C
CCS. Below CCS v5.5 iss
used to sh
how the way
y to load and
d debug the program.
p
2.1
Im
mport Projecct into CCS
Launch CCS
C v5.5. Iff this is the first
fi time you
u load the prooject, go to P
Project >> IImport Leggacy
CCSv3.3
3 Project. Th
he dialog is shown below
w on the leftt. Click on B
Browse... to cchoose
"C:\F280
035 DC-DC\\ TI_DC_DC
C_Buck_1_ch (C code)\T
TI_DC_DC__Buck_1_chh.pjt", then cllick
on Next. The dialog will be show
wn as below on the right . Click on Finish to starrt importing.
If there iss no problem
m in importin
ng, the conveerted projectt will be autoomatically looaded. Projeect
Explorer of the CCS will appear as shown beelow.
-7-
Powersim Inc.
www
w.powersimtecch.com
Au
uto Code Geneeration for F2 803x Target
Note thatt the project configuratio
on is set to RAM
R
Debug . With this ssetting, all prrogram and ddata
will be lo
oaded to the RAM memo
ory.
To comp
pile the projeect, right mou
use click on the project nname "TI_D
DC_DC_Bucck_1_ch" in tthe
panel of the
t Project Explorer,
E
theen click on "Build Projecct" in the poppped up mennu. Or click on
the project name in th
he panel of Project
P
Expllorer to selecct it as the cuurrent projecct (the projecct
name chaanges to bold
d). Select Prroject >> Bu
uild to buildd the project or Project >
>> Rebuild A
All
to rebuild
d the whole project.
p
Afteer the compiiling is compplete, CCS w
will display tthe followingg:
The warn
ning message can be ignored. This warning
w
messsage is displlayed when pprogram is nnot
saved in the flash meemory.
-8-
Powersim Inc.
www
w.powersimtecch.com
Au
uto Code Geneeration for F2 803x Target
2.2
CC
CS Project Configuratio
C
on
Select Prroject >> Prroperties. Seet the properrties of the pproject “DC__DC_Buck 11_ch” as shoown
below.
The settin
ngs are:
o Configura
ation: Ram
mDebug (Actiive)
o Device Fa
amily: C200
00
o Device Va
ariant: TMS
S320F28035
o Connectio
on: Select th
he correct con
nnection froom the list, acccording to tthe JTAG
connectio
on you have.
o In the Advvanced settin
ngs, use the browser to ffind the file F
F28035_RA
AM_Lnk.cmdd in
the folderr C:\F28035 DC_DC\DC
C_DC Buck 1_ch (C codde).
o Click on Apply,
A
and then
t
OK.
Select Ru
un >> Debu
ug. The hardw
ware target will
w be connnected, and thhe CCS willl display the
Debuggeer window ass shown in th
he figure bellow. The codde is ready too run in targgeted DSP
hardwaree.
Select Ru
un >> Resume to resum
me the code execution.
e
Thhe LED dispplay of the E
EVM would
display th
he dc-dc con
nverter outpu
ut voltage at 3.3V (+/- 0 .05V).
Section 4 of this tutorial will illustrate how to
o use DSP O
Oscilloscope to monitor tthe DSP inteernal
variabless and to conttrol the converter voltagee.
-9-
Powersim Inc.
www
w.powersimtecch.com
Au
uto Code Geneeration for F2 803x Target
2.3
CC
CS Target Configuratio
C
on
Before lo
oading a prog
gram to the target,
t
we neeed to createe a target connfiguration ffor the targett
board. In
n this examplle, a TI’s TM
MS320F2803
35 controlCA
ARD is usedd. Select Vieew >> Targeet
Configurrations. A dialog
d
windo
ow will appear as followss in CCS.
Rightt mouse click
k on User Defined
D
in th
he Target Coonfiguration dialog, then select New
Targ
get Configurration in thee pop-up men
nu. A dialogg will appearr as below.
- 10 -
Powersim Inc.
www
w.powersimtecch.com
Au
uto Code Geneeration for F2 803x Target
Change the
t file namee as you wish
h (here it is called
c
"F28003x", and thee file extension will be
"ccxml")), then click on
o Finish. A dialog nam
med "F2803xx.ccxml" willl appear as bbelow.
- 11 -
Powersim Inc.
www
w.powersimtecch.com
Au
uto Code Geneeration for F2 803x Target
In the "C
Connection" combo
c
box, choose the emulator
e
youu will use (fo
for example, "Spectrum
Digital C2000
C
XDS5
510LC Emullator"), then check "TMS
S320F280355" in the list box of "Boaard of
Device". Click on Sa
ave to save th
he configuraation.
Back to the
t "Target Configuratio
C
ons" dialog, right
r
click onn the "F28033x.ccxml" coonfigurationn, and
move thee cursor to "L
Link File to Project" in the
t pop-up m
menu. All proojects will bbe displayed in
the sub-m
menu. Selectt the project "TI_DC_DC
C_Buck_1_cch" as shownn below.
Now, cheeck if "F280
03x.ccxml" iss added to th
he project in the Project Explorer, ass shown beloow.
3.
Targ
get Hardwa
are Setup
Insert TI TMS320F28035 contro
olCARD into
o the 2-Channnel DC/DC Buck Conveerter Kit
(TMDSD
DCDC2KIT)), as shown below.
b
- 12 -
Powersim Inc.
www
w.powersimtecch.com
Au
uto Code Geneeration for F2 803x Target
Connect the J1 conneector of the board
b
to the JTAG emullator, and theen connect thhe JTAG
emulatorr to the comp
puter’s USB port. After connecting
c
tthe power to the board, tturn on Switcches
SW1 and
d SW2 on thee board. Set SW3 to the Ch2 position to display voltage.
4.
Run
nning Code in
i DSP Target
4.1
Load Code to DSP Targeet
In CCS, click
c
on "TI_
_DC_DC_B
Buck_1_ch" project
p
to seet it as the cuurrent projecct (the currennt
project name will app
pear in bold)). Then selecct Run >> D
Debug to connnect the com
mputer to thee
DSP. If the connectio
on is successsful, the prog
gram will bee upload to thhe target, annd the F280335
DSP willl automatically reset and
d run to the start
s
place off the main fuunction as shhown below.
- 13 -
Powersim Inc.
www
w.powersimtecch.com
Au
uto Code Geneeration for F2 803x Target
4.2
h Release Veersion)
Load Code to DSP (Flash
There aree 4 configuraations in a generated pro
oject, they arre
RamRelease:
R
Load program to RAM areea and run inn RAM
RamDebug:
R
Load program to RAM areea and run inn RAM
FlashRelease and
Load program to DSP’s flaash memory and run in fflash
FlashRamRellease:
Load program to flash mem
mory but coppy program into RAM aand
ran
n in RAM
- 14 -
Powersim Inc.
www
w.powersimtecch.com
Au
uto Code Geneeration for F2 803x Target
To use a different con
nfiguration, right click on
o the projecct name in Prroject Exploorer. Move thhe
nfigurations" in the pop-u
up menu andd select a connfiguration oof your choicce.
cursor to "Build Con
mpiled againn, then the coode can be
After chaanging configuration, thee project neeeds to be com
uploaded
d to the DSP with the sam
me method as
a described in Section 44.1.
4.3
Ru
un Code in DSP
D Target
To run th
he code in the DSP, wee can use thee toolbar in the "Debugg" toolbar ass shown beloow to
resume, stop,
s
step intto, step overr and step retturn to run thhe program.
5.
Mon
nitoring Wa
aveforms wiith DSP Osccilloscope
At the en
nd of Section
ns 4.3, the co
ode is runnin
ng in the targgeted DSP too generate a converter ouutput
of 3.3V (+/-0.05V).
(
Now,
N
one maay use PSIM
M’s DSP Osccilloscope feeature to monnitor the
variabless inside the DSP
D and to control
c
the co
onverter outtput voltage.
Connect the SCI portt of the hardw
ware target to
t the compuuter.
- 15 -
Powersim Inc.
www
w.powersimtecch.com
Au
uto Code Geneeration for F2 803x Target
PSIM. Selectt Utilities >>
> DSP Oscillloscope. Thhis will launcch the DSP O
Oscilloscopee as
elow.
orrect serial port numberr, baud rate, and parity ccheck. They must be idenntical to thesse in
Configuratio
on block in th
he PSIM circcuit.
e Connect bu
utton at the leeft bottom of the scope ppanel. All naames of SCI output and input
s will be listeed on the left
ft side of the panel, as shhown below.
variables av
vailable for monitoring
m
arre Vfdbk annd Ref_out. S
Select the vaariables to
on the scope screen.
- 16 -
Powersim Inc.
www
w.powersimtecch.com
Au
uto Code Geneeration for F2 803x Target
To chang
ge the DC-D
DC converter output voltaage, modify the value Vrref to 2 and click the Up
pdate
button. The
T LED disp
play of the converter
c
boaard will channge to the neew value. Thhe figure bellow
shows the waveforms with the neew value of Vref.
V
6.
Cod
de Composerr Studio Reeferences
For furth
her informatiion about thee Texas Instrrument’s Coode Composeer Studio, please refer too the
documen
nts in the link
ks below.

CCSv5
C
Getting
g Started GuideCCSv5 Getting Started Guide
htttp://processsors.wiki.ti.com/index..php/CCSv55_Getting_S
Started_Guide
- 17 -
Powersim Inc.
www
w.powersimtecch.com