SimCoder User Manual
SimCoder User Manual
SimCoder
User’s Guide
Chapter : -8
SimCoder User’s Guide
Version 2024.1
August 2024
Disclaimer
Altair Engineering Inc. (“Altair”) makes no representation or warranty with respect to the adequacy or accuracy of
this documentation or the software which it describes. In no event will Altair or its direct or indirect suppliers be
liable for any damages whatsoever including, but not limited to, direct, indirect, incidental, or consequential
damages of any character including, without limitation, loss of business profits, data, business information, or any
and all other commercial damages or losses, or for any damages in excess of the list price for the licence to the
software and documentation.
1 SimCoder Overview
1.1 Introduction 1
1.2 SimCoder Setup in Simulation Control 1
1.3 Elements for Code Generation 2
3 Event Handling
3.1 Basic Concept 16
3.2 Elements for Event Handling 16
3.3 Restrictions on Subcircuits with Events 17
4 SimCoder Libraries
4.1 Overview 19
4.2 Elements from Standard PSIM Library 19
4.2.1 Defining Global Parameters in Parameter File 19
4.2.2 Generating Sawtooth Waveform 21
4.3 Event Control Elements 21
4.3.1 Input Event and Output Event 22
4.3.2 Default Event 22
4.3.3 Event Connection 23
4.3.4 Flag for Event Block First Entry 23
4.4 Global Variable 23
4.5 Interrupt 25
4.6 SimCoder C Block 26
5 IQmath Library
5.1 Overview 29
5.2 IQmath Data Type and Range/Resolution 29
ii-5 Chapter :
7.15.1 SPI Configuration 99
7.15.2 SPI Device 100
7.15.3 SPI Input 101
7.15.4 SPI Output 102
7.16 Controller Area Network (CAN) Bus 104
7.16.1 CAN Configuration 104
7.16.2 CAN Input 105
7.16.3 CAN Output 106
7.17 Interrupt Time 107
7.18 Project Settings and Memory Allocation 107
Chapter : iii
-4
9.3 DSP Clock 153
9.4 PWM Generators 154
9.4.1 3-Phase PWM 155
9.4.2 1-Phase PWM and 1-Phase PWM (phase shift) 158
9.4.3 2-Phase PWM 164
9.4.4 Single PWM (shared with capture) 169
9.4.5 Synchronization Between PWM Blocks 169
9.5 Variable Frequency PWM 170
9.6 Start PWM and Stop PWM 171
9.7 Trip-Zone and Trip-Zone State 171
9.8 A/D Converter 172
9.9 Comparator 176
9.9.1 Comparator Input 176
9.9.2 Comparator Output 177
9.9.3 Comparator DAC 178
9.10 Digital Input and Digital Output 178
9.11 Capture and Capture State 179
9.12 Serial Communication Interface (SCI) 179
9.12.1 SCI Configuration 180
9.12.2 SCI Input 180
9.12.3 SCI Output 181
9.13 Serial Peripheral Interface (SPI) 181
9.13.1 SPI Configuration 181
9.13.2 SPI Device 182
9.13.3 SPI Input 184
9.13.4 SPI Output 185
9.14 Interrupt Time 186
9.15 Project Settings and Memory Allocation 186
iv
10.15 Input X-BAR, Output X-BAR, and PWM X-BAR 217
10.15.1 Input X-BAR 218
10.15.2 Output X-BAR 218
10.15.3 PWM X-BAR 219
10.16 Encoder, Encoder State, and Encoder Index/Strobe Position 220
10.17 Up/Down Counter 221
10.18 Capture and Capture State 222
10.19 Serial Communication Interface (SCI) 223
10.19.1 SCI Configuration 223
10.19.2 SCI Input 223
10.19.3 SCI Output 224
10.20 Serial Peripheral Interface (SPI) 224
10.20.1 SPI Configuration 224
10.20.2 SPI Device 225
10.20.3 SPI Input 226
10.20.4 SPI Output 227
10.21 Controller Area Network (CAN) Bus 228
10.21.1 CAN Configuration 229
10.21.2 CAN Input 229
10.21.3 CAN Output 230
10.21.4 CAN Remote Request 231
10.22 Interrupt Time 232
10.23 Project Settings and Memory Allocation 232
Chapter : v
-2
11.17 Up/Down Counter 268
11.18 Capture and Capture State 268
11.19 Serial Communication Interface (SCI) 269
11.19.1 SCI Configuration 269
11.19.2 SCI Input 270
11.19.3 SCI Output 270
11.20 Serial Peripheral Interface (SPI) 271
11.20.1 SPI Configuration 271
11.20.2 SPI Device 272
11.20.3 SPI Input 273
11.20.4 SPI Output 274
11.21 Controller Area Network (CAN) Bus 275
11.21.1 CAN Configuration 275
11.21.2 CAN Input 276
11.21.3 CAN Output 277
11.21.4 CAN Remote Request 277
11.22 Interrupt Time 278
11.23 Project Settings and Memory Allocation 279
13 TI DMC Library
13.1 Overview 298
13.2 ACI_FE: Flux Estimator of 3-phase Induction Motors 299
13.3 ACI_SE: Speed Estimator of 3-phase Induction Motors 300
13.4 ANGLE_MATH: Angle Wrap 302
13.5 CLARKE: Clarke Transformation 302
13.6 CUR_MOD: Current Model 304
13.7 IMPULSE: Impulse Generator 305
13.8 IPARK: Inverse Park Transformation 306
13.9 PARK: Park Transformation 307
13.10 PHASE_VOLT: Phase Voltage Reconstruction 308
vi
13.11 PID Controllers 308
13.11.1 PI: PI Controller with Anti-Windup 309
13.11.2 PI_REG4: PI Controller with Anti-Windup 310
13.11.3 PI _POS: PI Controller with Position Error Wrapper 310
13.11.4 PI _POS_REG4: PI Controller with Position Error Wrapper 311
13.11.5 PID_REG3: PID Controller with Anti-Windup 312
13.11.6 PID_GRANDO: PID Controller 312
13.12 RAMP_GEN: Ramp Generator 314
13.13 Ramp Control 315
13.13.1 RMP_CNTL: Ramp Control 315
13.13.2 RMP2CNTL: Ramp 2 Control 316
13.13.3 RMP3CNTL: Ramp 3 Control 317
13.14 SOMPOS: Sliding-Mode Rotor Position Observer 317
13.15 Speed Calculators 319
13.15.1 SPEED_EST: Speed Calculator 319
13.15.2 SPEED_FR: Speed Calculator with QEP Sensor 320
13.15.3 SPEED_PRD: Speed Calculator with Period Measurement 320
13.16 Space Vector Generators 321
13.17 VHZ_PROFILE: Volt/Hertz Profile for AC Induction Motors 322
vii
1
SimCoder Overview
1.1 Introduction
SimCoder1 is an add-on option of the PSIM software. It generates C code from PSIM schematics. With specific
hardware target libraries, the C code generated by SimCoder can run directly on target hardware platforms.
This manual describes how to use SimCoder.
One must select and set these parameters properly in order for SimCoder to generate code correctly. The setup
process is explained below.
Hardware Targets:
SimCoder supports the hardware targets of Texas Instruments’ C2000TM real-time control MCUs. The options
of "None" in the pull-down list of Hardware Target is simulation only.
For each F28xxx Target, the supported CPU versions in the product series are listed below. Each CPU version
1. SimCoderTM is a trademark of Altair Engineering Inc., and is copyright by Altair Engineering Inc., 2008-2023
Project Configuration
For F28xxx Targets, the project configuration can be set as RAM Debug, RAM Release, Flash Release, or Flash
RAM Release. For PE-Expert4 Target, the project configuration can be set as PE-ViewX.
Comments
The Comments area at the bottom of the SimCoder tab allows users to add comments to the code generated by
SimCoder. All text in this area will be added as comments to the beginning of the C code.
2.1 Overview
In general, automatic code generation using SimCoder involves the following steps:
- Design and simulate a system in PSIM with the control in continuous domain.
- Convert the control section of the system into discrete domain and simulate the system.
- If there is no hardware target, place the control section in a subcircuit, and generate the code.
- If there is a hardware target, modify the system by including hardware elements, and run the simulation to
validate the results. Then generate the code.
The first two steps, however, are not mandatory. One could, for example, create a schematic in PSIM and
generate the code directly without simulating the system.
Please note that code can only be generated when control is in discrete domain, not in continuous domain.
Therefore, Digital control Module is needed for SimCoder.
Simple examples are used in the sections below to illustrate the code generation process.
Digital PI controller
As compared to the control circuit in continuous domain, there are three changes in this circuit, as highlighted
by the yellow boxes. First, the analog PI controller is replaced by the digital PI controller. The "Algorithm Flag"
of the digital integrator is set to 1 (for Backward Euler method), and the sampling frequency is set to 20 kHz.
The gains k1 and k2 are obtained from the conversion program as described above.
In addition, a zero-order-hold block Z1 is used to simulate the A/D converter in digital hardware
implementation for sampling the feedback current iL. A unit-delay block U1 is used to model the one-cycle
delay inherent in digital control implementation. The delay is due to the fact that, usually quantities are sampled
at the beginning of a cycle, and controller parameters are calculated within the cycle. But since it takes time to
perform the calculation, the newly calculated quantities are normally not used until the beginning of the next
cycle.
Note that the converted digital controller should result in a stable control loop and desired performance. If the
simulation results with the digital control are not stable or not as desired, one needs to go back to the analog
control system, re-design the analog controller, and repeat the process.
With the Backward Euler method, we can also represent the output-input relationship in the time domain as
follows:
y(n) = y(n-1) + Ts * u(n)
where y(n) and u(n) are the output and input at the current time, y(n-1) is the output at the previous sampling
period, and Ts is the sampling period. Using the equation above, we can replace the discrete integrator in the
Note that, due to the factor Ts in the equation, the gain of the proportional block k2 needs to be divided by the
sampling frequency of 20kHz. The advantage of this circuit is that it is easier to start or stop the integration of
the integrator.
With the control circuit in discrete domain, one is now ready to move on to the next step.
PWM Generator
A/D Converter
DefaultTypefGbliref = 0;
DefaultTypefGblU2 = 0;
PS_EnableIntr();
fU2 = fGblU2;
fTI_ADC1 = PS_GetDcAdc(0);
fVDC2 = 2;
void Initialize(void)
{
PS_SysInit(30, 10);
PS_StartStopPwmClock(0);
PS_InitTimer(0, 0xffffffff);
PS_InitPwm(1, 0, 20000*1, (4e-6)*1e6, PWM_POSI_ONLY, 42822);// pwnNo, waveType, frequency, deadtime,
outtype
PS_SetPwmPeakOffset(1, 10, 0, 1.0/10);
PS_SetPwmIntrType(1, ePwmIntrAdc0, 1, 0);
PS_SetPwmVector(1, ePwmIntrAdc0, Task);
PS_SetPwmTzAct(1, eTZHighImpedance);
PS_SetPwm1RateSH(0);
PS_StartPwm(1);
PS_ResetAdcConvSeq();
PS_SetAdcConvSeq(eAdc0Intr, 0, 1.0);
PS_AdcInit(1, !1);
PS_StartStopPwmClock(1);
}
void main()
{
Initialize();
PS_EnableIntr(); // Enable Global interrupt INTM
PS_EnableDbgm();
for (;;) {
}
}
Subcircuit
To create the subcircuit, select the circuit in the dotted box. Right click the mouse to display the pull-down
menu. From the menu, select Create Subcircuit, and define the subcircuit file name.
The subcircuit for code generation excluded the comparator and the carrier wave source. One of the reasons for
this arrangement is, in most of the hardware setup, these two functions are either implemented by external
hardware or embedded in microcontroller’s peripheral interface. The other reason is, for simulation, the carrier
wave and the comparator must be calculated at every time step, but the code is executed at the sampling rate of
20kHz. In SimCoder generated code, the sampling rate of every element must be defined. The comparator has
two inputs: one is from the controller which has 20 kHz sampling rate, and the other is the carrier wave source
which is undefined. In such cases, SimCoder will assume that both inputs of the comparator have the same
sampling rate as the input which is defined.
SimCoder can generate code for a subcircuit either for simulation or for hardware target operation. These two
types of code are not interchangeable. The subcircuit code generated for simulation can not be used in hardware
target, and vice versa. These two situations are explained in the subsections below.
double fCurTime;
double GetCurTime() {return fCurTime;}
void FreeInOutArray()
{ ... ...}
void Task();
void TaskS1(DefaultType fIn0, DefaultType *fOut0);
DefaultType fGblS1_U1 = 0;
DefaultType fGblS1_U2 = 0;
void Task()
{
TaskS1(inAry[0],&outAry[0]);
}
typedef struct {
TimerIntFunc func;
long samprate;
double tmLastIntr;
} TimeChk;
#define NUM_TIMER_INTR 1
TimeChk lGbl_TimeOverChk[NUM_TIMER_INTR] = {
{Task, 20000, 0}};
void InitAllTaskPtr(void)
{
lGbl_TimeOverChk[0].func = Task;
lGbl_TimeOverChk[0].samprate = 20000;
}
void SimulationBegin(
const char *szId, int nInputCount, int nOutputCount,
int nParameterCount, const char ** pszParameters,
int *pnError, char * szErrorMsg,
void ** reserved_UserData, int reserved_ThreadIndex, void * reserved_AppPtr)
{
InitInOutArray();
}
#include <Stdlib.h>
#include <String.h>
#include <math.h>
#include <Psim.h>
/////////////////////////////////////////////////////////////////////
// FUNCTION: SimulationStep
{
// ENTER YOUR CODE HERE...
/////////////////////////////////////////////////////////////////////
// FUNCTION: SimulationBegin
{
// ENTER INITIALIZATION CODE HERE...
/////////////////////////////////////////////////////////////////////
// FUNCTION: SimulationEnd
{
}
To create a C Block in the main circuit, use the pull-down menu Elements >> Other >> Function Blocks >> C
Block. Then, copy the each section of the generated code to each section of the C Block: from the
SimulationStep function to SimulationStep section in the C Block, from the SimulationBegin function to
C Block replaces
the subcircuit
Go to the subcircuit’s attributes dialog. Click on the Generate Code button and select Generate Code for
Hardware Target.
Below is the C code generated by the SimCoder for the subcircuit for F28335 CPU. Unlike the generated code
for the whole system, the code for a subcircuit does not have the main program and the initialization routine. It
can be inserted into one’s own code for F28335 target hardware implementation.
This subcircuit has only one sampling rate. As a result, the generated code has only one function TaskS1. The
variables fIn0 refers to the subcircuit input I_fdbk, and the variable fOut0 corresponds to the subcircuit output
Ctrl.
*fOut0 = fGblS1_U1;
fS1_VDC2 = 2;
fS1_Z1 = fIn0;
fS1_SUM1 = fS1_VDC2 - fS1_Z1;
fS1_k1 = fS1_SUM1 * 0.4;
fS1_k2 = fS1_SUM1 * 1000;
{
static DefaultType out_A = 0;
fS1_B4 = out_A + 1.0/20000 * (fS1_k2);
out_A = fS1_B4;
}
fS1_SUMP1 = fS1_k1 + fS1_B4;
fGblS1_U1 = fS1_SUMP1;
#ifdef_DEBUG
fGblS1_iref = fS1_VDC2;
#endif
}
Subcircuit
Stop Integrator
Default Event
In the diagram, Blocks S1 and S2 are subcircuits, and the contents of the subcircuits are shown below.
S3
EI3
EI1 EO1 EI6
Condition B Condition A
S2 Condition D Condition C
EO2 EI2
In the main circuit, there are two states: S1 and S2, both in the form of subcircuits. The schematic of each state
is included in a subcircuit. State S1 has two input event ports: EI1 and EI3, and one output event port EO1. State
S2 has one input event port EI2 and one output event port EO2. By default, State S1 is the default state at the
beginning. This is defined by the connection of the default event element to the input event port EI3.
The output event port EO1 of S1 is connected to the input event port EI2 of S2, with the transition Condition A.
This means that when Condition A is met, the system will transit from State S1 to S2. Similarly, the output
event port EO2 of S2 is connected to the input event port EI1. When Condition B is met, the system will transit
from State S2 to S1.
When two or more states can not co-exist and only one state can exist at any time, such as S1 and S2 in this
case, we refer to these states as exclusive states.
The system on the right shows the content inside Subcircuit S2. It in turn has two states, S3 and S4. When the
system transits to State S2, it will start with State S3 by default. If Condition C is met, it will transit from State
S3 to S4. If Condition D is met, it will go back to State S3.
There is no limit on the number of states that a system can contain.
The image of an event port is a square, which is different from the image of a signal port which is a circle.
The connection to an input event port can only come from an output event port or a hardware interrupt element,
using the event connection wiring function. Input/output event ports and hardware interrupt elements can not be
connected to other types of nodes.
For each output event port, a condition must be defined. The property window of the output event port EO1 in
Subcircuit S3 above, for example, is shown below:
The condition "RunFlag == 1" is the condition that will trigger the output event to occur. The condition
statement must be a valid C code expression. For example, the condition statement can be:
(RunFlag == 1) && (FlagA >= 250.) || (FlagB < Vconst)
Note that only global variables, numerical values, and parameter constants defined in parameter files or passed
from the main circuit into subcircuits can be used in the condition expression. In the above expression,
RunFlag, FlagA, and FlagB can be global variables, and Vconst can be a constant defined in a parameter file or
passed into the subcircuit from the main circuit.
To create a global variable, connect the global variable element to a node.
The subcircuit S1 is a subcircuit with hardware interrupt. It has two hardware interrupt elements connected to it,
INT1 and INT2. It has one signal input port Si connected to the hardware digital input, and one signal output
port So connected to the hardware digital output.
- If a subcircuit with hardware interrupt contains z-domain blocks with sampling rates, these sampling rates
will be ignored as the subcircuit will be called only when a hardware interrupt occurs. For example, if the
subcircuit contains a discrete integrator, the sampling rate of the discrete integrator will be ignored. In the
calculation for the integrator, the previous time will be the last time that a hardware device triggers an
interrupt.
- If the signal outputs of two subcircuits are connected, they should be connected directly, not through other
elements. To illustrate this, consider the following circuits:
Connection OK Connection (Blocks P2 and P3) not allowed
P1 P2 P1
K K K
EI3 EI3
O2 O2 K
P3
In the circuit on the left, both subcircuits S1 and S2 have one output signal port, O1 and O2. They are connected
externally together to the input of the proportional block P1. The way the circuit works is that the input of the
block P1 will come from either Port O1 or O2, depending on which state is active. This connection is allowed.
However, in the circuit on the right, Port O1 is connected to Block P2, and Port O2 is connected to P3, and the
outputs of P2 and P3 are then connected together. Such a connection is not allowed. In this case, Block P2
should be moved into the subcircuit S1, and Block P2 moved into the subcircuit S2.
4.1 Overview
SimCoder can be used with or without a hardware target. When it is used without a hardware target, it will
convert a control schematic into C code. While the code can be simulated in PSIM, it is not for a specific
hardware. On the other hand, with a hardware target, SimCoder can generate code that is ready to run on the
specific hardware, or can be adopted for a specific hardware.
SimCoder element libraries include two types of elements: these that are not associated with any hardware
targets or are shared by all hardware targets, and these that are specific to a particular hardware.
SimCoder elements that are independent of any hardware include the following:
- Some of the elements of the standard PSIM library.
- All the elements under Elements >> Event Control.
- The Global Variable element under Elements >> SimCoder.
Simcoder elements that are shared by all hardware targets include the following:
- The Interrupt element under Elements >> SimCoder.
- The TI DMC element under Elements >> SimCoder >> TI DMC Library.
SimCoder elements that are hardware-specific include the following:
- F2833x Target: All the elements under Elements >> SimCoder >> F2833x Target.
- F2803x Target: All the elements under Elements >> SimCoder >> F2803x Target.
- F2806x Target: All the elements under Elements >> SimCoder >> F2806x Target.
- F2802x Target: All the elements under Elements >> SimCoder >> F2802x Target.
- PE-Expert4 Target: All the elements under Elements >> SimCoder >> PE-Expert4 Target.
The SimCoder elements that are independent or common to all hardware targets are described in this Chapter.
The elements for each specific hardware target are described in Chapter 6 to 9. Elements in the TI DMC Library
are described in Chapter 13.
The generated code for F28335 is shown below. Note that in the code, the parameter Kp is defined as 0.4 at the
beginning, and the parameter name Kp is used in the calculation.
DefaultTypefGbliref = 0.0;
DefaultTypefGblUDELAY1 = 0;
fTI_ADC1 = PS_GetDcAdc(0);
fVDC2 = 2;
#ifdef_DEBUG
fGbliref = fVDC2;
#endif
fZOH3 = fTI_ADC1;
fSUM1 = fVDC2 - fZOH3;
fP2 = fSUM1 * (1000./20000);
fSUMP3 = fP2 + fUDELAY1;
fGblUDELAY1 = fSUMP3;
fP1 = fSUM1 * Kp; The parameter Kp is used here.
fSUMP1 = fP1 + fSUMP3;
PS_SetPwm1RateSH(fSUMP1);
PS_ExitPwm1General();
}
... ...
Image:
Input Event Output Event
The letter "i" in the image refers to "Input". The letter "o" in the image refers to "Output".
The input event element is a type of subcircuit interface port. It should be used inside a subcircuit only. After
double clicking on the element, one will define the port name and location.
The output event element is also a type of subcircuit interface port. It should be used inside a subcircuit only.
After double clicking on the element, one will define the port name, location, as well as a condition, as shown
below:
In the main circuit that calls the Event subcircuit, if there is an event connection wire connecting to this port,
when the condition of the event connection is met, the system will transit to this Event subcircuit through this
input event port. When the condition defined in the output event port is met, the system will transit out of this E
vent subcircuit.
The condition statement must use format and operators supported by the C language. For example, the
statements below are acceptable condition statements:
A == 1
A >= B
(A > B) && (C > D)
where A, B, C, and D are global variables or numerical constants.
Image:
Default Event
When there are several exclusive states, the default event element is used to define which state is the default
state. It is connected to the input event port of a subcircuit outside the subcircuit.
Image:
Attribute:
Parameters Description
Event Subcircuit Block Name The name of the event subcircuit block that the flag is for.
The flag node is an output node. When the event subcircuit block is entered for the first time, the node value
will be 1. Otherwise, it will be 0. For example, to find out when the event subcircuit block S1 is entered the first
time, set Event Subcircuit Block Name to S1.
Image:
Global Variable
Attributes:
Parameters Description
Name The name of the global variable name
Initial Value The initial value of the global variable
To define a signal as a global variable, connect the global variable element to the particular node. Note that only
a signal in the control circuit for the code generation can be defined as a global variable.
As the name suggests, a global variable can be accessed globally. When the initial value of a global variable is
changed, the initial values of all the global variables in that circuit, including subcircuits, are changed at the
same time.
A global variable can be a signal sink or a signal source. When it is a signal sink, it reads the signal value from
Stop Mode
Run Mode
In this example, a global variable, RunSW, is connected to the output pin D0 of the digital input. This global
variable is then used in the conditional statements between the transition of the two modes of operation.
Another use of the global variable is to use it as a signal source. For example, a global variable can be used as a
signal source and passes the value to another block.
Note that global variable should not be used as a label to pass a value from one node to another, when two nodes
can be physically connected by a wire. The use of the global variables has the following restrictions:
- Global variables of the same name can be used multiple times only if they are in the same signal flow
path.
- If they are in different signal flow paths, global variables of the same name are not allowed, unless they
are in different exclusive states (exclusive states are states that can not occur at the same time).
To illustrate this, the diagram below shows situations where global variables can and cannot be used.
Case 1: V1 V1
(allowed) P1 P2 P3 P4
K K K K
Source Sink
Case 2: V1 V1
(not allowed) P1 P2 P3 P4
K K K K
Case 3:
(allowed) V1
P1 P2 Subcircuit 1
K K
V1
P3 P4 Subcircuit 2
K K
In Case 1, a global variable V1 is first used as a source and it assigns the value to the input of the block P1.
After a series of calculation, the output of the block P4 is assigned back to the same global variable V1. Since
both global variables are in the same signal flow path, it is allowed.
In Case 2, however, the global variable V1 is used as a label to pass values from the output of the block P2 to
4.5 Interrupt
In a hardware target, elements such as digital input, encoder, capture, and PWM generators (for F2833x and
F2803x DSPs) can generate hardware interrupt. The interrupt block allows users to associate the element that
generates the interrupt with the corresponding subcircuit that represents the interrupt service routine.
Please note that the interrupt element cannot be placed inside a subcircuit. It must be in the top-level main
circuit only.
Image:
Interrupt
Attributes:
Parameters Description
Device Name The name of the hardware device that initiates the hardware interrupt
Channel Number The input channel number of the device that initiates the interrupt. For example, if
Channel D0 of a digital input generates the interrupt, the channel number should
be set to 0.
Note that this parameter is used only for:
- Digital input
- Capture (PE-Expert4 Target only)
It does not apply to encoder and PWM generator.
Trigger Type This applies to digital input and capture only. It can be one of the following:
- No edge detection: No interrupt will be generated.
- Rising edge: The rising edge of the input signal will generate interrupt.
- Falling edge: The falling edge of the input signal will generate interrupt.
- Rising/falling edges: Both the rising and falling edges of the input signal will
generate interrupt.
In this circuit, the current I_out is measured and compared with the reference value Limit. If the current I_out
Tab Description
Runtime Code Main code that runs each time
Initialization The code that runs only once at the beginning for initialization
Variable Definition Definition of global variables
Predefined Macro Macros that are defined before external header files or C files to pre-process the
code. For example, the IQ math library uses a macro called "MATH_TYPE" to
determine if the library is floating-point (MATH_TYPE=1) or fixed-point
(MATH_TYPE=0). The macro "#define MATH_TYPE 1" can be defined in this
tab.
Header File External header files .h
External C File External C files that contain code for function implementation
Other functions in the dialog window include the following:
Function Description
Edit Image Edit the image of the C block
Enable Fixed Point When this box is checked, this block becomes a fixed-point block. Otherwise it is a
floating-point block.
Fixed Point Settings Define the data format of the C block inputs and outputs when it is a fixed-point
block.
Variables Macro Define variables that can be passed from the main circuit into the C code. Variable
values could be numbers or formulas. These formulas could contain variables that
were defined in parameter files or passed to the schematic from command-line.
Formulas are evaluated before simulation starts and they can not contain 't' (time)
or input/output values.
Example:
a = 15.2
b = Freq / sqrt(2)
where 'Freq' is defined in a parameter file.
These variables are compatible with SimCoder. Please note that SimCoder
generated code will show the evaluated value, not the formula.
Check Code Check the syntax of the code
SimCoder pre-processors can be used in the SimCoder C block to generate simplified code. In order to
differentiate SimCoder pre-processors from the processors in the C language, a double ## sign is used. The
following pre-processors are supported:
##if condition
...
##elif condition
...
##else
...
##endif
Examples of how the SimCoder C block is used can be found in each Target folder under the "examples/
SimCoder" folder.
5.1 Overview
TI’s IQmath library provides a list of functions that can port floating-point code to fixed-point code. These
functions provide high execution speed and high accuracy.
For more information on the IQmath library, please refer to relevant TI documents.
6.1 Overview
With the F2833x Hardware Target, SimCoder can generate code that is ready to run on any hardware boards
based on Texas Instruments’ F2833x floating-point DSP.
The F2833x Hardware Target will work with all F2833x packages. The figures in the next two pages show the
pin assignments of the F2833x DSP in the low-profile flat-pack (LQFP) package. The main functions
implemented in the F2833x Hardware Target are marked in color in the figures.
The F2833x Hardware Target library includes the following function blocks:
- PWM generators: 3-phase, 2-phase, 1-phase, and APWM
- Variable frequency PWM
- Start/Stop functions for PWM generators
- Trip-zone and trip-zone state
- A/D converter
- Digital input and output
- SCI configuration, input, and output
- SPI configuration, device, input, and output
- CAN configuration, input, and output
- Capture and capture state
- Encoder and encoder state
- Up/Down counter
- Interrupt time
- DSP clock
- Hardware configuration
When generating the code for a system that has multiple sampling rates, SimCoder will use the interrupts of the
PWM generators for the PWM sampling rates. For other sampling rates in the control system, it will use the
Timer 1 interrupt first, and then Timer 2 interrupt if needed, If there are more than three sampling rates in the
control system, the corresponding interrupt routines will be handled in the main program by software.
PWM generators can generate hardware interrupt. SimCoder will search and group all the elements that are
connected to the PWM generator and have the same sampling rate as the PWM generator. These elements will
be automatically placed and implemented in an interrupt service routine in the generated code.
In addition, digital input, encoder, capture, and trip-zone can also generate hardware interrupt. Each hardware
interrupt must be associated with an interrupt block (described in Section 5.4 of this Manual), and each interrupt
block must be associated with an interrupt service routine (a subcircuit that represents the interrupt service
routine). For example, if a PWM generator and a digital input both generate interrupt, there should be one
interrupt block and one interrupt service routine for each of them.
The definitions of the elements in the F2833x Hardware Target library are described in this Chapter.
Capture/APWM
SCI & SPI
(in yellow)
PWM 1-6
Counter /
Encoder
Trip-Zone 1-6
ADC Group A
ADC Group B
Capture/APWM
Counter/Encoder
Capture/APWM
Image:
For each GPIO port, a check box is provided for each of its available function. If this box is checked, only this
function is used, and all other functions are not allowed in SimCoder. For example, Port GPIO1 can be used for
"Digital Input", "Digital Output", "PWM" and "Capture". If a particular board uses Port GPIO1 as the "PWM"
output, only the checkbox for "PWM" should be checked and all other check boxes should be left unchecked. If
in the circuit Port GPIO1 is used as "Digital Input", SimCoder will report an error.
Image:
Attributes:
Parameters Description
External Clock (MHz) Frequency of the external clock on the DSP board, in MHz. The frequency must be
an integer, and the maximum frequency allowed is 30 MHz.
DSP Speed (MHz) DSP Speed, in MHz. The speed must be an integer, and must be an integer
multiple of the external clock frequency, from 1 to 12 times. The maximum DSP
speed allowed is 150 MHz.
If the DSP Clock block is not used in a circuit, the default values of the DSP block are used.
Image:
3-ph PWM
u up
un
v vp
vn
w wp
wn
F28335
Parameters Description
PWM Source Source of the PWM generator. It can be either "3-phase PWM 123" that uses
PWM 1 to 3, or "3-phase PWM 456" that uses PWM 4 to 6.
Dead Time Dead time Td for the PWM generator, in sec.
Sampling Frequency Sampling frequency of the PWM generator, in Hz. The calculation is done and
the PWM signal duty cycle is updated based on this frequency.
PWM Freq. Scaling The ratio between the PWM switching frequency and the sampling frequency. It
Factor can be from 1 to 100. For example, if the sampling frequency is 50 kHz and the
scaling factor is 3, the PWM switching frequency will be 150 kHz. That is
switches will operate at 150 kHz. But gating signals will be updated at 50 kHz, or
once per 3 switching cycles.
Carrier Wave Type Carrier wave type and the initial PWM output state. It can be one of the
following:
- Triangular (start low): Triangular wave, and the initial PWM output state is
low.
- Triangular (start high): Triangular wave, and the initial output state is high.
- Sawtooth (start low): Sawtooth wave, and the initial output state is low.
- Sawtooth (start high): Sawtooth wave, with the initial output state is high.
Trigger ADC Setting whether for the PWM generator to trigger the A/D converter. It can be
one of the following:
- Do not trigger ADC: PWM does not trigger the A/D converter.
- Trigger ADC Group A: PWM will trigger Group A of the A/D converter.
- Trigger ADC Group B: PWM will trigger Group B of the A/D converter.
- Trigger ADC Group A&B: PWM will trigger both Group A and B of the A/D
converter.
ADC Trigger Position A/D trigger position ranges from 0 to a value less than 1. When it is 0, the A/D
converter is triggered at the beginning of the PWM cycle, and when it is 0.5, the
A/D converter is triggered at the 180o position of the PWM cycle.
Use Trip-Zone i Define whether the PWM generator uses the ith trip-zone signal or not, where i
ranges from 1 to 6. It can be one of the following:
- Disable Trip-Zone i: Disable the ith trip-zone signal.
- One shot: The PWM generator uses the trip-zone signal in the one-shot mode.
Once triggered, the PWM must be started manually.
- Cycle by cycle: The PWM generator uses the trip-zone signal in the cycle-by-
cycle basis. The trip-zone signal is effective within the current cycle, and
PWM will automatically re-start in the next cycle.
Trip Action Define how the PWM generator responds to the trip action. It can be one of the
following:
- High impedance: The PWM outputs are in high impedance.
- PWM A high & B low: The PWM positive output is high, and the negative
output is low.
- PWM A low & B high: The PWM positive output is low, and the negative
output is high.
- No action: No action is taken.
Peak-to-Peak Value Peak-to-peak value Vpp of the carrier wave
Offset Value DC offset value Voffset of the carrier wave
Images:
Parameters Description
PWM Source Source of the PWM generator. Without phase shift, it can be PWM 1 to PWM 6.
With phase shift, it can be PWM 2 to PWM 6.
Output Mode Output mode of the PWM generator. It can be one of the following:
- Use PWM A&B: Both PWM outputs A and B are used, and they are
complementary.
- Use PWM A: Only PWM output A is used.
- Use PWM B: Only PWM output B is used.
Dead Time Dead time Td for the PWM generator, in sec.
Sampling Frequency Sampling frequency of the PWM generator, in Hz. The calculation is done and the
PWM signal duty cycle is updated based on this frequency.
PWM Freq. Scaling The ratio between the PWM switching frequency and the sampling frequency. It
Factor can be from 1 to 100. For example, if the sampling frequency is 50 kHz and the
scaling factor is 3, the PWM switching frequency will be 150 kHz. That is
switches will operate at 150 kHz. But gating signals will be updated at 50 kHz, or
once per 3 switching cycles.
Carrier Wave Type Carrier wave type and the initial PWM output state. It can be one of the following:
- Triangular (start low): Triangular wave, and the initial PWM output state is
low.
- Triangular (start high): Triangular wave, and the initial output state is high.
- Sawtooth (start low): Sawtooth wave, and the initial output state is low.
- Sawtooth (start high): Sawtooth wave, and the initial output state is high.
Trigger ADC Setting whether for the PWM generator to trigger the A/D converter. It can be one
of the following:
- Do not trigger ADC: PWM does not trigger the A/D converter.
- Trigger ADC Group A: PWM will trigger Group A of the A/D converter.
- Trigger ADC Group B: PWM will trigger Group B of the A/D converter.
- Trigger ADC Group A&B: PWM will trigger both Group A and B of the A/D
converter.
ADC Trigger Position A/D trigger position ranges from 0 to a value less than 1. When it is 0, the A/D
converter is triggered at the beginning of the PWM cycle, and when it is 0.5, the A/
D converter is triggered at the 180o position of the PWM cycle.
Use Trip-Zone i Define whether the PWM generator uses the ith trip-zone signal or not, where i
ranges from 1 to 6. It can be one of the following:
- Disable Trip-Zone i: Disable the ith trip-zone signal.
- One shot: The PWM generator uses the trip-zone signal in the one-shot mode.
Once triggered, the PWM must be started manually.
- Cycle by cycle: The PWM generator uses the trip-zone signal in the cycle-by-
cycle basis. The trip-zone signal is effective within the current cycle, and PWM
will automatically re-start in the next cycle.
Trip Action Define how the PWM generator responds to the trip action. It can be one of the
following:
- High impedance: The PWM outputs are in high impedance.
- PWM A high & B low: The PWM positive output is high, and the negative
output is low.
- PWM A low & B high: The PWM positive output is low, and the negative
output is high.
- No action: No action is taken.
Phase Shift
A 1-phase PWM block can generate PWM signal that is phase shifted with respect to another PWM signal. The
way how PWM blocks are defined for phase shift is explained in Section 6.4.5.
The phase shift value is in degree. When the value is -30o, the output will be shifted to the right (lagging) by 30o
of the switching cycle with respect to the reference PWM generator output. This is equivalent to shifting the
PWM carrier wave to the right by 30o. When the phase value is 30o, the output will be shifted to the left
(leading) by 30o.
Carrier Wave
There are two types of carrier waveforms: triangular wave (with equal rising and falling slope intervals) and
VL VL
Voffset Voffset t
Td PWMxA PWMxA
x = 1, 2, ..., 6
Td PWMxB PWMxB
The input and output waveforms of a PWM generator with the sawtooth carrier wave are shown below:
Td
PWMxA PWMxA
x = 1, 2, ..., 6
PWMxB PWMxB
Td
Start of the PWM cycle
A/D Trigger Start of the PWM cycle
Position Start of the A/D conversion
The figures above show how the dead time is defined, and the time sequence when the PWM generator triggers
the A/D converter. If triggering the A/D converter is selected, from the start of the PWM cycle, after a certain
delay defined by the A/D trigger position, the A/D conversion will start. After the A/D conversion is completed,
the PWM interrupt service routine will start.
If the PWM generator does not trigger the A/D converter, the PWM interrupt service routine will start at the
beginning of the PWM cycle.
The figures above also show how the start-high and start-low modes work. Assume that the PWM input is vm,
and the lowest value of the carrier wave is VL and the highest value is VH. In the start-high mode, the PWM
positive output PWMA is high at the beginning of the switching cycle, and it remains high as long as the input
vm is greater than the carrier wave. For example, for a carrier wave from 0 to 1, VL=0, and VH=1. If vm=0.2, the
PWM output PWMA will remain high as long as the carrier is less than 0.2.
On the other hand, in the start-low mode, the PWM positive output PWMA is low at the beginning of the
switching cycle, and it is high when the carrier wave is greater than the value VH-(vm-VL). For example, for a
Conditioning circuit
Note: In the start-low mode, the PWM input vm is converted to VH-(vm-VL) internally before it is compared with
the carrier wave to generate the PWM signal. With the conversion, both the start-low and start-high modes will
have the same duty cycle expression. For example, for a sawtooth wave with VL=0 and VH=1, or for a triangular
wave with VL= -VH, the duty cycle D of the PWMA output in both the start-low and start-high modes is:
D = vm/VH.
Image:
2-ph PWM
A A
B B
F28335
Attributes:
Parameters Description
PWM Source Source of the PWM generator. It can be PWM 1 to PWM 6.
Mode Type Operation mode of the PWM generation. It can be one of the 6 modes. The
waveforms of the 6 operation modes are described below.
Sampling Frequency Sampling frequency of the PWM generator, in Hz. The calculation is done and the
PWM signal duty cycle is updated based on this frequency.
PWM Freq. Scaling The ratio between the PWM switching frequency and the sampling frequency. It
Factor can be from 1 to 100. For example, if the sampling frequency is 50 kHz and the
scaling factor is 3, the PWM switching frequency will be 150 kHz. That is
switches will operate at 150 kHz. But gating signals will be updated at 50 kHz, or
once per 3 switching cycles.
Operation Mode 1:
The figure below on the left shows the waveforms of Mode 1. In the figure, "CA" and "CB" refer to two inputs
A and B of the 2-phase PWM generator. Each input controls the turn-off time of each output.
Operation Mode 2:
The figure below on the right shows the waveforms of Mode 2. Unlike in Mode 1, each input controls the turn-
on time of each output.
0 t t
CB CA CB CA CB CA CB CA
PWMxA PWMxA
PWMxB PWMxB
Operation Mode 3:
The figure below on the left shows the waveforms of Mode 3. Input A controls the turn-on and Input B controls
the turn-off of the PWM output A. The PWM output B is on for one complete PWM cycle, and is off for the
next cycle.
Operation Mode 4:
The figure below on the right shows the waveforms of Mode 4. The carrier wave is triangular. Each input
controls both the turn-on and turn-off of its output.
Mode 3: Mode 4:
t CA CA CA CA t
CA CB CA CB CB CB CB CB
PWMxA PWMxA
PWMxB PWMxB
Operation Mode 5:
The figure below on the left shows the waveforms of Mode 5. The carrier wave is triangular. Similar to Mode 4,
each input controls both the turn-on and turn-off of its output. Note that PWM output B is inverted in this case.
Operation Mode 6:
The figure below on the right shows the waveforms of Mode 6. Input A controls the turn-on and Input B
controls the turn-off of PWM output A. The PWM output B is on for the first half PWM cycle, and is off for the
second half cycle.
Mode 5: Mode 6:
CA CA CA CA CA CB CA CB t
CB CB CB CB
PWMxA PWMxA
PWMxB PWMxB
Image:
APWM
F28335
Attributes:
Parameters Description
PWM Source The PWM source can be one of the six APWM’s in 14 designated GPIO ports, as
listed below:
- APWM 1 (GPIO5, 24, 34)
- APWM 2 (GPIO7, 25, 37)
- APWM 3 (GPIO9, 26)
- APWM 4 (GPIO11, 27)
- APWM 5 (GPIO3, 48)
- APWM 6 (GPIO1, 49)
PWM Frequency Frequency of the PWM generator, in Hz
Carrier Wave Type Carrier wave type and the initial PWM output state. It can be one of the following:
- Sawtooth (start low): sawtooth wave, with the PWM output low initially.
- Sawtooth (start high): Sawtooth wave, with the PWM output high initially.
Stop Action Output status when the PWM generator is stopped. It can be one of the following:
- Output low: The PWM output will be set to low.
- Output high: The PWM output will be set to high.
Peak-to-Peak Value Peak-to-peak value of the carrier wave
Offset Value DC offset value of the carrier wave
Phase Shift Phase shift of the output with respect to the reference PWM generator, in deg.
Initial Input Value Initial value of the input
Start PWM at When it is set to Start, PWM will start right from the beginning. If it is set to Do
Beginning not start, one needs to start PWM using the Start PWM block.
Similar to 1-phase PWM generators, an APWM generator can generate a PWM signal that has a phase shift
with respect to another PWM generator. The way how PWM blocks are defined for phase shift is explained in
Section 6.4.5.
The phase shift value is in degree. When the value is -30o, the output will be shifted to the right (lagging) by 30o
of the switching cycle with respect to the reference PWM generator output. This is equivalent to shifting the
PWM carrier wave to the right by 30o. When the phase value is 30o, the output will be shifted to the left
(leading) by 30o.
As noted before, the APWM generators has reduced number of functions than 1-phase PWM generators. It can
not trigger the A/D converter and can not use the trip-zone signal.
Image:
Variable
Freq
F2833x
Attributes:
Parameters Description
PWM Source Source of the PWM generator. It can be one of the following:
PWM 1, PWM 2, PWM 3, PWM 4, PWM 5, PWM 6, 3-phase PWM 123, and 3-
phase PWM 456.
Adjust Interrupt Pos. Specify if the interrupt position is adjusted with the frequency. It can be one of the
following:
- Do not adjust: The interrupt position will remain unchanged as calculated with
the base frequency.
- Adjust: The interrupt position will be recalculated at the beginning of
each cycle based on the new frequency.
Image:
Attributes:
Parameters Description
PWM Source Source of the PWM generator. It can be: PWM 1-6, 3-phase PWM 123 and PWM
456, and Capture 1-6.
Image:
Parameters Description
Port GPIO12 as Trip-Zone 1 Define if Port GPIO12 is used as trip-zone 1.
Port GPIO13 as Trip-Zone 2 Define if Port GPIO13 is used as trip-zone 2.
Port GPIO14 as Trip-Zone 3 Define if Port GPIO14 is used as trip-zone 3.
Port GPIO15 as Trip-Zone 4 Define if Port GPIO15 is used as trip-zone 4.
Parameters Description
PWM Source Source of the PWM generator. It can be: PWM 1-6, and 3-phase PWM 123
and PWM 456.
The trip-zone interrupt can be generated in either one-shot mode of cycle-by-cycle mode, as defined in the
PWM generator parameter input. In the cycle-by-cycle mode, the interrupt only affects the PWM output within
the current PWM cycle. On the other hand, in the one-shot mode, interrupt triggers a trip action when the input
signal is low (0). will set the PWM output permanently, and the PWM generator must be restarted to resume the
operation.
The Trip-Zone State element indicates whether the trip-zone signal is in one-shot mode or cycle-by-cycle mode
when it triggers a PWM generator to generate an interrupt. When the output is 1, it means that the trip-zone
signal is in one-shot mode. When the output is 0, the trip-zone signal is in cycle-by-cycle mode.
Note that when defining the interrupt block associate with trip-zone, the "Device Name" parameter of the
interrupt block should be the name of the PWM generator, not the trip-zone block name. For example, if a
PWM generator called "PWM_G1" uses trip-zone 1 in the trip-zone block "TZ1". The "Device Name" of the
corresponding interrupt block should be "PWM_G1", not "TZ1". The "Channel Number" parameter in the
interrupt block is not used in this case.
As shown above, the A/D converter element in SimCoder is not exactly the same as the physical A/D converter
on the DSP. Rather, it combines the functions of an offset circuit, the DSP A/D converter, and a scaling block.
This is designed for the convenience of AC system applications.
The image and the parameters of the A/D converter in the SimCoder library are described below. In the
following description, "A/D converter" refers to the A/D converter in the SimCoder library, not the DSP A/D
converter, unless otherwise stated.
A/D Converter
Attributes:
Parameters Description
ADC Mode Mode of operation of the A/D converter. It can be one of the following:
- Continuous: The A/D converter performs the conversion continuously. When
the converter value is read, the result of the last conversion is read.
- Start/stop (8-channel): The A/D converter only performs the conversion upon
request, on only one of the 8-channel groups.
- Start/stop (16-channel): The A/D converter only performs the conversion upon
request, on all 16 channels.
Ch Ai or Bi Mode Input mode of the A/D converter channel Ai or Bi, where i is from 0 to 7. The input
mode can be one of the following:
- AC: This option is for simulation only, not for code generation. The input
range is considered from -1.5V to +1.5V. This option includes the offset circuit
into the A/D converter. It provides the convenience in cases where an external
level shifter is needed to shift the AC signal to the 0 to +3V range.
- DC: The input is a dc value, and the range is from 0 to +3V.
Ch Ai or Bi Gain Gain k of the A/D converter channel Ai (or Bi), where i is from 0 to 7.
Conversion Order Order of the A/D conversion. If the field is left blank (undefined), the conversion
will be done based on the sequential numbers of the A/D channel. For example, if
A0, A2, A4, B1, and B3 are used, the conversion will be done in this order.
To rearrange the sequence, write the order here. For example, if the conversion
order is defined as:
A4,A0,A2,B3,B2
The conversion order will be A4 before A0, and A0 before A2, and so on.
Any channels can be specified multiple times, as long as the total conversion
number does not exceed 16. For example, if the order is
A4,A4,A4,A0,A2,B3,B2
Channel A4 will be converted 3 times, then A0, A2, etc.
If there is a '-' prefix before any channel name, this channel will be converted but
the data will be discarded. For example, if the order is
-A4,A4,A4,A0,A2,B3,B2
Channel A4 will be converted 3 times, but its first conversion data will be
discarded.
If any channel is converted multiple times, the channel's final data will be the
average value in this conversion sequence (the discarded conversion data is not
included).
DC Signal Input
0 V -> +3 V
Please note that, in this example, if the gain of the proportional block is changed from 2 to 1, and the A/D gain
is changed from 50 to 100, the simulation results will be the same. But the generated hardware code will not be
correct. This is because the hardware code assumes that the maximum input value is scaled to +3V, but in this
case it is only +1.5V. Therefore, one must set up the circuit such that, in the dc mode, the maximum input value
is scaled to be +3V.
Notice that in this circuit, the ac signal is sent to the A/D converter directly. This is because that, when the A/D
input mode is set to ac, the input range is from -1.5V and +1.5V, and the function of the conditioning circuit that
performs the dc offset is already included in the A/D converter block. In the actual hardware circuit, the ac
signal will need to be scaled and offset so that the range is within 0V to +3V required by the DSP A/D
converter.
Also, to ensure the correctness of the generated code for the hardware, the maximum peak value of the input
must be scaled to 1.5V at the input port of the A/D converter.
Image:
Parameters Description
Port Position for Input i Port position of the Input i, where i is from 0 to 7. It can be one of the 88 GPIO
ports, from GPIO0 to GPIO87.
Use as External Indicate if this port is used as an external interrupt input.
Interrupt
Parameters Description
Port Position for Port position of the Output i, where i is from 0 to 7. It can be one of the 88 GPIO
Output i ports, from GPIO0 to GPIO87.
Note that if a GPIO port is used as an input port, this same port cannot be used as another peripheral port. For
example, if Port GPIO1 is assigned as digital input and it is also used as PWM1 output, an error will be
reported.
In the F2833x DSP, up to 7 external interrupt sources can be defined from ports GPIO0 to GPIO63 (specifically,
up to 2 interrupt sources from Port GPIO0 to GPIO31, and up to 5 interrupt sources from Port GPIO32 to
GPIO63). The priority of external interrupts in Port GPIO0 to GPIO31 is higher than the priority of the interrupt
in Port GPIO32 to GPIO63.
Image:
Attributes:
Parameters Description
Counter Source Source of the counter. It can be one of the following:
- Counter 1 (GPIO20, 21): Counter 1 at Port GPIO20 and 21 is used.
- Counter 1 (GPIO50, 51): Counter 1 at Port GPIO50 and 51 is used.
- Counter 2 (GPIO24, 25): Counter 2 at Port GPIO24 and 25 is used.
In the image, "Clk" refers to the input clock signal, and "Dir" refers to the signal that defines the counting
direction. When the "Dir" input is 1, the counter counts forward, and when the input is 0, the counter counts
backward.
Note that the "Clk" input corresponds to the first port of the counter, and the "Dir" input corresponds to the
second port. For example, for Counter 1 at Port GPIO20 and 21, GPIO20 is the "Clk" input and GPIO21 is the
"Dir" input.
The output of the up/down counter gives the counter value.
Note that the up/down counter uses the same resource as the encoder, and the same GPIO ports cannot be used
in a counter and encoder at the same time. For example, using both Encoder 1 and Up/Down Counter 1 will
cause conflict and is not allowed.
Image:
Encoder
A Index Pos
Encoder
B Cnt Cnt
Z State
Strobe F2833x
F28335
F28335
Parameters Description
Encoder Source Source of the encoder. It can be one of the followings:
- Encoder 1 (GPIO20, 21): Encoder 1 at Port GPIO20 and 21 is used, with
GPIO22 as Strobe and GPIO23 as Index (Z).
- Encoder 1 (GPIO50, 51): Encoder 1 at Port GPIO50 and 51 is used, with
GPIO52 as Strobe and GPIO53 as Index (Z).
- Encoder 2 (GPIO24, 25): Encoder 2 at Port GPIO24 and 25 is used, with
GPIO27 as Strobe and GPIO26 as Index (Z).
Use Z Signal Define if the encoder uses the Z (or index) signal. It can be:
- No: Not used.
- Yes (rising edge): The signal rising edge is used.
- Yes (falling edge): The signal falling edge is used.
Use Strobe Signal Define if the encoder uses the strobe signal.
- No: Not used.
- Yes (rising edge): The signal rising edge is used.
- Yes (rising/falling edge): Both the signal rising and falling edges are used.
Counting Direction The counting direction can be either Forward or Reverse. When it is set to
Forward, the encoder counts up. Otherwise, the encoder counts down.
Z Signal Polarity Trigger polarity of Z signal. It can be:
- Active High
- Active Low
Strobe Signal Polarity Trigger polarity of strobe signal. It can be:
- Active High
- Active Low
Encoder Resolution Resolution of the external encoder hardware. If it is 0, the encoder counter will
keep on counting and will not reset. If for example, the resolution is set to 4096,
the counter will be reset to 0 after it reaches 4095.
Parameters Description
Encoder Source Define which encoder generates the interrupt. It can be one of the followings, must
be the same Encoder used in the same schematic:
- Encoder 1 (GPIO20, 21): Encoder 1 at Port GPIO20 and 21 is used.
- Encoder 1 (GPIO50, 51): Encoder 1 at Port GPIO50 and 51 is used.
- Encoder 2 (GPIO24, 25): Encoder 2 at Port GPIO24 and 25 is used.
Parameters Description
Encoder Source Source of the encoder. There are three sources, as listed below:
- Encoder 1 (GPIO20, 21): Encoder 1 at Port GPIO20 and 21 is used.
- Encoder 1 (GPIO50, 51): Encoder 1 at Port GPIO50 and 51 is used.
- Encoder 2 (GPIO24, 25): Encoder 2 at Port GPIO24 and 25 is used.
Note that Encoder 1 (GPIO20, 21) and Encoder 1 (GPIO50, 51) use the same
internal function blocks, and they cannot be used at the same time.
Latch Position Latch counter type. It can be one of the following:
- IndexPos: Z/index signal is used.
- StrobePos: Strobe signal is used.
Position Type Latch position. It can be one of the following:
- The first latched position
- The current latched position
Image:
Parameters Description
Capture Source Source of the capture. There are in total 6 captures that use 14 designated GPIO
ports, as listed below:
- Capture 1 (GPIO5, 24, 34)
- Capture 2 (GPIO7, 25, 37)
- Capture 3 (GPIO9, 26)
- Capture 4 (GPIO11, 27)
- Capture 5 (GPIO3, 48)
- Capture 6 (GPIO1, 49)
Event Filter Prescale Event filter prescale. The input signal is divided by the selected prescale.
Timer Mode Capture counter timer mode. It can be either Absolute time or Time difference.
Parameters Description
Capture Source Source of the capture. It can be one of the 6 captures: Capture 1, Capture 2, ...,
Capture 6.
The Capture State block output is either 1 or 0, where 1 means the rising edge and 0 means the falling edge.
Image:
Attributes:
Parameters Description
SCI Port Define the SCI port. Different sets of GPIO ports that can be used for SCI, as listed
below:
- SCIA: GPIO28 and 35 in combination with GPIO29 and 36
- SCIB: GPIO9, 14, 18, and 22 in combination with GPIO11, 15, 19, and 23
- SCIC: GPIO62 and 63
Speed (bps) SCI communication speed, in bps (bits per second). A list of preset speeds is
provided at 200000, 115200, 57600, 38400, 19200, or 9600 bps. Or one can
specify any other speed manually.
Parity Check The parity check setting for error check in communication. It can be either None,
Odd, or Even.
Output Buffer Size Size of the data buffer allocated in DSP for SCI. The buffer is located in the RAM
area, and each buffer cell stores one data point which consists of three 16-bit words
(that is, 6 bytes, or 48 bits, per data point).
Note that the buffer size should be properly selected. On one hand, a large buffer is preferred in order to collect
more data points so that more variables can be monitored over a longer period of time. On the other hand, the
internal DSP memory is limited, and the buffer should not be too large to interfere with the normal DSP
operation.
For more information on how to select the buffer size, please refer to the document "Tutorial - Using SCI for
Waveform Monitoring.pdf".
Image:
Attributes:
Parameters Description
Initial Value The initial value of the SCI input variable.
In a schematic, the SCI input behaviors as a constant. While its value can be changed at runtime when the code
is running on the DSP, the value will be fixed at the initial value in the simulation.
Image:
Attributes:
Parameters Description
Data Point Step It defines how frequent data is collected. If the Data Point Step is 1, every data
point is collected and transmitted. If the Data Point Step is 10, for example, only
one point of out every 10 points is collected and transmitted.
Note that if the Data Point Step is too small, there may be too many data points and it may not be possible to
transmit them all. In this case, some data points will be discarded during the data transmission.
Also, the Data Point Step parameter is used only when then DSP Oscilloscope is in the continuous mode. When
it is in the snap-shot node, this parameter is ignored and every point is collected and transmitted.
In simulation, the SCI output behaviors as a voltage probe.
Image:
Attributes:
Parameters Description
SPI Port Define the SPI port. The SPI port can be either GPIO16-19 or GPIO54-57.
Chip Select Pin0, 1, 2, The GPIO port of the chip select pin. PSIM supports up to 16 SPI devices, which
and 3 requires four GPIO pins for chip select, as defined by Chip Select Pin0 to Pin3.
These GPIO ports and the SPI slave transmit-enable pin SPISTE are used to
generate the chip select signal.
SPI Buffer Size The buffer size of the SPI commands. Each memory cell of the buffer saves the
index of a SPI command. Normally, one can specify the buffer size as 1 plus the
number of SPI commands (i.e. Start Conversion Command, Receiving Data
Command, Sending Data Command, and Sync. Command) in all SPI Input/Output
elements.
Image:
Attributes:
Parameters Description
Chip Select Pins The state of the chip select pins corresponding to the SPI device. When the chip
select pins are at this state, this SPI device is selected.
Communication Speed SPI communication speed, in MHz.
(MHz)
Sync. Active Mode The triggering mode of the synchronization signal of the SPI device. It can be
either Rising edge or Falling edge.
SPI Initial Command The SPI command that initializes the SPI device.
Hardware Interrupt Specify the type of the interrupt signal that the SPI device generates. This is valid
Mode only when the SPI device’s interrupt output node is connected to the input of a
digital output element. It can be one of the following:
- No hardware interrupt
- Rising edge
- Falling edge
Interrupt Timing Specify how a SPI device generates interrupt when it completes conversion. It can
be one of the following:
- No interrupt: No interrupt is generated. In this case, DSP sends the command to
a SPI input device. This device starts the conversion and returns the result in
the same command
- Multiple interrupt in series: Multiple interrupts are generated in series after
each conversion. This is for a SPI device that has one A/D conversion unit and
multiple input channels. In this case, DSP send the first conversion command,
and the SPI device starts the conversion. When the conversion is complete, the
SPI device will generate an interrupt. In the interrupt service routine, DSP will
send a command to fetch the conversion result, and start a new conversion of
another channel of the same SPI input device.
- One-time interrupt: Only one interrupt is generated at the end of the
conversion. This is for a SPI device that can perform multiple channel
conversions in one request. In this case, DSP sends the command to the SPI
input device, and the SPI device completes the conversion of multiple input
channels. When all the conversions are complete, the SPI device will generate
an interrupt.
Command Gaps (ns) The gap between two SPI commands, in nsec.
Conversion Sequence Define the names of the SPI input elements, separated by comma, that determine
the conversion sequence. Note that this parameter is valid only when the SPI
device generates multiple interrupts in series.
In a schematic, the chip select pins of all the SPI devices are connected to the chip select pins of the SPI
Configuration block, without defining how the chip select logic is implemented. In the actual hardware,
however, one would need to implement the corresponding chip select logic accordingly.
A SPI command consists of a series of 16-bit numbers separated by comma. In the 16-bit number, only the
lower bits are the significant bits used by the command. For example, if the Command Word Length is 8, Bits 0
to 7 are the command, and Bits 8 to 15 are not used.
A SPI device can be either an input device or an output device. For example, an external A/D converter is an
input device. Usually DSP will send one or multiple A/D conversion commands to the device, and then set the
synchronization signal to start the conversion. The synchronization signal is reset at the next command of the
Chapter 6: F2833x Hardware Target 58
same device.
A SPI input device using the synchronization signal usually needs an interrupt pin to trigger DSP to enter the
interrupt service routine.
On the other hand, an external D/A converter is an output device. Usually DSP sends one or multiple D/A
conversion commands to the device, and then sets the synchronization signal to start the conversion. The
synchronization signal is reset at the next command of the same device.
Image:
Attributes:
Parameters Description
Device Name Name of the SPI input device.
Start Conversion Command to start conversion, in hex numbers, separated by comma (for example,
Command 0x23,0x43,0x00).
Receiving Data Command to receive data, in hex numbers, separated by comma (for example,
Command 0x23,0x43,0x00).
Data Bit Position Define where the data bits are in the receiving data string. The format is:
ElementName = {Xn[MSB..LSB]}
where
- ElementName is the name of the SPI input device. If it is the current SPI input
device, use y instead.
- {} means that the item in the bracket repeats multiple times.
- Xn is the nth word received from the SPI input device, and n start from 0.
- MSB..LSB defines the position of the significant bits in the word.
Input Range Specify the parameter Vmax that defines the input range. This parameter is valid
only when the SPI device is an A/D converter. If the device conversion mode is
DC, the input ranges from 0 to Vmax. If the device conversion mode is AC, the
input ranges from -Vmax/2 to Vmax/2.
Scale Factor Output scale factor Kscale. If the scale factor is 0, the SPI device is not an A/D
converter, and the result will be exactly the same as what DSP receives from SPI
communication. Otherwise, the SPI device is an A/D converter, and the result is
scaled based on this factor and the A/D conversion mode.
ADC Mode The A/D conversion mode of the device. It can be either DC or AC. Note that this
parameter is valid only when the device is an A/D converter.
Initial Value The initial value of the input.
The formula for the Data Bit Position defines the data length of a SPI input device. For example,
y=x1[3..0]x2[7..0], means that the data length is 12, and the result is the lower 4 bits of the 2nd word and the
lower 8 bits of the 3rd word. If the received data string is 0x12,0x78,0xAF, then the result is 0x8AF.
If the scale factor is not 0, the output will be scaled based on the following:
In the DC conversion mode:
Data_Length
2
- In the AC conversion mode:
) Vmax Ks cale
- In hardware: Output = (Result – 2Data_Length-1 ------- ---------
-----------------------
The parameter Data_Length is calculated from the Data Bit Position formula.
Image:
Attributes:
Parameters Description
DAC Mode The D/A conversion mode of the device. It can be either DC or AC. Note that this
parameter is valid only when the device is a D/A converter.
Sending Data Command to send the output data, in hex numbers, separated by comma (for
Command example, 0x23,0x43,0x00).
Data Bit Position Define where the data bits are in the sending data string. The format is:
ElementName = {Xn[MSB..LSB]}
where
- ElementName is the name of the SPI output device. If it is the current SPI
output device, use y instead.
- {} means that the item in the bracket repeats multiple times.
- Xn is the nth word sent to the SPI output device, and n start from 0.
- MSB..LSB defines the position of the significant bits in the word.
Sync. Command The command to synchronize output channels of the SPI output device, in hex
numbers, separated by comma (for example, 0x23,0x43,0x00). This command is
used when the SPI output device does not have the synchronization signal
The formula for the Data Bit Position defines the data length of a SPI output device. For example,
V max
In the AC conversion mode:
--------------------------- -----------
V max
The parameter Data_Length is calculated from the Data Bit Position formula.
Image:
CAN
Config
F28335
Attributes:
Parameters Description
Image:
CAN
In
Attributes:
Parameters Description
Number of Inputs Number of CAN inputs. It can have up to 8 inputs.
CAN Source The CAN source can be either CAN A or CAN B.
Use Extension ID If this is set to Yes, the ID of a message is a 29-bit integer. If this is set to No, the ID
of a message is a 11-bit integer.
Message ID The ID of a message. It is an integer, for example, 0x23.
Local Mask The mask for the message. It is an integer. If the bits of the message ID matches
the bits of the mask, the message will be received. Otherwise, it will be ignored.
For example, if the mask is 0x380 and the message ID is 0x389, this message will
be received. But if the message ID is 0x480, the message will be ignored.
Overwrite Flag It can be set to Allow overwrite or Do not allow overwrite.
Assume a mailbox is configured to accept a message, and there is a new message
coming from the CAN bus, while the old message is still in the mailbox and has
not been processed yet. If the flag is set to "Allow overwrite", the new message
will be accepted, and the old message will be overwritten. If the flag is set to "Do
not allow overwrite", the new message will not be accepted, and the old one will
be kept.
Image:
CAN
Out
Attributes:
Parameters Description
Number of Outputs Number of CAN outputs. It can have up to 8 outputs.
CAN Source The CAN source can be either CAN A or CAN B.
Use Extension ID If this is set to Yes, the ID of a message is a 29-bit integer. If this is set to No, the ID
of a message is a 11-bit integer.
Message ID The ID of a message. It is an integer, for example, 0x23.
Trigger Type The trigger type can be one of the following:
- No trigger: No triggering
- Rising edge: Triggering occurs at the rising edge of the trigger source.
- Falling edge: Triggering occurs at the falling edge of the trigger source.
- Rising/falling edge: Triggering occurs at both the rising edge and the falling
edge of the trigger source.
A rising/falling edge is considered to have occurred if the difference between the
current value of the trigger source and the value at the last triggering instant is
equal to or greater than 1.
Attributes:
Parameters Description
Time Output Method Define how interrupt time is measured. It can be one of the following:
- SCI (time used): Using SCI. Time used by the interrupt service routine, in
DSP clock count, is measured and is sent out via SCI output.
- SCI (time remaining): Using SCI. Time remaining in the interrupt service
routine, in DSP clock count, is measured and is send out via SCI output. The
time remaining is defined as the time from the end of the current interrupt to
the beginning of the next interrupt.
- GPIO0 to GPIO87: Using a GPIO port. A pulse is generated at the specified
GPIO port. The pulse is set to high when entering the interrupt, and set to low
when exiting the interrupt. An oscilloscope can be used to measure the width of
the pulse.
Sampling Frequency Sampling frequency of the interrupt service routine, in Hz.
When SCI is used, the value is the count of the DSP clock. For example, if the value is 7500, for a 150-MHz
DSP clock, the interrupt time will be: 7500 / 150M = 50 us.
RAM Memory
0x0000 - 0x07FF (2K)
interrupt vectors
stack
0x8000 - 0xFFFF (32K*)
program and data space
Notes:
* The RAM memory predefined by SimCoder for program and data space is:
- For F28335, F28334: from 0x8000 to 0xFFFF (32K)
- For F28332, from 0x8000 to 0xDFFF (16K)
- If the combined program and data space exceeds the size of the RAM space, Flash Release must be
selected as the project setting.
** The flash memory predefined by SimCoder for program space is:
- For F28335: from 0x300000 to 0x33FFFF (256K)
- For F28334: from 0x320000 to 0x33FFFF (128K)
- For F28332: from 0x330000 to 0x33FFFF (64K)
7.1 Overview
With the F2803x Hardware Target, SimCoder can generate code that is ready to run on any hardware boards
based on Texas Instruments’ F2803x fixed-point DSP.
The F2803x Hardware Target will work with all F2803x packages.
The F2803x Hardware Target library includes the following function blocks:
- PWM generators: 3-phase, 2-phase, 1-phase, and APWM
- Variable frequency PWM
- Start/Stop functions for PWM generators
- Trip-one and trip-zone state
- A/D converter
- Comparator input, output, and DAC
- Digital input and output
- Up/Down counter
- Encoder and encoder state
- Capture and capture state
- SCI configuration, Input, and output
- SPI configuration, device, input, and output
- CAN configuration, input, and output
- Interrupt Time
- DSP clock
- Hardware configuration
When generating the code for a system that has multiple sampling rates, SimCoder will use the interrupts of the
PWM generators for the PWM sampling rates. For other sampling rates in the control system, it will use the
Timer 1 interrupt first, and then Timer 2 interrupt if needed, If there are more than three sampling rates in the
control system, the corresponding interrupt routines will be handled in the main program by software.
In TI F2803x, PWM generators can generate hardware interrupt. SimCoder will search and group all the
elements that are connected to the PWM generator and have the same sampling rate as the PWM generator.
These elements will be automatically placed and implemented in an interrupt service routine in the generated
code.
In addition, digital input, encoder, capture, and trip-zone can also generate hardware interrupt. Each hardware
interrupt must be associated with an interrupt block (described in Section 4.5 of this Manual), and each interrupt
block must be associated with an interrupt service routine (a subcircuit that represents the interrupt service
routine). For example, if a PWM generator and a digital input both generate interrupt, there should be one
interrupt block and one interrupt service routine for each of them.
The definitions of the elements in the F2803x Hardware Target library are described in this Chapter.
The figure below shows the F2803x 80-pin PN QFP port assignment.
Image:
The Hardware Configuration block is for user to specify the I/O ports of the F2803x hardware. Every port to be
used must be assigned correctly. The ports not in use can be left unchecked.
For each GPIO port, a check box is provided for each of its available function. When a box is checked, the
GPIO port is configured for that particular function. For example, if the checkbox for "Digital Input" is checked
for port GPIO1, this port is configured as a digital input, and hence, cannot be used for any other functions. If it
is used as a PWM output in the PSIM circuit schematic, an error message will be generated.
Attributes:
Parameters Description
DSP Clock Source There are five ways of providing system clock to F2803x. They are as follows:
- Internal oscillator 1
- Internal oscillator 2
- External oscillator
- External clock (GPIO19)
- External clock (GPIO38)
External Clock (MHz) Frequency of the external clock on the DSP board, in MHz. The frequency must be
an integer, and the maximum frequency allowed is 10 MHz. This parameter is
ignored if the DSP clock source is selected to be internal oscillator 1 or 2.
DSP Speed (MHz) DSP Speed, in MHz. The speed must be an integer, and must be an integer
multiple of the external clock frequency, from 1 to 12 times. The maximum DSP
speed allowed is 60 MHz.
If a DSP Configuration block is not used in a circuit, the default values of the DSP Configuration block are
used.
Image:
Attributes:
Parameters Description
PWM Source Source of the PWM generator. It can be either "3-phase PWM 123" that uses PWM
1 to 3, or "3-phase PWM 456" that uses PWM 4 to 6.
Dead Time The dead time Td for the PWM generator, in sec.
Sampling Frequency Sampling frequency of the PWM generator, in Hz. The calculation is done and the
PWM signal duty cycle is updated based on this frequency.
PWM Freq. Scaling The ratio between the PWM switching frequency and the sampling frequency. It
Factor can be from 1 to 100. For example, if the sampling frequency is 50 kHz and the
scaling factor is 3, the PWM switching frequency will be 150 kHz. That is
switches will operate at 150 kHz. But gating signals will be updated at 50 kHz, or
once per 3 switching cycles.
Carrier Wave Type The carrier wave type and the initial PWM output state. It can be one of the
following:
- Triangular (start low): Triangular wave, and the initial PWM output state is low.
- Triangular (start high): Triangular wave, and the initial output state is high.
- Sawtooth (start low): Sawtooth wave, and the initial output state is low.
- Sawtooth (start high): Sawtooth wave, with the initial output state is high.
Trigger ADC Setting whether for the PWM generator to trigger the A/D converter. It can be one
of the following:
- Do not trigger ADC: PWM does not trigger the A/D converter.
- Trigger ADC: PWM will trigger A/D converter.
Trip Action Define how the PWM generator responds to the trip action. It can be one of the
following:
- High impedance: PWM outputs in high impedance
- PWM A high & B low: Set PWM A high and B low.
- PWM A low & B high: Set PWM A low and B high.
- No action: No action taken.
Peak-to-Peak Value Peak-to-peak value Vpp of the carrier wave
Offset Value DC offset value Voffset of the carrier wave
Initial Input Value u, v, Initial value of 3-phase inputs u, v, and w
w
Start PWM at When it is set to "Start", PWM will start right from the beginning. If it is set to "Do
Beginning not start", one needs to start PWM using the "Start PWM" function.
Simulation Output The simulation output mode can be set to Switching mode or Average mode.
Mode When it is set to "Switching mode", the outputs of the PWM block are PWM
signals. When it is set to "Average mode", the outputs of the PWM block are
average mode signals.
In the average mode, if the carrier wave is from negative to positive, and the
absolute values of the negative peak and the positive peak are equal (for example,
the carrier wave is from -1 to +1, or from -5 to +5), the modulation is considered as
an ac signal modulation. Otherwise, the modulation is considered as a dc signal
modulation. For example, modulation in a 3-phase or single-phase inverter is an ac
modulation, and modulation in a buck converter is a dc modulation.
In the ac signal modulation, if the input u of the PWM block is Vu, the output up
and un in average mode will be:
Vup = Vu / (Vpp + Voffset)
Vun = -Vup
In this case, Vu is between -(Vpp+Voffset) and Vpp+Voffset, and Vup is between -1 to
+1.
In the dc signal modulation, the output up and un in average mode will be:
Vup = (Vu - Voffset) / Vpp
Vun = 1 - Vup
In this case, Vu is between Voffset and Vpp+Voffset, and Vup is between 0 to +1.
When it is set to the average mode, the PWM block outputs can be connected to a
converter/inverter in the average mode model.
Attributes:
Parameters Description
PWM Source Source of the PWM generator. Without phase shift, it can be PWM 1 to PWM 7.
With phase shift, it can be PWM 2 to PWM 7.
Output Mode The output mode of the PWM generator. It can be one of the following:
- Use PWM A&B: Both PWM outputs A and B are used, and they are
complementary.
- Use PWM A: Only PWM output A is used.
- Use PWM B: Only PWM output B is used.
Dead Time The dead time Td for the PWM generator, in sec.
Sampling Frequency Sampling frequency of the PWM generator, in Hz. The calculation is done and the
PWM signal duty cycle is updated based on this frequency.
PWM Freq. Scaling The ratio between the PWM switching frequency and the sampling frequency. It
Factor can be from 1 to 100. For example, if the sampling frequency is 50 kHz and the
scaling factor is 3, the PWM switching frequency will be 150 kHz. That is
switches will operate at 150 kHz. But gating signals will be updated at 50 kHz, or
once per 3 switching cycles.
Carrier Wave Type The carrier wave type and the initial PWM output state. It can be one of the
following:
- Triangular (start low): Triangular wave, and the initial PWM output state is
low.
- Triangular (start high): Triangular wave, and the initial output state is high.
- Sawtooth (start low): Sawtooth wave, and the initial output state is low.
- Sawtooth (start high): Sawtooth wave, and the initial output state is high.
Trigger ADC Setting whether for the PWM generator to trigger the A/D converter. It can be one
of the following:
- Do not trigger ADC: PWM does not trigger the A/D converter.
- Trigger ADC Group A: PWM will trigger Group A of the A/D converter.
- Trigger ADC Group B: PWM will trigger Group B of the A/D converter.
- Trigger ADC Group A&B: PWM will trigger both Group A and B of the A/D
converter.
ADC Trigger Position The A/D trigger position ranges from 0 to a value less than 1. When it is 0, the A/
D converter is triggered at the beginning of the PWM cycle, and when it is 0.5, the
A/D converter is triggered at the 180o position of the PWM cycle.
Use Trip-Zone i Define whether the PWM generator uses the ith trip-zone signal or not, where i
ranges from 1 to 6. It can be one of the following:
- Disable Trip-Zone i: Disable the ith trip-zone signal.
- One shot: The PWM generator uses the trip-zone signal in the one-shot mode.
Once triggered, the PWM must be started manually.
- Cycle by cycle: The PWM generator uses the trip-zone signal in the cycle-by-
cycle basis. The trip-zone signal is effective within the current cycle, and PWM
will automatically re-start in the next cycle.
Carrier Wave
There are two types of carrier waveforms: triangular wave (with equal rising and falling slope intervals) and
sawtooth wave. In addition, there are two operation modes: start-low and start-high modes, as explained below.
The input and output waveforms of a PWM generator with the triangular carrier wave are shown below:
Start-High Mode Start-Low Mode
VH PWM input vm
VH
Carrier wave V -(v -V )
PWM H m L
Vpp
input vm Vpp
VL VL
Voffset
Voffset t t
Td PWMxA PWMxA
x = 1, 2, ..., 6
Td PWMxB PWMxB
The input and output waveforms of a PWM generator with the sawtooth carrier wave are shown below:
Start-High Mode Start-Low Mode
Carrier wave PWM input vm
VH VH
V -(v -V )
PWM Vpp H m L
input vm Vpp
VL VL
Voffset t t
Td Voffset
PWMxA PWMxA
x = 1, 2, ..., 6
Td PWMxB
PWMxB
The figures above show how the dead time is defined, and the time sequence when the PWM generator triggers
the A/D converter. If triggering the A/D converter is selected, from the start of the PWM cycle, after a certain
delay defined by the A/D trigger position, the A/D conversion will start. After the A/D conversion is completed,
the PWM interrupt service routine will start.
Conditioning circuit
Note: In the start-low mode, the PWM input vm is converted to VH-(vm-VL) internally before it is compared with
the carrier wave to generate the PWM signal. With the conversion, both the start-low and start-high modes will
have the same duty cycle expression. For example, for a sawtooth wave with VL=0 and VH=1, or for a triangular
wave with VL= -VH, the duty cycle D of the PWMA output in both the start-low and start-high modes is:
D = vm/VH.
Image:
Parameters Description
PWM Source Source of the PWM generator. It can be PWM 1 to PWM 6.
Mode Type The operation mode of the PWM generation. It can be one of the 6 modes. The
waveforms of the 6 operation modes are described below.
Sampling Frequency Sampling frequency of the PWM generator, in Hz. The calculation is done and the
PWM signal duty cycle is updated based on this frequency.
PWM Freq. Scaling The ratio between the PWM switching frequency and the sampling frequency. It
Factor can be from 1 to 100. For example, if the sampling frequency is 50 kHz and the
scaling factor is 3, the PWM switching frequency will be 150 kHz. That is
switches will operate at 150 kHz. But gating signals will be updated at 50 kHz, or
once per 3 switching cycles.
Trigger ADC Setting whether for the PWM generator to trigger the A/D converter. It can be one
of the following:
- Do not trigger ADC: PWM does not trigger the A/D converter.
- Trigger ADC Group A: PWM will trigger Group A of the A/D converter.
- Trigger ADC Group B: PWM will trigger Group B of the A/D converter.
- Trigger ADC Group A&B: PWM will trigger both Group A and B of the A/D
converter.
ADC Trigger Position The A/D trigger position ranges from 0 to a value less than 1. When it is 0, the A/
D converter is triggered at the beginning of the PWM cycle, and when it is 0.5, the
A/D converter is triggered at the 180o position of the PWM cycle.
Use Trip-Zone i Define whether the PWM generator uses the ith trip-zone signal or not, where i
ranges from 1 to 6. It can be one of the following:
- Disable Trip-Zone i: Disable the ith trip-zone signal.
- One shot: The PWM generator uses the trip-zone signal in the one-shot
mode. Once triggered, the PWM must be started manually.
- Cycle by cycle: The PWM generator uses the trip-zone signal in the cycle-by-
cycle basis. The trip-zone signal is effective within the current cycle, and PWM
will automatically re-start in the next cycle.
PWMA DC Trip Digital compare (DC) trip source DCAH for PWMA. The PWM channel may have
Src1(DCAH) up to two DC trip sources: DCAH and DCAL. The trip source can be one of the
following:
- Do not use: PWM doesn't use this signal.
- Trip-zone 1: PWM uses trip-zone 1 as digital compare input signal.
- Trip-zone 2: PWM uses trip-zone 2 as digital compare input signal.
- Trip-zone 3: PWM uses trip-zone 3 as digital compare input signal.
- Comparator 1: PWM uses Comparator 1 as digital compare input signal.
- Comparator 2: PWM uses Comparator 2 as digital compare input signal.
- Comparator 3: PWM uses Comparator 3 as digital compare input signal.
PWMA DC Trip Digital compare (DC) trip source DCAL for PWMA. The trip source can be one of
Src1(DCAL) the following:
- Do not use: PWM doesn't use this signal.
- Trip-zone 1: PWM uses trip-zone 1 as digital compare input signal.
- Trip-zone 2: PWM uses trip-zone 2 as digital compare input signal.
- Trip-zone 3: PWM uses trip-zone 3 as digital compare input signal.
- Comparator 1: PWM uses Comparator 1 as digital compare input signal.
- Comparator 2: PWM uses Comparator 2 as digital compare input signal.
- Comparator 3: PWM uses Comparator 3 as digital compare input signal.
For 2-phase PWM generators, the outputs are determined based on the mode of operation, as described below.
The carrier wave is either sawtooth or triangular, depending on the mode of operation. It increases from 0 to the
peak value Vpk, and there is no dc offset.
Operation Mode 1:
The figure below on the left shows the waveforms of Mode 1. In the figure, "CA" and "CB" refer to two inputs
A and B of the 2-phase PWM generator. Each input controls the turn-off time of each output.
Operation Mode 2:
The figure below on the right shows the waveforms of Mode 2. Unlike in Mode 1, each input controls the turn-
on time of each output.
0 t t
CB CA CB CA CB CA CB CA
PWMxA PWMxA
PWMxB PWMxB
Operation Mode 3:
The figure below on the left shows the waveforms of Mode 3. Input A controls the turn-on and Input B controls
the turn-off of the PWM output A. The PWM output B is on for one complete PWM cycle, and is off for the
next cycle.
Operation Mode 4:
The figure below on the right shows the waveforms of Mode 4. The carrier wave is triangular. Each input
controls both the turn-on and turn-off of its output.
Mode 3: Mode 4:
t CA CA CA CA t
CA CB CA CB CB CB CB CB
PWMxA PWMxA
PWMxB PWMxB
Operation Mode 5:
The figure below on the left shows the waveforms of Mode 5. The carrier wave is triangular. Similar to Mode 4,
each input controls both the turn-on and turn-off of its output. Note that PWM output B is inverted in this case.
Operation Mode 6:
The figure below on the right shows the waveforms of Mode 6. In this mode, Input A controls the turn-on and
Input B controls the turn-off of PWM output A. The PWM output B is on for the first half PWM cycle, and is
off for the second half cycle.
Mode 5: Mode 6:
t CA CB CA CB t
CA CA CA CA
CB CB CB CB
PWMxA PWMxA
PWMxB PWMxB
Image:
Attributes:
Parameters Description
PWM Source APWM generators share the same resource as captures. The PWM source can be
from one of the three designated GPIO ports: APWM 1 (GPIO5, 19, 24)
PWM Frequency Frequency of the PWM generator, in Hz
Carrier Wave Type The carrier wave type and the initial PWM output state. It can be one of the
following:
- Sawtooth (start low): Sawtooth wave, with the PWM output in the low state
initially.
- Sawtooth (start high): Sawtooth wave, with the PWM output in the high state
initially.
Stop Action The output status when the PWM generator is stopped. It can be one of the
following:
- Output low: The PWM output will be set to low.
- Output high: The PWM output will be set to high.
Peak-to-Peak Value Peak-to-peak value of the carrier wave
Offset Value DC offset value of the carrier wave
Phase Shift Phase shift of the output with respect to the reference PWM generator, in deg.
Initial Input Value Initial value of the input
Start PWM at When it is set to Start, PWM will start right from the beginning. If it is set to Do
Beginning not start, one needs to start PWM using the Start PWM block.
Similar to 1-phase PWM generators, an APWM generator can generate a PWM signal that has a phase shift
with respect to another PWM generator. The way how PWM blocks are defined for phase shift is explained in
Section 7.4.5.
As noted before, the APWM generators has reduced number of functions than 1-phase PWM generators. It can
not trigger the A/D converter and can not use the trip-zone signal.
Image:
Variable
Freq
F2803x
Attributes:
Parameters Description
PWM Source Source of the PWM generator. It can be one of the following:
PWM 1, PWM 2, PWM 3, PWM 4, PWM 5, PWM 6, 3-phase PWM 123, and 3-
phase PWM 456.
Adjust Interrupt Pos. Specify if the interrupt position is adjusted with the frequency. It can be one of the
following:
- Do not adjust: The interrupt position will remain unchanged as calculated with
the base frequency.
- Adjust: The interrupt position will be recalculated at the beginning of
each cycle based on the new frequency.
Adjust Ramp Specify if the ramp compensation of the comparator DAC block is adjusted with
Compensation the frequency. It can be one of the following:
- Do not adjust: The ramp compensation will remain unchanged as calculated
with the base frequency.
- Adjust: The ramp compensation will be recalculated at the beginning of
each cycle based on the new frequency.
The sampling frequency of the corresponding PWM block will be changed at the beginning of the next PWM
period as follows:
PWM_Frequency = PWM_Base Frequency / Input_Value
where PWM_Base_Frequency is the sampling frequency of the corresponding PWM block, and Input_Value is
the input value of this block.
If the interrupt position is to be adjusted, the interrupt position will be recalculated in each cycle. Since
adjusting the interrupt position takes time, if the frequency change is small, it is recommended not to adjust the
interrupt position.
Similarly, if the ramp compensation is to be adjusted, the ramp compensation will be recalculated in each cycle.
Since adjusting the ramp compensation takes time, if the frequency change is small, it is recommended not to
Images:
Attributes:
Parameters Description
PWM Source The source of the PWM generator. It can be: PWM 1-7, 3-phase PWM 123 and
PWM 456, and Capture 1.
Image:
Parameters Description
Use Trip-Zone i Specify if this Trip-Zone i is used.
GPIO Port for Trip-Zone i Specify a designated GPIO port as Trip-Zone input signal.
- GPIO port for trip-zone 1: select either GPIO12 or 13
- GPIO port for trip-zone 2: select either GPIO13, 16, or 18
- GPIO port for trip-zone 3: select either GPIO14, 17, or 19
Use Comparator i Specify if comparator 1, 2, or 3 is used as Trip-Zone input signal i
Parameters Description
PWM Source The source of the PWM generator. It can be: PWM 1-7, and 3-phase PWM
123 and PWM 456.
As shown above, the A/D converter element in SimCoder is not exactly the same as the physical A/D converter
on the DSP. Rather, it combines the functions of an offset circuit, the DSP A/D converter, and a scaling block.
This is designed for the convenience of AC system applications. It will be further explained in Section 6.5.3.
In many applications, the circuit variables to be monitored are AC signals, especially in AC motor drive
systems. For each of this kind of AC signals, an offset circuit must be built in the hardware on circuit board at
the input of the DSP analog input, in order to shift the signal level to the acceptable range of 0 to +3.3V.
SimCoder’s A/D converter provides the convenience for such cases. Instead of level-shifting and scaling the
A/D output signals, user may chose to use the offset option and scaling factor in the SimCoder A/D converter,
and the target code will be generated accordingly.
The image and the parameters of the A/D converter in the target library are described below. In the following
description, "A/D converter" refers to the A/D converter in the target library, not the DSP A/D converter, unless
otherwise stated.
F2803x
Attributes:
Parameters Description
Ch Ai or Bi Mode Input mode of the ith A/D converter channel Ai or Bi. The input mode can be one of
the following:
- AC: This option is for simulation only, not for code generation. The input
range is considered from -1.65V to +1.65V. This option includes the offset
circuit into the A/D converter. It provides the convenience in cases where an
external level shifter is needed to shift the AC signal to the 0 to +3.3V range.
- DC: The input is a dc value, and the range is from 0 to +3.3V.
Ch Ai or Bi Gain Gain k of the ith A/D converter channel Ai or Bi.
Conversion Order Order of the A/D conversion. If the field is left blank (undefined), the conversion
will be done based on the serial numbers of the A/D channel. For example, if A0,
A2, A4, B1, and B3 are used, the conversion will be done in this order: A0, A2,
A4, B1, and B3. If you wish certain channels to be performed first, you can define
the order here. For example, if the conversion order is defined as:
A4,A0,A2,B3,B2
The conversion will be done in the order defined, that is, A4 before A0, and A0
before A2, and so on.
ADCINT1 PIE Specify if interrupt ADCINT1 uses PIE Group1 or PIE Group10.
Selection
ADCINT2 PIE Specify if interrupt ADCINT2 uses PIE Group1 or PIE Group10.
Selection
An A/D converter has up to 16 channels. SimCoder divides them into groups according their sampling rates.
The group with the highest sampling rate uses interrupt ADCINT1, and the group with the second highest
sampling rate uses interrupt ADCINT2, etc. The two ADC groups with the highest sampling rates can choose
interrupt from PIE (peripheral interrupt expansion) groups of the PIE vector table for different interrupt priority.
PIE Group1 has a higher interrupt priority than PIE Group10. For example, PWM's interrupt is in PIE Group3,
Its interrupt priority is lower than PIE Group1 but higher than Group10. If one wants PWM interrupt to have a
higher priority than ADC interrupt, one needs to set the interrupt corresponding to the ADC channels to use PIE
Group10.
Trigger Source:
The A/D converter can be triggered from multiple sources. Multiple A/D channels may share the same trigger
source. Each A/D channel can be triggered by:
DC Signal Input
0 V -> +3.3 V
Please note that, in this example, if the gain of the proportional block is changed from 2.2 to 1.1, and the A/D
gain is changed from 45.4545 to 90.909, the simulation results will be the same. But the generated hardware
code will not be correct. This is because the hardware code assumes that the maximum input value is scaled to
+3.3V, but in this case it is only +1.5V. Therefore, one must set up the circuit such that, in the dc mode, the
maximum input value is scaled to be +3.3V.
In another example, assume that a power circuit voltage is an ac quantity, and the range is as follows:
Vi_max = +/- 75 V
The input mode of the A/D converter will be set to ac, and the input range is from -1.65V to +1.65V. Assume
that the actual value of the voltage has a peak value of:
Vi = +/- 50 V
Let the voltage sensor gain be 0.01. After the voltage sensor, the maximum value and the actual value of the
input become:
Vi_max_s = +/- 0.75 V
Vi_s = +/- 0.5 V
Since the A/D converter input range is from -1.65V to +1.65V, this signal must be scaled before it is sent to the
DSP. A conditioning circuit with a gain of 2.2 is needed (i.e. 1.65/0.75 = 2.2). After the conditioning circuit and
at the input of the DSP A/D converter, the maximum value and the actual value of the input become:
Vi_max_s_c = +/- 1.65 V
Vi_s_c = +/- 1.1 V
The scaling block after the DSP A/D can be selected such that the original power circuit quantity is restored. In
this example, a gain of 45.4545 will be used. Note that this is the reciprocal of the combined gain of the voltage
sensor and the conditioning circuit. At the A/D output, the maximum value and the actual value are:
Vo_max = +/- 75 V
Vo = +/- 50 V
The gain of the A/D channel in PSIM will be set to 45.4545. The circuit connection and the settings are shown
in the figure below.
AC Signal Input
-1.65 V -> +1.65 V
Notice that in this circuit, the ac signal is sent to the A/D converter directly. This is because that, when the A/D
input mode is set to AC, the input range is from -1.65V and +1.65V, and the function of the conditioning circuit
that performs the dc offset is already included in the A/D converter block. In the actual hardware circuit, the ac
signal must be scaled and offset so that the range is within 0V to +3.3V required by the A/D converter.
7.9 Comparator
F2803x support three comparator modules. Each comparator block can accommodate two external analog
inputs, or use one external analog input and use the internal DAC reference for the other input. The comparator
output can be sent to the PWM trip-zone and to the GPIO output.
Image:
Parameters Description
Comparator i Define how the output of the ith comparator is used. It can be one of the
following:
- Do not use: Not used
- As a normal comparator: Used as a normal comparator
- As a Trip-Zone signal: Used as a trip-zone signal
Output Logic Define the comparator output logic. It can be:
- High when A > B: The output is high when Input A is greater than B.
- High when A < B: The output is high when Input A is less than B.
Compare Method Define how Input A of the comparator is compared to Input B. it can be
one of the following:
- Compare to Input B: Input A is compared to Input B where Input
B is an external analog signal.
- Compare to Constant Value: Input A is compared to a constant value.
- Compare to DAC output: Input A is compared to a DAC output
which is an internal signal.
Constant Value The constant value when Compare Method is defined as Compare to
Constant Value. The range of the constant value is from 0 to 3.3V.
For all comparators, Input A is always from an external analog input. If Input B is also from another external
analog input (if the parameter Compare Method is defined as Compare to Input B), the corresponding port must
be defined as a comparator input in the Hardware Configuration block.
If the compare method is to compare to a constant value, Input B needs to be connected to ground in the
schematic. If the compare method is to compare to a DAC output, Input B needs to be connected a comparator
DAC output. In both cases, the corresponding ADC/AIO port can be used for other functions.
Image:
Attributes:
Parameters Description
Comparator i Output Output port position of the ith comparator. It can be:
- For Comparator A: GPIO1, 20, or 42
- For Comparator B: GPIO3, 21, 34, or 43
- For Comparator C: GPIO34
A comparator output block must be used together with a comparator input block. When a comparator output
channel is used, the corresponding comparator input channel must be defined.
Image:
Attributes:
Parameters Description
DAC i Range The upper limit of the input signal range of the ith comparator DAC. The lower
limit is 0.
Use Ramp Generator Define if the ramp generator is used in the comparator DAC.
Total Ramp The total compensation of the ramp generator in one PWM period. It represents the
Compensation total decrease of the ramp in one cycle.
Outputs of the comparator DAC can only be connected to the corresponding inverting inputs (Input B) of the
comparator in a comparator input block. That is, node out1 can only be connected to node B1 of the comparator
input block, and node out2 to node B2, and node out3 to B3. Also, a comparator DAC block cannot be used
alone. It must be used in conjunction with a comparator input block.
If the ramp generator is not used, the input value is applied directly to DAC output immediately. The output
range is from 0 to 3.3V, and the output can be calculated as follows:
DAC Output = DAC Input * 3.3 / DAC Range
If the ramp generator is used, the input value is saved and used as the initial output value in the next PWM
period. The comparator DAC output decreases linearly within the PWM period, and the total decrease is equal
to the total ramp compensation value.
When the ramp generator is used, the sampling rate associated with the comparator DAC input must be the
same as the frequency of the PWM generator that uses the comparator.
Images:
Parameters Description
Port Position for Input i The port position of the Input i, where i is from 0 to 7. It can be one of the
45 GPIO ports or one of the 6 AIO ports.
Use as External Interrupt Indicate if this port is used as an external interrupt input.
Parameters Description
Port Position for Output i The port position of the Output i, where i is from 0 to 7. It can be one of
the 45 GPIO ports or one of the 6 AIO ports.
Note that each GPIO and AIO port can be used for one function only. If an IO port is used as a digital input port,
it can not be used as a digital output or any other peripheral port. For example, if Port GPIO1 is assigned as
digital input and it is also used as PWM1 output, an error will be reported.
F2803x DSP supports 3 masked external interrupts (XINT1 to XINT3). There are no dedicated pins for the
external interrupts. XINT1, XINT2, and XINT3 interrupts can accept inputs from GPIO0 to GPIO31 pins.
Image:
Attributes:
In the image, "Clk" refers to the input clock signal, and "Dir" refers to the signal that defines the counting
direction. When the "Dir" input is 1, the counter counts forward, and when the input is 0, the counter counts
backward.
The output of the up/down counter gives the counter value.
Note that the up/down counter uses the same resource as the encoder, and the same GPIO ports cannot be used
in a counter and in an encoder at the same time. For example, using both Encoder 1 and Up/Down Counter 1
will cause conflict and is not allowed.
Images:
Encoder
Index Pos
A
B Cnt Cnt
Z State
Strobe F2803x
F2803x
F2803x
Parameters Description
Use Z Signal Define if the encoder uses the Z (or index) signal.
Use Strobe Signal Define if the encoder uses the strobe signal.
Counting Direction The counting direction
- Forward: the encoder counts up.
- Reverse: the encoder counts down.
Z Signal Polarity Define the trigger polarity of Z signal.
- Active High
- Active Low.
Strobe Signal Polarity Define the trigger polarity of strobe signal.
- Active High
- Active Low.
Encoder Resolution The resolution of the external encoder hardware. If it is 0, the encoder counter will
keep on counting and will not reset. If for example, the resolution is set to 4096,
the counter will be reset to 0 after it reaches 4095.
Parameters Description
Latch Position Specify the kept counter type, choose from the followings:
- IndexPos, if the setting "Use Z Signal" is not "No" in Encoder
- StrobePos, if the setting "Use Strobe Signal" is not "No" in Encoder
Type of Position This can be chosen from the followings:
- The first latched position, or
- The current latched position
Images:
Parameters Description
Capture Source Source of the capture may come from one of 3 GPIO ports, as listed below:
- Capture 1 (GPIO 5)
- Capture 1 (GPIO 19)
- Capture 1 (GPIO 24)
Event Filter Prescale Event filter prescale. The input signal is divided by the selected prescale.
Timer Mode Capture counter timer mode. It can be either Absolute time or Time difference.
Parameters Description
Capture Source Source of the capture. It has only one source Capture1.
The Capture State block output is either 1 or 0, where 1 means the rising edge and 0 means the falling edge.
Image:
SCI
Config
F2803x
Attributes:
Parameters Description
SCI Port Define the SCI port. Different sets of GPIO ports that can be used for SCI, as listed
below:
SCIA: GPIO 28 and 7 in combination with GPIO 29 and 12
Speed (bps) SCI communication speed, in bps (bits per second). A list of preset speeds is
provided at 200000, 115200, 57600, 38400, 19200, or 9600 bps. Or one can
specify any other speed manually.
Parity Check The parity check setting for error check in communication. It can be either None,
Odd, or Even.
Output Buffer Size Size of the data buffer allocated in DSP for SCI. The buffer is located in the RAM
area, and each buffer cell stores one data point which consists of three 16-bit words
(that is, 6 bytes, or 48 bits, per data point).
Image:
SCI
F2803x
Attributes:
Parameters Description
Initial Value The initial value of the SCI input variable.
In the schematic, the SCI input behaviors as a constant. While its value can be changed at runtime when the
code is running on the DSP, the value will be fixed at the initial value in the simulation.
Image:
SCI
F2803x
Attributes:
Parameters Description
Data Point Step It defines how frequent data is collected. If the Data Point Step is 1, every data
point is collected and transmitted. If the Data Point Step is 10, for example, only
one point of out every 10 points is collected and transmitted.
Note that if the Data Point Step is too small, there may be too many data points and it may not be possible to
transmit them all. In this case, some data points will be discarded during the data transmission.
Also, the Data Point Step parameter is used only when then DSP Oscilloscope is in the continuous mode. When
it is in the snap-shot node, this parameter is ignored and every point is collected and transmitted.
In simulation, the SCI output behaviors as a voltage probe.
Images:
Image:
SPI Config
CS0
CS1
CS2
CS3
F2803x
Attributes:
Parameters Description
SPI Port Define the SPI port from the options:
- SPIA (GPIO 16-19)
- SPIA (GPIO 3, 5, 18, 19)
- SPIB (GPIO 12-15)
- SPIB (GPIO 24-27)
Chip Select Pin0, 1, 2, The GPIO port of the chip select pin. PSIM supports up to 16 SPI devices, which
and 3 requires four GPIO pins for chip select, as defined by Chip Select Pin0 to Pin3.
These GPIO ports and the SPI slave transmit-enable pin SPISTE are used to
generate the chip select signal.
SPI Buffer Size The buffer size of the SPI commands. Each memory cell of the buffer saves the
index of a SPI command. Normally, one can specify the buffer size as 1 plus the
number of SPI commands (i.e. Start Conversion Command, Receiving Data
Command, Sending Data Command, and Sync. Command) in all SPI Input/Output
elements.
Image:
SPI Device
CS0
CS1
CS2 Intr
CS3
Sync
F2803x
Attributes:
Parameters Description
Chip Select Pins The state of the chip select pins corresponding to the SPI device. When the chip
select pins are at this state, this SPI device is selected.
Communication Speed SPI communication speed, in MHz.
(MHz)
Clock Type SPI clock type, as determined by the SPI hardware device. It can be one of the
following:
- Rising edge without delay: The clock is normally low, and data is latched at the
clock rising edge.
- Rising edge with delay: The clock is normally low, and data is latched at the
clock rising edge with delay.
- Falling edge without delay: The clock is normally high, and data is latched at
the clock falling edge.
- Falling edge with delay: The clock is normally high, and data is latched at the
clock falling edge with delay.
Command Word Word length, or the length of the significant bits, of SPI communication
Length commands. It can be from 1 to 16 bits.
Sync. Active Mode The triggering mode of the synchronization signal of the SPI device. It can be
either Rising edge or Falling edge.
SPI Initial Command The SPI command that initializes the SPI device.
Hardware Interrupt Specify the type of the interrupt signal that the SPI device generates. This is valid
Mode only when the SPI device’s interrupt output node is connected to the input of a
digital output element. It can be one of the following:
- No hardware interrupt
- Rising edge
- Falling edge
Image:
SPI
F2803x
Parameters Description
Device Name Name of the SPI input device.
Start Conversion Command to start conversion, in hex numbers, separated by comma (for example,
Command 0x23,0x43,0x00).
Receiving Data Command to receive data, in hex numbers, separated by comma (for example,
Command 0x23,0x43,0x00).
Data Bit Position Define where the data bits are in the receiving data string. The format is:
ElementName = {Xn[MSB..LSB]}
where
- ElementName is the name of the SPI input device. If it is the current SPI input
device, use y instead.
- {} means that the item in the bracket repeats multiple times.
- Xn is the nth word received from the SPI input device, and n start from 0.
- MSB..LSB defines the position of the significant bits in the word.
Input Range Specify the parameter Vmax that defines the input range. This parameter is valid
only when the SPI device is an A/D converter. If the device conversion mode is
DC, the input ranges from 0 to Vmax. If the device conversion mode is AC, the
input ranges from -Vmax/2 to Vmax/2.
Scale Factor Output scale factor Kscale. If the scale factor is 0, the SPI device is not an A/D
converter, and the result will be exactly the same as what DSP receives from SPI
communication. Otherwise, the SPI device is an A/D converter, and the result is
scaled based on this factor and the A/D conversion mode.
ADC Mode The A/D conversion mode of the device. It can be either DC or AC. Note that this
parameter is valid only when the device is an A/D converter.
Initial Value The initial value of the input.
The formula for the Data Bit Position defines the data length of a SPI input device. For example,
y=x1[3..0]x2[7..0], means that the data length is 12, and the result is the lower 4 bits of the 2nd word and the
lower 8 bits of the 3rd word. If the received data string is 0x12,0x78,0xAF, then the result is 0x8AF.
If the scale factor is not 0, the output will be scaled based on the following:
In the DC conversion mode:
- In simulation: Output = Input K scale
Data_Length
2
In the AC conversion mode:
) V max Ksc al e
- In hardware: Output = (Result – 2Data_Length-1 ------- ---------
-----------------------
The parameter Data_Length is calculated from the Data Bit Position formula.
SPI
F2803x
Attributes:
Parameters Description
Device Name Name of the SPI output device.
Scale Factor Output scale factor Kscale. If the scale factor is 0, the SPI device is not a D/A
converter, and the result will be exactly the same as what DSP receives from SPI
communication. Otherwise, the SPI device is an D/A converter, and the result is
scaled based on this factor and the D/A conversion mode.
Output Range Specify the parameter Vmax that defines the output range. This parameter is valid
only when the SPI device is an D/A converter. If the device conversion mode is
DC, the input ranges from 0 to Vmax. If the device conversion mode is AC, the
input ranges from -Vmax/2 to Vmax/2.
DAC Mode The D/A conversion mode of the device. It can be either DC or AC. Note that this
parameter is valid only when the device is a D/A converter.
Sending Data Command to send the output data, in hex numbers, separated by comma (for
Command example, 0x23,0x43,0x00).
Data Bit Position Define where the data bits are in the sending data string. The format is:
ElementName = {Xn[MSB..LSB]}
where
- ElementName is the name of the SPI output device. If it is the current SPI
output device, use y instead.
- {} means that the item in the bracket repeats multiple times.
- Xn is the nth word sent to the SPI output device, and n start from 0.
- MSB..LSB defines the position of the significant bits in the word.
Sync. Command The command to synchronize output channels of the SPI output device, in hex
numbers, separated by comma (for example, 0x23,0x43,0x00). This command is
used when the SPI output device does not have the synchronization signal
The formula for the Data Bit Position defines the data length of a SPI output device. For example,
y=x1[3..0]x2[7..0], means that the data length is 12, and the data is the lower 4 bits of the 2nd word and the
lower 8 bits of the 3rd word. If the sending data string is 0x12,0x78,0xAF, then the data is 0x8AF.
If the scale factor is not 0, the output will be scaled based on the following:
In the DC conversion mode:
- In simulation: Output = Input K scale
V max
In the AC conversion mode:
Image:
CAN
Config
F2803x
Attributes:
Parameters Description
CAN Source The CAN source can be one of the two groups: CAN A and CAN B.
CAN A uses a combination of GPIO 19 and 31 for transmit, versus GPIO 18 and
30 for receive.
CAN B uses a combination of GPIO 8, 12, 16 and 20 for transmit, versus GPIO 10,
13, 17, and 21 for receive.
CAN Speed Communication speed, in Hz. It can be set to one of the following preset values:
125kHz, 250kHz, 500kHz, and 1MHz
Or you can set the speed manually by typing the text in the parameter field. Note
that the speed should not exceed 1MHz.
Data Byte Order The order of the data bytes. It can be one of the following:
- Least significant byte 1st
- Most significant byte 1st
"Least significant byte 1st" means that the least significant byte is placed first;
while "Most significant byte 1st" means that the most significant byte is placed
first.
Number of Input Number of input mailboxes
Mailboxes
Checking Receive Mail If it is set to Enable, the error report function "_ProcCanAErrReport(nErr)" (for
Lost CAN A) will be called if the received mail is lost. This function will return the
value of the error status nErr.
If it is set to Disable, the error report function will not be called.
Checking Bus Off If it is set to Enable, the error report function "_ProcCanAErrReport(nErr)" (for
CAN A) will be called if the bus is in the off state. This function will return the
value of the error status nErr from the CAN register CANGIF0.
If it is set to Disable, the error report function will not be called.
Error Check Mode The error check mode can be either Passive or Active. If it is in the error-passive
mode, an interrupt will be generated when the error count reaches 128. If it is in
the error-active mode, an interrupt will be generated every time.
The returned status nErr in the function "_ProcCanAErrReport(nErr)" (for CAN A) is a 32-bit integer. It obtains
Image:
CAN
In
Attributes:
Parameters Description
Number of Inputs Number of CAN inputs. It can have up to 8 inputs.
Use Extension ID If this is set to Yes, the ID of a message is a 29-bit integer. If this is set to No, the ID
of a message is a 11-bit integer.
Message ID The ID of a message. It is an integer, for example, 0x23.
Local Mask The mask for the message. It is an integer. If the bits of the message ID matches
the bits of the mask, the message will be received. Otherwise, it will be ignored.
For example, if the mask is 0x380 and the message ID is 0x389, this message will
be received. But if the message ID is 0x480, the message will be ignored.
Overwrite Flag It can be set to Allow overwrite or Do not allow overwrite.
Assume a mailbox is configured to accept a message, and there is a new message
coming from the CAN bus, while the old message is still in the mailbox and has
not been processed yet. If the flag is set to "Allow overwrite", the new message
will be accepted, and the old message will be overwritten. If the flag is set to "Do
not allow overwrite", the new message will not be accepted, and the old one will
be kept.
Receive Message Rate The number of messages received by the input block in a specific period of time.
For example, there are two input blocks, with the first input block receiving 20
messages per second, and the second input block receiving 30 messages per
second. The parameter "Receive Message Rate" will be set to 20 for the first block,
and 30 for the second block.
Inputi Gain The gain to the ith input where i can be 1 to 8. The output is the input multiplied by
the gain.
Inputi Data Start A message can have up to 8 data points. A data point can have 1 bit up to 32 bits.
Position This defines the start position of the current data point in the message.
Inputi Data End This defines the end position of the current data point in the message.
Position
Inputi Data Type The data type can be either Float, Integer, or IQ1 to IQ30.
Inputi Default Data The initial value of the SCI input variable.
Image:
CAN
Out
Attributes:
Parameters Description
Number of Outputs Number of CAN outputs. It can have up to 8 outputs.
Use Extension ID If this is set to Yes, the ID of a message is a 29-bit integer. If this is set to No, the ID
of a message is a 11-bit integer.
Message ID The ID of a message. It is an integer, for example, 0x23.
Trigger Type The trigger type can be one of the following:
- No trigger: No triggering
- Rising edge: Triggering occurs at the rising edge of the trigger source.
- Falling edge: Triggering occurs at the falling edge of the trigger source.
- Rising/falling edge: Triggering occurs at both the rising edge and the falling
edge of the trigger source.
A rising/falling edge is considered to have occurred if the difference between the
current value of the trigger source and the value at the last triggering instant is
equal to or greater than 1.
Trigger Source A trigger source can be either a constant of a global variable depending on the
Trigger Type.
If the Trigger Type is set to "No trigger", the trigger source defines the counter
limit. For example, if the trigger source is a constant or a global value, and the
value is 5, it means that triggering will occur once out of every 5 times. In another
word, the data will be sent out once per every 5 cycles.
If the Trigger Type is set to edge trigger, the trigger source can only be a global
variable. Triggering will occur when the global variable has the rising or falling
edge or both depending on the Trigger Type.
Outputi Gain The gain to the ith output where i can be 1 to 8. The output is the output multiplied
by the gain.
Outputi Data Start A message can have up to 8 data points. A data point can have 1 bit up to 32 bits.
Position This defines the start position of the current data point in the message.
Outputi Data End This defines the end position of the current data point in the message.
Position
Outputi Data Type The data type can be either Float, Integer, or IQ1 to IQ30.
Outputi Default Data The initial value of the SCI output variable.
Attributes:
Parameters Description
Time Output Method Define how interrupt time is measured. It can be one of the following:
- SCI (time used): Using SCI. Time used by the interrupt service routine, in
DSP clock count, is measured and is sent out via SCI output.
- SCI (time remaining): Using SCI. Time remaining in the interrupt service
routine, in DSP clock count, is measured and is send out via SCI output. The
time remaining is defined as the time from the end of the current interrupt to
the beginning of the next interrupt.
- GPIO0 to GPIO44 or AIO2 to AIO14: Using a GPIO port. A pulse is generated
at the specified GPIO port. The pulse is set to high when entering the interrupt,
and set to low when exiting the interrupt. An oscilloscope can be used to
measure the width of the pulse.
Sampling Frequency Sampling frequency of the interrupt service routine, in Hz.
When SCI is used, the value is the count of the DSP clock. For example, if the value is 6000, for a 60-MHz DSP
clock, the interrupt time will be: 6000 / 60M = 100 us.
Memory Allocation:
In the generated link files, the memory allocation is defined in the following way.
With the RAM Debug, RAM Release, and Flash RAM Release settings:
RAM Memory
0x0000 - 0x07FF (2K)
interrupt vectors
stack
0x8000 - 0x9FFF (8K*)
program and data space
Notes:
* The RAM memory predefined by SimCoder for program and data space is:
- For F28035, F28034, F28032, and F28032: from 0x8000 to 0x9FFF (8K)
- For F28031: from 0x8000 to 0x97FF (6K)
- For F28030: from 0x8000 to 0x8FFF (4K)
- If the combined program and data space exceeds the size of the RAM space, Flash Release must be
selected as the project setting.
** The flash memory predefined by SimCoder for program space is:
- For F28035 and F28034: from 0x3E8000 to 0x3F7FFF (64K)
- For F28033, F28032, and F28031: from 0x3F0000 to 0x3F7FFF (32K)
- For F28030: from 0x3F4000 to 0x3F7FFF (16K)
8.1 Overview
With the F2806x Hardware Target, SimCoder can generate code that is ready to run on any hardware boards
based on Texas Instruments’ F2806x fixed-point DSP.
The F2806x Hardware Target will work with all F2806x packages.
The F2806x Hardware Target library includes the following function blocks:
- PWM generators: 3-phase, 2-phase, 1-phase, and APWM
- Variable frequency PWM
- Start/Stop functions for PWM generators
- Trip-one and trip-zone state
- A/D converter
- Comparator input, output, and DAC
- Digital input and output
- Up/Down counter
- Encoder and encoder state
- Capture and capture state
- SCI configuration, Input, and output
- SPI configuration, device, input, and output
- CAN configuration, input, and output
- Interrupt Time
- DSP clock
- Hardware configuration
When generating the code for a system that has multiple sampling rates, SimCoder will use the interrupts of the
PWM generators for the PWM sampling rates. For other sampling rates in the control system, it will use the
Timer 1 interrupt first, and then Timer 2 interrupt if needed, If there are more than three sampling rates in the
control system, the corresponding interrupt routines will be handled in the main program by software.
In TI F2806x, PWM generators can generate hardware interrupt. SimCoder will search and group all the
elements that are connected to the PWM generator and have the same sampling rate as the PWM generator.
These elements will be automatically placed and implemented in an interrupt service routine in the generated
code.
In addition, digital input, encoder, capture, and trip-zone can also generate hardware interrupt. Each hardware
interrupt must be associated with an interrupt block (described in Section 4.5 of this Manual), and each interrupt
block must be associated with an interrupt service routine (a subcircuit that represents the interrupt service
routine). For example, if a PWM generator and a digital input both generate interrupt, there should be one
interrupt block and one interrupt service routine for each of them.
The definitions of the elements in the F2806x Hardware Target library are described in this Chapter.
The figure below shows the F2806x 100-pin PZ port assignment.
Image:
Hardware Hardware
Config
(100-pin)
F2806x F2806x
The Hardware Configuration block is for user to specify the I/O ports of the F2806x hardware. Every port to be
used must be assigned correctly. The ports not in use can be left unchecked.
For each GPIO port, a check box is provided for each of its available function. When a box is checked, the
GPIO port is configured for that particular function. For example, if the checkbox for "Digital Input" is checked
for port GPIO1, this port is configured as a digital input, and hence, cannot be used for any other functions. If it
is used as a PWM output in the PSIM circuit schematic, an error message will be generated.
Image:
DSP
Clock
F2806x
Parameters Description
DSP Clock Source There are five ways of providing system clock to F2806x. They are as follows:
- Internal oscillator 1
- Internal oscillator 2
- External oscillator
- External clock (GPIO19)
- External clock (GPIO38)
External Clock (MHz) Frequency of the external clock on the DSP board, in MHz. The frequency must be
an integer, and the maximum frequency allowed is 10 MHz. This parameter is
ignored if the DSP clock source is selected to be internal oscillator 1 or 2.
DSP Speed (MHz) DSP Speed, in MHz. The speed must be an integer, and must be an integer
multiple of the external clock frequency, from 1 to 12 times. The maximum DSP
speed allowed is 90 MHz.
If a DSP Configuration block is not used in a circuit, the default values of the DSP Configuration block will be
used.
Image:
u up
un
v vp
vn
w wp
wn
Attributes:
Parameters Description
PWM Source Source of the PWM generator. It can be either "3-phase PWM 123" that uses PWM
1 to 3, or "3-phase PWM 456" that uses PWM 4 to 6.
Dead Time The dead time Td for the PWM generator, in sec.
Sampling Frequency Sampling frequency of the PWM generator, in Hz. The calculation is done and the
PWM signal duty cycle is updated based on this frequency.
PWM Freq. Scaling The ratio between the PWM switching frequency and the sampling frequency. It
Factor can be from 1 to 100. For example, if the sampling frequency is 50 kHz and the
scaling factor is 3, the PWM switching frequency will be 150 kHz. That is
switches will operate at 150 kHz. But gating signals will be updated at 50 kHz, or
once per 3 switching cycles.
Carrier Wave Type Carrier wave type and the initial PWM output state. It can be one of the following:
- Triangular (start low): Triangular wave, and the initial PWM output state is low.
- Triangular (start high): Triangular wave, and the initial output state is high.
- Sawtooth (start low): Sawtooth wave, and the initial output state is low.
- Sawtooth (start high): Sawtooth wave, with the initial output state is high.
Trigger ADC Setting whether for the PWM generator to trigger the A/D converter. It can be one
of the following:
- Do not trigger ADC: PWM does not trigger the A/D converter.
- Trigger ADC: PWM will trigger A/D converter.
ADC Trigger Position A/D trigger position ranges from 0 to a value less than 1. When it is 0, the A/D
converter is triggered at the beginning of the PWM cycle, and when it is 0.5, the A/
D converter is triggered at the 180o position of the PWM cycle.
A in A
B phase B
Attributes:
Parameters Description
PWM Source Source of the PWM generator. Without phase shift, it can be PWM 1 to PWM 8.
With phase shift, it can be PWM 2 to PWM 8.
Output Mode Output mode of the PWM generator. It can be one of the following:
- Use PWM A&B: Both PWM outputs A and B are used, and they are
complementary.
- Use PWM A: Only PWM output A is used.
- Use PWM B: Only PWM output B is used.
Dead Time Dead time Td for the PWM generator, in sec.
Sampling Frequency Sampling frequency of the PWM generator, in Hz. The calculation is done and the
PWM signal duty cycle is updated based on this frequency.
PWM Freq. Scaling The ratio between the PWM switching frequency and the sampling frequency. It
Factor can be from 1 to 100. For example, if the sampling frequency is 50 kHz and the
scaling factor is 3, the PWM switching frequency will be 150 kHz. That is
switches will operate at 150 kHz. But gating signals will be updated at 50 kHz, or
once per 3 switching cycles.
Carrier Wave Type Carrier wave type and the initial PWM output state. It can be one of the following:
- Triangular (start low): Triangular wave, and the initial PWM output state is
low.
- Triangular (start high): Triangular wave, and the initial output state is high.
- Sawtooth (start low): Sawtooth wave, and the initial output state is low.
- Sawtooth (start high): Sawtooth wave, and the initial output state is high.
Trigger ADC Setting whether for the PWM generator to trigger the A/D converter. It can be one
of the following:
- Do not trigger ADC: PWM does not trigger the A/D converter.
- Trigger ADC Group A: PWM will trigger Group A of the A/D converter.
- Trigger ADC Group B: PWM will trigger Group B of the A/D converter.
- Trigger ADC Group A&B: PWM will trigger both Group A and B of the A/D
converter.
ADC Trigger Position A/D trigger position ranges from 0 to a value less than 1. When it is 0, the A/D
converter is triggered at the beginning of the PWM cycle, and when it is 0.5, the A/
D converter is triggered at the 180o position of the PWM cycle.
Use Trip-Zone i Define whether the PWM generator uses the ith trip-zone signal or not, where i
ranges from 1 to 6. It can be one of the following:
- Disable Trip-Zone i: Disable the ith trip-zone signal.
- One shot: The PWM generator uses the trip-zone signal in the one-shot mode.
Once triggered, the PWM must be started manually.
- Cycle by cycle: The PWM generator uses the trip-zone signal in the cycle-by-
cycle basis. The trip-zone signal is effective within the current cycle, and PWM
will automatically re-start in the next cycle.
Phase Shift
A 1-phase PWM generator can generate PWM signal that is phase shifted with respect to another PWM signal.
The way how PWM blocks are defined for phase shift is explained in Section 8.4.5.
The phase shift value is in degrees. When the value is -30o, the output will be shifted to the right (lagging) by
30o of the switching cycle with respect to the reference PWM generator output. This is equivalent to shifting the
Carrier Wave
There are two types of carrier waveforms: triangular wave (with equal rising and falling slope intervals) and
sawtooth wave. In addition, there are two operation modes: start-low and start-high modes, as explained below.
The input and output waveforms of a PWM generator with the triangular carrier wave are shown below:
PWM Vpp H m L
input vm Vpp
VL
VVoffset
L
Voffset t t
Td PWMxA PWMxA
x = 1, 2, ..., 6
Td PWMxB PWMxB
The input and output waveforms of a PWM generator with the sawtooth carrier wave are shown below:
PWM Vpp H m L
input vm Vpp
VL VL
Voffset t t
Td Voffset
PWMxA PWMxA
x = 1, 2, ..., 6
Td PWMxB
PWMxB
The figures above show how the dead time is defined, and the time sequence when the PWM generator triggers
the A/D converter. If triggering the A/D converter is selected, from the start of the PWM cycle, after a certain
delay defined by the A/D trigger position, the A/D conversion will start. After the A/D conversion is completed,
the PWM interrupt service routine will start.
If the PWM generator does not trigger the A/D converter, the PWM interrupt service routine will start at the
beginning of the PWM cycle.
Conditioning circuit
Note: In the start-low mode, the PWM input vm is converted to VH-(vm-VL) internally before it is compared with
the carrier wave to generate the PWM signal. With the conversion, both the start-low and start-high modes will
have the same duty cycle expression. For example, for a sawtooth wave with VL=0 and VH=1, or for a triangular
wave with VL= -VH, the duty cycle D of the PWMA output in both the start-low and start-high modes is:
D = vm/VH.
Image:
A A
B B
Parameters Description
PWM Source Source of the PWM generator. It can be PWM 1 to PWM 8.
Mode Type Operation mode of the PWM generation. It can be one of the 6 modes. The
waveforms of the 6 operation modes are described below.
Sampling Frequency Sampling frequency of the PWM generator, in Hz. The calculation is done and the
PWM signal duty cycle is updated based on this frequency.
PWM Freq. Scaling The ratio between the PWM switching frequency and the sampling frequency. It
Factor can be from 1 to 100. For example, if the sampling frequency is 50 kHz and the
scaling factor is 3, the PWM switching frequency will be 150 kHz. That is
switches will operate at 150 kHz. But gating signals will be updated at 50 kHz, or
once per 3 switching cycles.
Trigger ADC Setting whether for the PWM generator to trigger the A/D converter. It can be one
of the following:
- Do not trigger ADC: PWM does not trigger the A/D converter.
- Trigger ADC Group A: PWM will trigger Group A of the A/D converter.
- Trigger ADC Group B: PWM will trigger Group B of the A/D converter.
- Trigger ADC Group A&B: PWM will trigger both Group A and B of the A/D
converter.
ADC Trigger Position A/D trigger position ranges from 0 to a value less than 1. When it is 0, the A/D
converter is triggered at the beginning of the PWM cycle, and when it is 0.5, the A/
D converter is triggered at the 180o position of the PWM cycle.
Use Trip-Zone i Define whether the PWM generator uses the ith trip-zone signal or not, where i
ranges from 1 to 6. It can be one of the following:
- Disable Trip-Zone i: Disable the ith trip-zone signal.
- One shot: The PWM generator uses the trip-zone signal in the one-shot
mode. Once triggered, the PWM must be started manually.
- Cycle by cycle: The PWM generator uses the trip-zone signal in the cycle-by-
cycle basis. The trip-zone signal is effective within the current cycle, and PWM
will automatically re-start in the next cycle.
PWMA DC Trip Digital compare (DC) trip source DCAH for PWMA. The PWM channel may have
Src1(DCAH) up to two DC trip sources: DCAH and DCAL. The trip source can be one of the
following:
- Do not use: PWM doesn't use this signal.
- Trip-zone 1: PWM uses trip-zone 1 as digital compare input signal.
- Trip-zone 2: PWM uses trip-zone 2 as digital compare input signal.
- Trip-zone 3: PWM uses trip-zone 3 as digital compare input signal.
- Comparator 1: PWM uses Comparator 1 as digital compare input signal.
- Comparator 2: PWM uses Comparator 2 as digital compare input signal.
- Comparator 3: PWM uses Comparator 3 as digital compare input signal.
PWMA DC Trip Digital compare (DC) trip source DCAL for PWMA. The trip source can be one of
Src1(DCAL) the following:
- Do not use: PWM doesn't use this signal.
- Trip-zone 1: PWM uses trip-zone 1 as digital compare input signal.
- Trip-zone 2: PWM uses trip-zone 2 as digital compare input signal.
- Trip-zone 3: PWM uses trip-zone 3 as digital compare input signal.
- Comparator 1: PWM uses Comparator 1 as digital compare input signal.
- Comparator 2: PWM uses Comparator 2 as digital compare input signal.
- Comparator 3: PWM uses Comparator 3 as digital compare input signal.
Operation Mode 1:
The figure below on the left shows the waveforms of Mode 1. In the figure, "CA" and "CB" refer to two inputs
A and B of the 2-phase PWM generator. Each input controls the turn-off time of each output.
Operation Mode 2:
The figure below on the right shows the waveforms of Mode 2. Unlike in Mode 1, each input controls the turn-
on time of each output.
0 t t
CB CA CB CA CB CA CB CA
PWMxA PWMxA
PWMxB PWMxB
Operation Mode 3:
The figure below on the left shows the waveforms of Mode 3. Input A controls the turn-on and Input B controls
the turn-off of the PWM output A. The PWM output B is on for one complete PWM cycle, and is off for the
next cycle.
Operation Mode 4:
The figure below on the right shows the waveforms of Mode 4. The carrier wave is triangular. Each input
controls both the turn-on and turn-off of its output.
Mode 3: Mode 4:
t CA CA CA CA t
CA CB CA CB CB CB CB CB
PWMxA PWMxA
PWMxB PWMxB
Operation Mode 5:
The figure below on the left shows the waveforms of Mode 5. The carrier wave is triangular. Similar to Mode 4,
each input controls both the turn-on and turn-off of its output. Note that PWM output B is inverted in this case.
Operation Mode 6:
The figure below on the right shows the waveforms of Mode 6. In this mode, Input A controls the turn-on and
Input B controls the turn-off of PWM output A. The PWM output B is on for the first half PWM cycle, and is
off for the second half cycle.
Mode 5: Mode 6:
t CA CB CA CB t
CA CA CA CA
CB CB CB CB
PWMxA PWMxA
PWMxB PWMxB
Image:
Attributes:
Parameters Description
PWM Source Source of the PWM generator. It can be from one of the following:
- APWM 1 (GPIO 5, 11, 19, and 24)
- APWM 2 (GPIO 7, 15, and 25)
- APWM 3 (GIPIO 9 and 26)
PWM Frequency Frequency of the PWM generator, in Hz
Carrier Wave Type The carrier wave type and the initial PWM output state. It can be one of the
following:
- Sawtooth (start low): Sawtooth wave, with the PWM output in the low state
initially.
- Sawtooth (start high): Sawtooth wave, with the PWM output in the high state
initially.
Stop Action The output status when the PWM generator is stopped. It can be one of the
following:
- Output low: The PWM output will be set to low.
- Output high: The PWM output will be set to high.
Peak-to-Peak Value Peak-to-peak value of the carrier wave
Offset Value DC offset value of the carrier wave
Phase Shift Phase shift of the output with respect to the reference PWM generator, in deg.
Initial Input Value Initial value of the input
Start PWM at When it is set to Start, PWM will start right from the beginning. If it is set to Do
Beginning not start, one needs to start PWM using the Start PWM block.
Similar to 1-phase PWM generators, an APWM generator can generate a PWM signal that has a phase shift
with respect to another PWM generator. The way how PWM blocks are defined for phase shift is explained in
Section 8.4.5.
Image:
Variable
Freq
F2806x
Attributes:
Parameters Description
PWM Source Source of the PWM generator. It can be one of the following:
PWM 1, PWM 2, PWM 3, PWM 4, PWM 5, PWM 6, 3-phase PWM 123, and 3-
phase PWM 456.
Adjust Interrupt Pos. Specify if the interrupt position is adjusted with the frequency. It can be one of the
following:
- Do not adjust: The interrupt position will remain unchanged as calculated with
the base frequency.
- Adjust: The interrupt position will be recalculated at the beginning of
each cycle based on the new frequency.
Adjust Ramp Specify if the ramp compensation of the comparator DAC block is adjusted with
Compensation the frequency. It can be one of the following:
- Do not adjust: The ramp compensation will remain unchanged as calculated
with the base frequency.
- Adjust: The ramp compensation will be recalculated at the beginning of
each cycle based on the new frequency.
The sampling frequency of the corresponding PWM block will be changed at the beginning of the next PWM
period as follows:
PWM_Frequency = PWM_Base Frequency / Input_Value
Image:
Attributes:
Parameters Description
PWM Source The source of the PWM generator. It can be: PWM 1-7, 3-phase PWM 123 and
PWM 456, and Capture 1.
Image:
TZ1
TZ2
TZ3
Parameters Description
Use Trip-Zone i Specify if the ith trip-zone is used.
GPIO Port for Trip-Zone i Specify a designated GPIO port as the ith trip-zone input signal. It can be one
of the following:
- For trip-zone 1: GPIO12 or 13
- For trip-zone 2: GPIO13, 16, or 18
- For trip-zone 3: GPIO14, 17, or 19
Use Comparator i Specify if the ith comparator is used as the trip-zone input signal
Parameters Description
PWM Source Source of the PWM generator. It can be: PWM 1-7, 3-phase PWM 123, and
PWM 456.
The trip-zone interrupt can be generated in either one-shot mode of cycle-by-cycle mode, as defined in the
PWM generator parameter input. In the cycle-by-cycle mode, the interrupt only affects the PWM output within
the current PWM cycle. On the other hand, in the one-shot mode, interrupt triggers a trip action when the input
signal is low (0). will set the PWM output permanently, and the PWM generator must be restarted to resume the
operation.
The Trip-Zone State element indicates whether the trip-zone signal is in one-shot mode or cycle-by-cycle mode
when it triggers a PWM generator to generate an interrupt. When the output is 1, it means that the trip-zone
signal is in one-shot mode. When the output is 0, the trip-zone signal is in cycle-by-cycle mode.
Note that when defining the interrupt block associate with trip-zone, the "Device Name" parameter of the
interrupt block should be the name of the PWM generator, not the trip-zone block name. For example, if a
PWM generator called "PWM_G1" uses trip-zone 1 in the trip-zone block "TZ1". The "Device Name" of the
corresponding interrupt block should be "PWM_G1", not "TZ1". The "Channel Number" parameter in the
interrupt block is not used in this case.
As shown above, the A/D converter element in SimCoder is not exactly the same as the physical A/D converter
on the DSP. Rather, it combines the functions of an offset circuit, the DSP A/D converter, and a scaling block.
This is designed for the convenience of AC system applications. It will be further explained in Section 6.5.3.
In many applications, the circuit variables to be monitored are AC signals, especially in AC motor drive
systems. For each of this kind of AC signals, an offset circuit must be built in the hardware on circuit board at
Image:
ADC
D0
D1
D2
D3
D4
D5
D6
D7
D8
D9
D10
D11
D12
D13
D14
D15
F2806x
Attributes:
Parameters Description
Ch Ai or Bi Mode Input mode of the ith A/D converter channel Ai or Bi. The input mode can be one of
the following:
- AC: This option is for simulation only, not for code generation. The input
range is considered from -1.65V to +1.65V. This option includes the offset
circuit into the A/D converter. It provides the convenience in cases where an
external level shifter is needed to shift the AC signal to the 0 to +3.3V range.
- DC: The input is a dc value, and the range is from 0 to +3.3V.
Ch Ai or Bi Gain Gain k of the ith A/D converter channel Ai or Bi.
Conversion Order Order of the A/D conversion. If the field is left blank (undefined), the conversion
will be done based on the serial numbers of the A/D channel. For example, if A0,
A2, A4, B1, and B3 are used, the conversion will be done in this order: A0, A2,
A4, B1, and B3. If you wish certain channels to be performed first, you can define
the order here. For example, if the conversion order is defined as:
A4,A0,A2,B3,B2
The conversion will be done in the order defined, that is, A4 before A0, and A0
before A2, and so on.
ADCINT1 PIE Specify if interrupt ADCINT1 uses PIE Group1 or PIE Group10.
Selection
ADCINT2 PIE Specify if interrupt ADCINT2 uses PIE Group1 or PIE Group10.
Selection
An A/D converter has up to 16 channels. SimCoder divides them into groups according their sampling rates.
The group with the highest sampling rate uses interrupt ADCINT1, and the group with the second highest
Gain = 45.4545
150 Vdc_max Input Mode = DC
0.01
2.2
100 Vdc 100 Vdc
DC Signal Input
0 V -> +3.3 V
Please note that, in this example, if the gain of the proportional block is changed from 2.2 to 1.1, and the A/D
gain is changed from 45.4545 to 90.909, the simulation results will be the same. But the generated hardware
code will not be correct. This is because the hardware code assumes that the maximum input value is scaled to
+3.3V, but in this case it is only +1.5V. Therefore, one must set up the circuit such that, in the dc mode, the
maximum input value is scaled to be +3.3V.
In another example, assume that a power circuit voltage is an ac quantity, and the range is as follows:
Vi_max = +/- 75 V
The input mode of the A/D converter will be set to ac, and the input range is from -1.65V to +1.65V. Assume
that the actual value of the voltage has a peak value of:
Vi = +/- 50 V
Let the voltage sensor gain be 0.01. After the voltage sensor, the maximum value and the actual value of the
input become:
Vi_max_s = +/- 0.75 V
Vi_s = +/- 0.5 V
Since the A/D converter input range is from -1.65V to +1.65V, this signal must be scaled before it is sent to the
DSP. A conditioning circuit with a gain of 2.2 is needed (i.e. 1.65/0.75 = 2.2). After the conditioning circuit and
at the input of the DSP A/D converter, the maximum value and the actual value of the input become:
Vi_max_s_c = +/- 1.65 V
Vi_s_c = +/- 1.1 V
The scaling block after the DSP A/D can be selected such that the original power circuit quantity is restored. In
this example, a gain of 45.4545 will be used. Note that this is the reciprocal of the combined gain of the voltage
sensor and the conditioning circuit. At the A/D output, the maximum value and the actual value are:
Vo_max = +/- 75 V
Vo = +/- 50 V
The gain of the A/D channel in PSIM will be set to 45.4545. The circuit connection and the settings are shown
in the figure below.
AC Signal Input
-1.65 V -> +1.65 V
Notice that in this circuit, the ac signal is sent to the A/D converter directly. This is because that, when the A/D
input mode is set to AC, the input range is from -1.65V and +1.65V, and the function of the conditioning circuit
that performs the dc offset is already included in the A/D converter block. In the actual hardware circuit, the ac
signal must be scaled and offset so that the range is within 0V to +3.3V required by the A/D converter.
8.9 Comparator
F2806x supports three comparator modules. Each comparator block can have two external analog inputs, or one
external analog input and one internal DAC reference for the other input. The comparator output can be sent to
the PWM trip-zone and to the GPIO output.
Image:
A1 out1
B1
A2 out2
B2
A3 out3
B3
Parameters Description
Comparator i Define how the output of the ith comparator is used. It can be one of the
following:
- Do not use: Not used
- As a normal comparator: Used as a normal comparator
- As a Trip-Zone signal: Used as a trip-zone signal
Output Logic Define the comparator output logic. It can be:
- High when A > B: The output is high when Input A is greater than B.
- High when A < B: The output is high when Input A is less than B.
Compare Method Define how Input A of the comparator is compared to Input B. it can be
one of the following:
- Compare to Input B: Input A is compared to Input B where Input
B is an external analog signal.
- Compare to Constant Value: Input A is compared to a constant value.
- Compare to DAC output: Input A is compared to a DAC output
which is an internal signal.
Constant Value The constant value when Compare Method is defined as Compare to
Constant Value. The range of the constant value is from 0 to 3.3V.
For all comparators, Input A is always from an external analog input. If Input B is also from another external
analog input (if the parameter Compare Method is defined as Compare to Input B), the corresponding port must
be defined as a comparator input in the Hardware Configuration block.
If the compare method is to compare to a constant value, Input B needs to be connected to ground in the
schematic. If the compare method is to compare to a DAC output, Input B needs to be connected a comparator
DAC output. In both cases, the corresponding ADC/AIO port can be used for other functions.
Image:
out1
out2
out3
Attributes:
Parameters Description
Comparator i Output Output port position of the ith comparator. It can be:
- For Comparator A: GPIO1, 20, or 42
- For Comparator B: GPIO3, 21, 34, or 43
- For Comparator C: GPIO34
A comparator output block must be used together with a comparator input block. When a comparator outupt
channel is used, the corresponding comparator input channel must be defined.
in1 out1
in2 out2
in3 out3
Attributes:
Parameters Description
DAC i Range The upper limit of the input signal range of the ith comparator DAC. The lower
limit is 0.
Use Ramp Generator Define if the ramp generator is used in the comparator DAC.
Total Ramp The total compensation of the ramp generator in one PWM period. It represents the
Compensation total decrease of the ramp in one cycle.
Outputs of the comparator DAC can only be connected to the corresponding inverting inputs (Input B) of the
comparator in a comparator input block. That is, node out1 can only be connected to node B1 of the comparator
input block, and node out2 to node B2, and node out3 to B3. Also, a comparator DAC block cannot be used
alone. It must be used in conjunction with a comparator input block.
If the ramp generator is not used, the input value is applied directly to DAC output immediately. The output
range is from 0 to 3.3V, and the output can be calculated as follows:
DAC Output = DAC Input * 3.3 / DAC Range
If the ramp generator is used, the input value is saved and used as the initial output value in the next PWM
period. The comparator DAC output decreases linearly within the PWM period, and the total decrease is equal
to the total ramp compensation value.
When the ramp generator is used, the sampling rate associated with the comparator DAC input must be the
same as the frequency of the PWM generator that uses the comparator.
Image:
DIN
D0 D0 D0 D0
D1 D1 D1 D1
D2 D2 D2 D2
D3 D3 D3 D3
D4 D4 D4 D4
D5 D5 D5 D5
D6 D6 D6 D6
D7 D7 D7 D7
F2806x
Parameters Description
Port Position for Input i The port position of the Input i, where i is from 0 to 7. It can be one of the
45 GPIO ports or one of the 6 AIO ports.
Use as External Interrupt Indicate if this port is used as an external interrupt input.
Parameters Description
Port Position for Output i The port position of the Output i, where i is from 0 to 7. It can be one of
the 45 GPIO ports or one of the 6 AIO ports.
Note that each GPIO and AIO port can be used for one function only. If an IO port is used as a digital input port,
it can not be used as a digital output or any other peripheral port. For example, if Port GPIO1 is assigned as
digital input and it is also used as PWM1 output, an error will be reported.
F2806x supports 3 masked external interrupts (XINT1 to XINT3). There are no dedicated pins for the external
interrupts. XINT1, XINT2, and XINT3 interrupts can accept inputs from GPIO0 to GPIO31 pins.
Image:
Clk Cnt
Dir
Attributes:
In the image, "Clk" refers to the input clock signal, and "Dir" refers to the signal that defines the counting
direction. When the "Dir" input is 1, the counter counts forward, and when the input is 0, the counter counts
backward.
The output of the up/down counter gives the counter value.
Note that the up/down counter uses the same resource as the encoder, and the same GPIO ports cannot be used
in a counter and in an encoder at the same time. For example, using both Encoder 1 and Up/Down Counter 1
will cause conflict and is not allowed.
Images:
Index Pos
A Encoder Cnt
B
Cn F2806x
t Z
Strobe
Parameters Description
Use Z Signal Define if the encoder uses the Z (or index) signal.
Use Strobe Signal Define if the encoder uses the strobe signal.
Counting Direction The counting direction
- Forward: the encoder counts up.
- Reverse: the encoder counts down.
Z Signal Polarity Define the trigger polarity of Z signal.
- Active High
- Active Low.
Strobe Signal Polarity Define the trigger polarity of strobe signal.
- Active High
- Active Low.
Encoder Resolution The resolution of the external encoder hardware. If it is 0, the encoder counter will
keep on counting and will not reset. If for example, the resolution is set to 4096,
the counter will be reset to 0 after it reaches 4095.
Parameters Description
Latch Position Specify the kept counter type, choose from the followings:
- IndexPos, if the setting "Use Z Signal" is not "No" in Encoder
- StrobePos, if the setting "Use Strobe Signal" is not "No" in Encoder
Type of Position This can be chosen from the followings:
- The first latched position, or
- The current latched position
Image:
Parameters Description
Capture Source Source of the capture may come from one of 3 GPIO ports, as listed below:
- Capture 1 (GPIO5)
- Capture 1 (GPIO19)
- Capture 1 (GPIO24)
Event Filter Prescale Event filter prescale. The input signal is divided by the selected prescale.
Timer Mode Capture counter timer mode. It can be either Absolute time or Time difference.
Parameters Description
Capture Source Source of the capture. It has only one source Capture1.
The Capture State block output is either 1 or 0, where 1 means the rising edge and 0 means the falling edge.
Image:
SCI
Config
F2806x
Attributes:
Parameters Description
SCI Port Define the SCI port. Different sets of GPIO ports can be used for SCI, as listed
below:
- SCIA: GPIO28 and 7 in combination with GPIO29 and 12
- SCIB: GPIO11, 15, 19, 23, 41, and 44 in combination with GPIO9, 14, 18, 22,
40, and 58
Speed (bps) SCI communication speed, in bps (bits per second). A list of preset speeds is
provided at 200000, 115200, 57600, 38400, 19200, or 9600 bps. Or one can
specify any other speed manually.
Image:
in
Attributes:
Parameters Description
Initial Value The initial value of the SCI input variable.
In the schematic, the SCI input behaviors as a constant. While its value can be changed at runtime when the
code is running on the DSP, the value will be fixed at the initial value in the simulation.
Image:
out
Attributes:
Parameters Description
Data Point Step It defines how frequent data is collected. If the Data Point Step is 1, every data
point is collected and transmitted. If the Data Point Step is 10, for example, only
one point of out every 10 points is collected and transmitted.
Image:
CS0
CS1
CS2
CS3
Attributes:
Parameters Description
SPI Port Define the SPI port from the options:
- SPIA (GPIO 16-19)
- SPIA (GPIO 3, 5, 18, 19)
- SPIB (GPIO 12-15)
- SPIB (GPIO 24-27)
Chip Select Pin0, 1, 2, The GPIO port of the chip select pin. PSIM supports up to 16 SPI devices, which
and 3 requires four GPIO pins for chip select, as defined by Chip Select Pin0 to Pin3.
These GPIO ports and the SPI slave transmit-enable pin SPISTE are used to
generate the chip select signal.
SPI Buffer Size The buffer size of the SPI commands. Each memory cell of the buffer saves the
index of a SPI command. Normally, one can specify the buffer size as 1 plus the
number of SPI commands (i.e. Start Conversion Command, Receiving Data
Command, Sending Data Command, and Sync. Command) in all SPI Input/Output
elements.
Image:
CS0
CS1
CS2 Intr
CS3
Sync
Attributes:
Parameters Description
Chip Select Pins The state of the chip select pins corresponding to the SPI device. When the chip
select pins are at this state, this SPI device is selected.
Communication Speed SPI communication speed, in MHz.
(MHz)
Clock Type SPI clock type, as determined by the SPI hardware device. It can be one of the
following:
- Rising edge without delay: The clock is normally low, and data is latched at the
clock rising edge.
- Rising edge with delay: The clock is normally low, and data is latched at the
clock rising edge with delay.
- Falling edge without delay: The clock is normally high, and data is latched at
the clock falling edge.
- Falling edge with delay: The clock is normally high, and data is latched at the
clock falling edge with delay.
Command Word Word length, or the length of the significant bits, of SPI communication
Length commands. It can be from 1 to 16 bits.
Sync. Active Mode The triggering mode of the synchronization signal of the SPI device. It can be
either Rising edge or Falling edge.
SPI Initial Command The SPI command that initializes the SPI device.
Hardware Interrupt Specify the type of the interrupt signal that the SPI device generates. This is valid
Mode only when the SPI device’s interrupt output node is connected to the input of a
digital output element. It can be one of the following:
- No hardware interrupt
- Rising edge
- Falling edge
Image:
in
SPI
Attributes:
Parameters Description
Device Name Name of the SPI input device.
Data Bit Position Define where the data bits are in the receiving data string. The format is:
ElementName = {Xn[MSB..LSB]}
where
- ElementName is the name of the SPI input device. If it is the current SPI input
device, use y instead.
- {} means that the item in the bracket repeats multiple times.
- Xn is the nth word received from the SPI input device, and n start from 0.
- MSB..LSB defines the position of the significant bits in the word.
Input Range Specify the parameter Vmax that defines the input range. This parameter is valid
only when the SPI device is an A/D converter. If the device conversion mode is
DC, the input ranges from 0 to Vmax. If the device conversion mode is AC, the
input ranges from -Vmax/2 to Vmax/2.
Scale Factor Output scale factor Kscale. If the scale factor is 0, the SPI device is not an A/D
converter, and the result will be exactly the same as what DSP receives from SPI
communication. Otherwise, the SPI device is an A/D converter, and the result is
scaled based on this factor and the A/D conversion mode.
ADC Mode The A/D conversion mode of the device. It can be either DC or AC. Note that this
parameter is valid only when the device is an A/D converter.
Initial Value The initial value of the input.
The formula for the Data Bit Position defines the data length of a SPI input device. For example,
y=x1[3..0]x2[7..0], means that the data length is 12, and the result is the lower 4 bits of the 2nd word and the
lower 8 bits of the 3rd word. If the received data string is 0x12,0x78,0xAF, then the result is 0x8AF.
If the scale factor is not 0, the output will be scaled based on the following:
In the DC conversion mode:
- In simulation: Output = Input K scale
Data_Length
2
In the AC conversion mode:
) V max Ksc al e
- In hardware: Output = (Result – 2Data_Length-1 ------- ---------
-----------------------
The parameter Data_Length is calculated from the Data Bit Position formula.
Parameters Description
Device Name Name of the SPI output device.
Scale Factor Output scale factor Kscale. If the scale factor is 0, the SPI device is not a D/A
converter, and the result will be exactly the same as what DSP receives from SPI
communication. Otherwise, the SPI device is an D/A converter, and the result is
scaled based on this factor and the D/A conversion mode.
Output Range Specify the parameter Vmax that defines the output range. This parameter is valid
only when the SPI device is an D/A converter. If the device conversion mode is
DC, the input ranges from 0 to Vmax. If the device conversion mode is AC, the
input ranges from -Vmax/2 to Vmax/2.
DAC Mode The D/A conversion mode of the device. It can be either DC or AC. Note that this
parameter is valid only when the device is a D/A converter.
Sending Data Command to send the output data, in hex numbers, separated by comma (for
Command example, 0x23,0x43,0x00).
Data Bit Position Define where the data bits are in the sending data string. The format is:
ElementName = {Xn[MSB..LSB]}
where
- ElementName is the name of the SPI output device. If it is the current SPI
output device, use y instead.
- {} means that the item in the bracket repeats multiple times.
- Xn is the nth word sent to the SPI output device, and n start from 0.
- MSB..LSB defines the position of the significant bits in the word.
Sync. Command The command to synchronize output channels of the SPI output device, in hex
numbers, separated by comma (for example, 0x23,0x43,0x00). This command is
used when the SPI output device does not have the synchronization signal
The formula for the Data Bit Position defines the data length of a SPI output device. For example,
y=x1[3..0]x2[7..0], means that the data length is 12, and the data is the lower 4 bits of the 2nd word and the
lower 8 bits of the 3rd word. If the sending data string is 0x12,0x78,0xAF, then the data is 0x8AF.
If the scale factor is not 0, the output will be scaled based on the following:
In the DC conversion mode:
- In simulation: Output = Input K scale
V max
In the AC conversion mode:
--------------------------- -----------
V max
The parameter Data_Length is calculated from the Data Bit Position formula.
Image:
CAN
Config
F2806x
Attributes:
Parameters Description
CAN Speed Communication speed, in Hz. It can be set to one of the following preset values:
125kHz, 250kHz, 500kHz, and 1MHz
Or you can set the speed manually by typing the text in the parameter field. Note
that the speed should not exceed 1MHz.
Data Byte Order The order of the data bytes. It can be one of the following:
- Least significant byte 1st
- Most significant byte 1st
"Least significant byte 1st" means that the least significant byte is placed first;
while "Most significant byte 1st" means that the most significant byte is placed
first.
Number of Input Number of input mailboxes
Mailboxes
Checking Receive Mail If it is set to Enable, the error report function "_ProcCanAErrReport(nErr)" (for
Lost CAN A) will be called if the received mail is lost. This function will return the
value of the error status nErr from the CAN register CANGIF0.
If it is set to Disable, the error report function will not be called.
Checking Bus Off If it is set to Enable, the error report function "_ProcCanAErrReport(nErr)" (for
CAN A) will be called if the bus is in the off state. This function will return the
value of the error status nErr from the CAN register CANGIF0.
If it is set to Disable, the error report function will not be called.
Error Check Mode The error check mode can be either Passive or Active. If it is in the error-passive
mode, an interrupt will be generated when the error count reaches 128. If it is in
the error-active mode, an interrupt will be generated every time.
The returned status nErr in the function "_ProcCanAErrReport(nErr)" (for CAN A) is a 32-bit integer. It obtains
its value from the Global Interrupt Flag Register CANGIF0. After returning from the function "_ProcCanAE
rrReport(nErr)", the register CANGIF0 will be cleared.
Also, if you wish to take actions on a specific error, you can add your own code within the "_ProcCanAE
rrReport(nErr)" function.
Image:
CAN
In
Attributes:
Parameters Description
Number of Inputs Number of CAN inputs. It can have up to 8 inputs.
Use Extension ID If this is set to Yes, the ID of a message is a 29-bit integer. If this is set to No, the ID
of a message is a 11-bit integer.
Message ID The ID of a message. It is an integer, for example, 0x23.
Local Mask The mask for the message. It is an integer. If the bits of the message ID matches
the bits of the mask, the message will be received. Otherwise, it will be ignored.
For example, if the mask is 0x380 and the message ID is 0x389, this message will
be received. But if the message ID is 0x480, the message will be ignored.
Overwrite Flag It can be set to Allow overwrite or Do not allow overwrite.
Assume a mailbox is configured to accept a message, and there is a new message
coming from the CAN bus, while the old message is still in the mailbox and has
not been processed yet. If the flag is set to "Allow overwrite", the new message
will be accepted, and the old message will be overwritten. If the flag is set to "Do
not allow overwrite", the new message will not be accepted, and the old one will
be kept.
Receive Message Rate The number of messages received by the input block in a specific period of time.
For example, there are two input blocks, with the first input block receiving 20
messages per second, and the second input block receiving 30 messages per
second. The parameter "Receive Message Rate" will be set to 20 for the first block,
and 30 for the second block.
Inputi Gain The gain to the ith input where i can be 1 to 8. The output is the input multiplied by
the gain.
Inputi Data Start A message can have up to 8 data points. A data point can have 1 bit up to 32 bits.
Position This defines the start position of the current data point in the message.
Inputi Data End This defines the end position of the current data point in the message.
Position
Inputi Data Type The data type can be either Float, Integer, or IQ1 to IQ30.
Inputi Default Data The initial value of the SCI input variable.
Image:
CAN
Out
Attributes:
Parameters Description
Number of Outputs Number of CAN outputs. It can have up to 8 outputs.
CAN Source The CAN source can be either CAN A or CAN B.
Use Extension ID If this is set to Yes, the ID of a message is a 29-bit integer. If this is set to No, the ID
of a message is a 11-bit integer.
Message ID The ID of a message. It is an integer, for example, 0x23.
Trigger Type The trigger type can be one of the following:
- No trigger: No triggering
- Rising edge: Triggering occurs at the rising edge of the trigger source.
- Falling edge: Triggering occurs at the falling edge of the trigger source.
- Rising/falling edge: Triggering occurs at both the rising edge and the falling
edge of the trigger source.
A rising/falling edge is considered to have occurred if the difference between the
current value of the trigger source and the value at the last triggering instant is
equal to or greater than 1.
Trigger Source A trigger source can be either a constant of a global variable depending on the
Trigger Type.
If the Trigger Type is set to "No trigger", the trigger source defines the counter
limit. For example, if the trigger source is a constant or a global value, and the
value is 5, it means that triggering will occur once out of every 5 times. In another
word, the data will be sent out once per every 5 cycles.
If the Trigger Type is set to edge trigger, the trigger source can only be a global
variable. Triggering will occur when the global variable has the rising or falling
edge or both depending on the Trigger Type.
Outputi Gain The gain to the ith output where i can be 1 to 8. The output is the output multiplied
by the gain.
Outputi Data Start A message can have up to 8 data points. A data point can have 1 bit up to 32 bits.
Position This defines the start position of the current data point in the message.
Outputi Data End This defines the end position of the current data point in the message.
Position
Outputi Data Type The data type can be either Float, Integer, or IQ1 to IQ30.
Outputi Default Data The initial value of the SCI output variable.
Attributes:
Parameters Description
Time Output Method Define how interrupt time is measured. It can be one of the following:
- SCI (time used): Using SCI. Time used by the interrupt service routine, in
DSP clock count, is measured and is sent out via SCI output.
- SCI (time remaining): Using SCI. Time remaining in the interrupt service
routine, in DSP clock count, is measured and is send out via SCI output. The
time remaining is defined as the time from the end of the current interrupt to
the beginning of the next interrupt.
- GPIO0 to GPIO44, or AIO2 to AIO14: Using a GPIO port. A pulse is
generated at the specified GPIO port. The pulse is set to high when entering the
interrupt, and set to low when exiting the interrupt. An oscilloscope can be
used to measure the width of the pulse.
Sampling Frequency Sampling frequency of the interrupt service routine, in Hz.
When SCI is used, the value is the count of the DSP clock. For example, if the value is 6000, for a 60-MHz DSP
clock, the interrupt time will be: 6000 / 60M = 100 us.
Memory Allocation:
In the generated link files, the memory allocation is defined in the following way.
With the RAM Debug, RAM Release, and Flash RAM Release settings:
RAM Memory
0x0000 - 0x07FF (2K)
interrupt vectors
stack
0x8000 - 0x13FFF (96K*)
program and data space
Notes:
* The RAM memory predefined by SimCoder for program and data space is:
- For F28069, F28068, F28067, F28065, and F28064: from 0x8000 to 0x13FFF (96K)
- For F28066 and F28063: From 0x8000 to 0x0FFFF (64K)
- For F28062: From 0x8000 to 0x0DFFF (48K)
- If the combined program and data space exceeds the size of the RAM space, Flash Release must be
selected as the project setting.
** The flash memory predefined by SimCoder for program space is:
- For F28069, F28068, F28067, and F28066: From 0x3E8000 to 0x3F7FFF (256K)
- For F28065, F28064, F28063, and F28062: From 0x3E8000 to 0x3F7FFF (128K)
9.1 Overview
With the F2802x Hardware Target, SimCoder can generate code that is ready to run on any hardware boards
based on Texas Instruments’ F2802x fixed-point DSP.
The F2802x Hardware Target will work with all F2802x packages.
The F2802x Hardware Target library includes the following function blocks:
- PWM generators: 3-phase, 2-phase, 1-phase, and APWM
- Variable frequency PWM
- Start/Stop functions for PWM generators
- Trip-one and trip-zone state
- A/D converter
- Comparator input, output, and DAC
- Digital input and output
- Capture and capture state
- SCI configuration, Input, and output
- SPI configuration, device, input, and output
- CAN configuration, input, and output
- Interrupt Time
- DSP clock
- Hardware configuration
When generating the code for a system that has multiple sampling rates, SimCoder will use the interrupts of the
PWM generators for the PWM sampling rates. For other sampling rates in the control system, it will use the
Timer 1 interrupt first, and then Timer 2 interrupt if needed, If there are more than three sampling rates in the
control system, the corresponding interrupt routines will be handled in the main program by software.
In TI F2802x, PWM generators can generate hardware interrupt. SimCoder will search and group all the
elements that are connected to the PWM generator and have the same sampling rate as the PWM generator.
These elements will be automatically placed and implemented in an interrupt service routine in the generated
code.
In addition, digital input, encoder, capture, and trip-zone can also generate hardware interrupt. Each hardware
interrupt must be associated with an interrupt block (described in Section 4.5 of this Manual), and each interrupt
block must be associated with an interrupt service routine (a subcircuit that represents the interrupt service
routine). For example, if a PWM generator and a digital input both generate interrupt, there should be one
interrupt block and one interrupt service routine for each of them.
The definitions of the elements in the F2802x Hardware Target library are described in this Chapter.
The figure below shows the F2802x 48-pin PT LQFP port assignment.
Image:
Hardware Hardware
Config Config
(48-pin) (38-pin)
F2802x F2802x
The Hardware Configuration block is for user to specify the I/O ports of the F2802x hardware. Every port to be
used must be assigned correctly. The ports not in use can be left unchecked.
For each GPIO port, a check box is provided for each of its available function. When a box is checked, the
GPIO port is configured for that particular function. For example, if the checkbox for "Digital Input" is checked
for port GPIO1, this port is configured as a digital input, and hence, cannot be used for any other functions. If it
is used as a PWM output in the PSIM circuit schematic, an error message will be generated.
Image:
Parameters Description
DSP Clock Source There are five ways of providing system clock to F2802x. They are as follows:
- Internal oscillator 1
- Internal oscillator 2
- External oscillator
- External clock (GPIO19)
- External clock (GPIO38)
External Clock (MHz) Frequency of the external clock on the DSP board, in MHz. The frequency must be
an integer, and the maximum frequency allowed is 10 MHz. This parameter is
ignored if the DSP clock source is selected to be internal oscillator 1 or 2.
DSP Speed (MHz) DSP Speed, in MHz. The speed must be an integer, and must be an integer
multiple of the external clock frequency, from 1 to 12 times. The maximum DSP
speed allowed is 60 MHz.
If a DSP Configuration block is not used in a circuit, the default values of the DSP Configuration block will be
used.
Image:
u up
un
v vp
vn
w wp
wn
Attributes:
Parameters Description
PWM Source Source of the PWM generator. It can be "3-phase PWM 123" that uses PWM 1 to
3.
Dead Time The dead time Td for the PWM generator, in sec.
Sampling Frequency Sampling frequency of the PWM generator, in Hz. The calculation is done and the
PWM signal duty cycle is updated based on this frequency.
PWM Freq. Scaling The ratio between the PWM switching frequency and the sampling frequency. It
Factor can be from 1 to 100. For example, if the sampling frequency is 50 kHz and the
scaling factor is 3, the PWM switching frequency will be 150 kHz. That is
switches will operate at 150 kHz. But gating signals will be updated at 50 kHz, or
once per 3 switching cycles.
Carrier Wave Type Carrier wave type and the initial PWM output state. It can be one of the following:
- Triangular (start low): Triangular wave, and the initial PWM output state is low.
- Triangular (start high): Triangular wave, and the initial output state is high.
- Sawtooth (start low): Sawtooth wave, and the initial output state is low.
- Sawtooth (start high): Sawtooth wave, with the initial output state is high.
Trigger ADC Setting whether for the PWM generator to trigger the A/D converter. It can be one
of the following:
- Do not trigger ADC: PWM does not trigger the A/D converter.
- Trigger ADC: PWM will trigger A/D converter.
ADC Trigger Position A/D trigger position ranges from 0 to a value less than 1. When it is 0, the A/D
converter is triggered at the beginning of the PWM cycle, and when it is 0.5, the A/
D converter is triggered at the 180o position of the PWM cycle.
Use Trip-Zone i Define whether the PWM generator uses the ith trip-zone signal or not, where i
ranges from 1 to 6. It can be one of the following:
- Disable Trip-Zone i: Disable the ith trip-zone signal.
- One shot: The PWM generator uses the trip-zone signal in the one-
shot mode. Once triggered, the PWM must be started manually.
- Cycle by cycle: The PWM generator uses the trip-zone signal in the cycle-by-
cycle basis. The trip-zone signal is effective within the current cycle, and PWM
will automatically re-start in the next cycle.
Image:
1-Phase PWM 1-Phase PWM (phase shift)
A in A
B phase B
Parameters Description
PWM Source Source of the PWM generator. Without phase shift, it can be PWM 1 to PWM 4.
With phase shift, it can be PWM 2 to PWM 4.
Output Mode Output mode of the PWM generator. It can be one of the following:
- Use PWM A&B: Both PWM outputs A and B are used, and they are
complementary.
- Use PWM A: Only PWM output A is used.
- Use PWM B: Only PWM output B is used.
Dead Time Dead time Td for the PWM generator, in sec.
Sampling Frequency Sampling frequency of the PWM generator, in Hz. The calculation is done and the
PWM signal duty cycle is updated based on this frequency.
PWM Freq. Scaling The ratio between the PWM switching frequency and the sampling frequency. It
Factor can be from 1 to 100. For example, if the sampling frequency is 50 kHz and the
scaling factor is 3, the PWM switching frequency will be 150 kHz. That is
switches will operate at 150 kHz. But gating signals will be updated at 50 kHz, or
once per 3 switching cycles.
Carrier Wave Type Carrier wave type and the initial PWM output state. It can be one of the following:
- Triangular (start low): Triangular wave, and the initial PWM output state is
low.
- Triangular (start high): Triangular wave, and the initial output state is high.
- Sawtooth (start low): Sawtooth wave, and the initial output state is low.
- Sawtooth (start high): Sawtooth wave, and the initial output state is high.
Trigger ADC Setting whether for the PWM generator to trigger the A/D converter. It can be one
of the following:
- Do not trigger ADC: PWM does not trigger the A/D converter.
- Trigger ADC Group A: PWM will trigger Group A of the A/D converter.
- Trigger ADC Group B: PWM will trigger Group B of the A/D converter.
- Trigger ADC Group A&B: PWM will trigger both Group A and B of the A/D
converter.
ADC Trigger Position A/D trigger position ranges from 0 to a value less than 1. When it is 0, the A/D
converter is triggered at the beginning of the PWM cycle, and when it is 0.5, the A/
D converter is triggered at the 180o position of the PWM cycle.
Use Trip-Zone i Define whether the PWM generator uses the ith trip-zone signal or not, where i
ranges from 1 to 6. It can be one of the following:
- Disable Trip-Zone i: Disable the ith trip-zone signal.
- One shot: The PWM generator uses the trip-zone signal in the one-shot mode.
Once triggered, the PWM must be started manually.
- Cycle by cycle: The PWM generator uses the trip-zone signal in the cycle-by-
cycle basis. The trip-zone signal is effective within the current cycle, and PWM
will automatically re-start in the next cycle.
Phase Shift
A 1-phase PWM generator can generate PWM signal that is phase shifted with respect to another PWM signal.
The way how PWM blocks are defined for phase shift is explained in Section 9.4.5.
The phase shift value is in degrees. When the value is -30o, the output will be shifted to the right (lagging) by
30o of the switching cycle with respect to the reference PWM generator output. This is equivalent to shifting the
Carrier Wave
There are two types of carrier waveforms: triangular wave (with equal rising and falling slope intervals) and
sawtooth wave. In addition, there are two operation modes: start-low and start-high modes, as explained below.
The input and output waveforms of a PWM generator with the triangular carrier wave are shown below:
PWM H m L
Vpp
input vm Vpp
VL
VVoffset
L
Voffset t t
Td PWMxA PWMxA
x = 1, 2, ..., 6
Td PWMxB PWMxB
The input and output waveforms of a PWM generator with the sawtooth carrier wave are shown below:
PWM Vpp H m L
input vm Vpp
VL VL
Voffset t t
Td Voffset
PWMxA PWMxA
x = 1, 2, ..., 6
Td PWMxB
PWMxB
The figures above show how the dead time is defined, and the time sequence when the PWM generator triggers
the A/D converter. If triggering the A/D converter is selected, from the start of the PWM cycle, after a certain
delay defined by the A/D trigger position, the A/D conversion will start. After the A/D conversion is completed,
the PWM interrupt service routine will start.
If the PWM generator does not trigger the A/D converter, the PWM interrupt service routine will start at the
beginning of the PWM cycle.
Conditioning circuit
Note: In the start-low mode, the PWM input vm is converted to VH-(vm-VL) internally before it is compared with
the carrier wave to generate the PWM signal. With the conversion, both the start-low and start-high modes will
have the same duty cycle expression. For example, for a sawtooth wave with VL=0 and VH=1, or for a triangular
wave with VL= -VH, the duty cycle D of the PWMA output in both the start-low and start-high modes is:
D = vm/VH.
Image:
A A
B B
Parameters Description
PWM Source Source of the PWM generator. It can be PWM 1 to PWM 4.
Mode Type Operation mode of the PWM generation. It can be one of the 6 modes. The
waveforms of the 6 operation modes are described below.
Sampling Frequency Sampling frequency of the PWM generator, in Hz. The calculation is done and the
PWM signal duty cycle is updated based on this frequency.
PWM Freq. Scaling The ratio between the PWM switching frequency and the sampling frequency. It
Factor can be from 1 to 100. For example, if the sampling frequency is 50 kHz and the
scaling factor is 3, the PWM switching frequency will be 150 kHz. That is
switches will operate at 150 kHz. But gating signals will be updated at 50 kHz, or
once per 3 switching cycles.
Trigger ADC Setting whether for the PWM generator to trigger the A/D converter. It can be one
of the following:
- Do not trigger ADC: PWM does not trigger the A/D converter.
- Trigger ADC Group A: PWM will trigger Group A of the A/D converter.
- Trigger ADC Group B: PWM will trigger Group B of the A/D converter.
- Trigger ADC Group A&B: PWM will trigger both Group A and B of the A/D
converter.
ADC Trigger Position A/D trigger position ranges from 0 to a value less than 1. When it is 0, the A/D
converter is triggered at the beginning of the PWM cycle, and when it is 0.5, the A/
D converter is triggered at the 180o position of the PWM cycle.
Use Trip-Zone i Define whether the PWM generator uses the ith trip-zone signal or not, where i
ranges from 1 to 6. It can be one of the following:
- Disable Trip-Zone i: Disable the ith trip-zone signal.
- One shot: The PWM generator uses the trip-zone signal in the one-shot
mode. Once triggered, the PWM must be started manually.
- Cycle by cycle: The PWM generator uses the trip-zone signal in the cycle-by-
cycle basis. The trip-zone signal is effective within the current cycle, and PWM
will automatically re-start in the next cycle.
PWMA DC Trip Digital compare (DC) trip source DCAH for PWMA. The PWM channel may have
Src1(DCAH) up to two DC trip sources: DCAH and DCAL. The trip source can be one of the
following:
- Do not use: PWM doesn't use this signal.
- Trip-zone 1: PWM uses trip-zone 1 as digital compare input signal.
- Trip-zone 2: PWM uses trip-zone 2 as digital compare input signal.
- Trip-zone 3: PWM uses trip-zone 3 as digital compare input signal.
- Comparator 1: PWM uses Comparator 1 as digital compare input signal.
- Comparator 2: PWM uses Comparator 2 as digital compare input signal.
- Comparator 3: PWM uses Comparator 3 as digital compare input signal.
PWMA DC Trip Digital compare (DC) trip source DCAL for PWMA. The trip source can be one of
Src1(DCAL) the following:
- Do not use: PWM doesn't use this signal.
- Trip-zone 1: PWM uses trip-zone 1 as digital compare input signal.
- Trip-zone 2: PWM uses trip-zone 2 as digital compare input signal.
- Trip-zone 3: PWM uses trip-zone 3 as digital compare input signal.
- Comparator 1: PWM uses Comparator 1 as digital compare input signal.
- Comparator 2: PWM uses Comparator 2 as digital compare input signal.
- Comparator 3: PWM uses Comparator 3 as digital compare input signal.
For 2-phase PWM generators, the outputs are determined based on the mode of operation, as described below.
The carrier wave is either sawtooth or triangular, depending on the mode of operation. It increases from 0 to the
peak value Vpk, and there is no dc offset.
Operation Mode 1:
The figure below on the left shows the waveforms of Mode 1. In the figure, "CA" and "CB" refer to two inputs
A and B of the 2-phase PWM generator. Each input controls the turn-off time of each output.
Operation Mode 2:
The figure below on the right shows the waveforms of Mode 2. Unlike in Mode 1, each input controls the turn-
on time of each output.
0 t t
CB CA CB CA CB CA CB CA
PWMxA PWMxA
PWMxB PWMxB
Operation Mode 3:
The figure below on the left shows the waveforms of Mode 3. Input A controls the turn-on and Input B controls
the turn-off of the PWM output A. The PWM output B is on for one complete PWM cycle, and is off for the
next cycle.
Operation Mode 4:
The figure below on the right shows the waveforms of Mode 4. The carrier wave is triangular. Each input
controls both the turn-on and turn-off of its output.
Mode 3: Mode 4:
t CA CA CA CA t
CA CB CA CB CB CB CB CB
PWMxA PWMxA
PWMxB PWMxB
Operation Mode 5:
The figure below on the left shows the waveforms of Mode 5. The carrier wave is triangular. Similar to Mode 4,
each input controls both the turn-on and turn-off of its output. Note that PWM output B is inverted in this case.
Operation Mode 6:
The figure below on the right shows the waveforms of Mode 6. In this mode, Input A controls the turn-on and
Input B controls the turn-off of PWM output A. The PWM output B is on for the first half PWM cycle, and is
off for the second half cycle.
Mode 5: Mode 6:
t CA CB CA CB t
CA CA CA CA
CB CB CB CB
PWMxA PWMxA
PWMxB PWMxB
Image:
Attributes:
Parameters Description
PWM Source Source of the PWM generator. It can be from one of the following:
- APWM 1 (GPIO 5)
- APWM 1 (GPIO 19)
PWM Frequency Frequency of the PWM generator, in Hz
Carrier Wave Type The carrier wave type and the initial PWM output state. It can be one of the
following:
- Sawtooth (start low): Sawtooth wave, with the PWM output in the low state
initially.
- Sawtooth (start high): Sawtooth wave, with the PWM output in the high state
initially.
Stop Action The output status when the PWM generator is stopped. It can be one of the
following:
- Output low: The PWM output will be set to low.
- Output high: The PWM output will be set to high.
Peak-to-Peak Value Peak-to-peak value of the carrier wave
Offset Value DC offset value of the carrier wave
Phase Shift Phase shift of the output with respect to the reference PWM generator, in deg.
Initial Input Value Initial value of the input
Start PWM at When it is set to Start, PWM will start right from the beginning. If it is set to Do
Beginning not start, one needs to start PWM using the Start PWM block.
Similar to 1-phase PWM generators, an APWM generator can generate a PWM signal that has a phase shift
with respect to another PWM generator. The way how PWM blocks are defined for phase shift is explained in
Section 9.4.5.
Image:
Variable
Freq
F2802x
Attributes:
Parameters Description
PWM Source Source of the PWM generator. It can be one of the following:
PWM 1, PWM 2, PWM 3, PWM 4, and 3-phase PWM 123
Adjust Interrupt Pos. Specify if the interrupt position is adjusted with the frequency. It can be one of the
following:
- Do not adjust: The interrupt position will remain unchanged as calculated with
the base frequency.
- Adjust: The interrupt position will be recalculated at the beginning of
each cycle based on the new frequency.
Adjust Ramp Specify if the ramp compensation of the comparator DAC block is adjusted with
Compensation the frequency. It can be one of the following:
- Do not adjust: The ramp compensation will remain unchanged as calculated
with the base frequency.
- Adjust: The ramp compensation will be recalculated at the beginning of
each cycle based on the new frequency.
The sampling frequency of the corresponding PWM block will be changed at the beginning of the next PWM
period as follows:
PWM_Frequency = PWM_Base Frequency / Input_Value
where PWM_Base_Frequency is the sampling frequency of the corresponding PWM block, and Input_Value is
the input value of this block.
If the interrupt position is to be adjusted, the interrupt position will be recalculated in each cycle. Since
adjusting the interrupt position takes time, if the frequency change is small, it is recommended not to adjust the
interrupt position.
Similarly, if the ramp compensation is to be adjusted, the ramp compensation will be recalculated in each cycle.
Since adjusting the ramp compensation takes time, if the frequency change is small, it is recommended not to
adjust the ramp compensation.
Image:
F2802x F2802x
Attributes:
Parameters Description
PWM Source The source of the PWM generator. It can be: PWM 1-7, 3-phase PWM 123 and
PWM 456, and Capture 1.
Image:
TZ1
TZ2
TZ3
Parameters Description
Use Trip-Zone i Specify if the ith trip-zone is used.
GPIO Port for Trip-Zone i Specify a designated GPIO port as the ith trip-zone input signal. It can be one
of the following:
- For trip-zone 1: GPIO12
- For trip-zone 2: GPIO16 or 28
- For trip-zone 3: GPIO17 or 34
Use Comparator i Specify if the ith comparator is used as the trip-zone input signal
Parameters Description
PWM Source Source of the PWM generator. It can be: PWM 1-4 and 3-phase PWM 123.
The trip-zone interrupt can be generated in either one-shot mode of cycle-by-cycle mode, as defined in the
As shown above, the A/D converter element in SimCoder is not exactly the same as the physical A/D converter
on the DSP. Rather, it combines the functions of an offset circuit, the DSP A/D converter, and a scaling block.
This is designed for the convenience of AC system applications. It will be further explained in Section 6.5.3.
In many applications, the circuit variables to be monitored are AC signals, especially in AC motor drive
systems. For each of this kind of AC signals, an offset circuit must be built in the hardware on circuit board at
the input of the DSP analog input, in order to shift the signal level to the acceptable range of 0 to +3.3V.
SimCoder’s A/D converter provides the convenience for such cases. Instead of level-shifting and scaling the A/
D output signals, user may chose to use the offset option and scaling factor in the SimCoder A/D converter, and
the target code will be generated accordingly.
The image and the parameters of the A/D converter in the SimCoder library are described below. In the
following description, "A/D converter" refers to the A/D converter in the SimCoder library, not the DSP A/D
converter, unless otherwise stated.
F2802x
Attributes:
Parameters Description
Ch Ai or Bi Mode Input mode of the ith A/D converter channel Ai or Bi. The input mode can be one of
the following:
- AC: This option is for simulation only, not for code generation. The input
range is considered from -1.65V to +1.65V. This option includes the offset
circuit into the A/D converter. It provides the convenience in cases where an
external level shifter is needed to shift the AC signal to the 0 to +3.3V range.
- DC: The input is a dc value, and the range is from 0 to +3.3V.
Ch Ai or Bi Gain Gain k of the ith A/D converter channel Ai or Bi.
Conversion Order Order of the A/D conversion. If the field is left blank (undefined), the conversion
will be done based on the serial numbers of the A/D channel. For example, if A0,
A2, A4, B1, and B3 are used, the conversion will be done in this order: A0, A2,
A4, B1, and B3. If you wish certain channels to be performed first, you can define
the order here. For example, if the conversion order is defined as:
A4,A0,A2,B3,B2
The conversion will be done in the order defined, that is, A4 before A0, and A0
before A2, and so on.
ADCINT1 PIE Specify if interrupt ADCINT1 uses PIE Group1 or PIE Group10.
Selection
ADCINT2 PIE Specify if interrupt ADCINT2 uses PIE Group1 or PIE Group10.
Selection
An A/D converter has up to 16 channels. SimCoder divides them into groups according their sampling rates.
The group with the highest sampling rate uses interrupt ADCINT1, and the group with the second highest
sampling rate uses interrupt ADCINT2, etc. The two ADC groups with the highest sampling rates can choose
interrupt from PIE (peripheral interrupt expansion) groups of the PIE vector table for different interrupt priority.
PIE Group1 has a higher interrupt priority than PIE Group10. For example, PWM's interrupt is in PIE Group3,
Its interrupt priority is lower than PIE Group1 but higher than Group10. If one wants PWM interrupt to have a
higher priority than ADC interrupt, one needs to set the interrupt corresponding to the ADC channels to use PIE
Group10.
Trigger Source:
The A/D converter can be triggered from multiple sources. Multiple A/D channels may share the same trigger
source. Each A/D channel can be triggered by:
- One of the PWM generators,
DC Signal Input
0 V -> +3.3 V
Please note that, in this example, if the gain of the proportional block is changed from 2.2 to 1.1, and the A/D
gain is changed from 45.4545 to 90.909, the simulation results will be the same. But the generated hardware
code will not be correct. This is because the hardware code assumes that the maximum input value is scaled to
+3.3V, but in this case it is only +1.5V. Therefore, one must set up the circuit such that, in the dc mode, the
maximum input value is scaled to be +3.3V.
In another example, assume that a power circuit voltage is an ac quantity, and the range is as follows:
Vi_max = +/- 75 V
The input mode of the A/D converter will be set to ac, and the input range is from -1.65V to +1.65V. Assume
that the actual value of the voltage has a peak value of:
Vi = +/- 50 V
Let the voltage sensor gain be 0.01. After the voltage sensor, the maximum value and the actual value of the
input become:
Vi_max_s = +/- 0.75 V
Vi_s = +/- 0.5 V
Since the A/D converter input range is from -1.65V to +1.65V, this signal must be scaled before it is sent to the
DSP. A conditioning circuit with a gain of 2.2 is needed (i.e. 1.65/0.75 = 2.2). After the conditioning circuit and
at the input of the DSP A/D converter, the maximum value and the actual value of the input become:
Vi_max_s_c = +/- 1.65 V
Vi_s_c = +/- 1.1 V
The scaling block after the DSP A/D can be selected such that the original power circuit quantity is restored. In
this example, a gain of 45.4545 will be used. Note that this is the reciprocal of the combined gain of the voltage
sensor and the conditioning circuit. At the A/D output, the maximum value and the actual value are:
Vo_max = +/- 75 V
Vo = +/- 50 V
The gain of the A/D channel in PSIM will be set to 45.4545. The circuit connection and the settings are shown
in the figure below.
AC Signal Input
-1.65 V -> +1.65 V
Notice that in this circuit, the ac signal is sent to the A/D converter directly. This is because that, when the A/D
input mode is set to AC, the input range is from -1.65V and +1.65V, and the function of the conditioning circuit
that performs the dc offset is already included in the A/D converter block. In the actual hardware circuit, the ac
signal must be scaled and offset so that the range is within 0V to +3.3V required by the A/D converter.
9.9 Comparator
F2802x supports three comparator modules. Each comparator block can have two external analog inputs, or one
external analog input and one internal DAC reference for the other input. The comparator output can be sent to
the PWM trip-zone and to the GPIO output.
Image:
A1 out1
B1
A2 out2
B2
Parameters Description
Comparator i Define how the output of the ith comparator is used. It can be one of the
following:
- Do not use: Not used
- As a normal comparator: Used as a normal comparator
- As a Trip-Zone signal: Used as a trip-zone signal
Output Logic Define the comparator output logic. It can be:
- High when A > B: The output is high when Input A is greater than B.
- High when A < B: The output is high when Input A is less than B.
Compare Method Define how Input A of the comparator is compared to Input B. it can be
one of the following:
- Compare to Input B: Input A is compared to Input B where Input
B is an external analog signal.
- Compare to Constant Value: Input A is compared to a constant value.
- Compare to DAC output: Input A is compared to a DAC output
which is an internal signal.
Constant Value The constant value when Compare Method is defined as Compare to
Constant Value. The range of the constant value is from 0 to 3.3V.
For all comparators, Input A is always from an external analog input. If Input B is also from another external
analog input (if the parameter Compare Method is defined as Compare to Input B), the corresponding port must
be defined as a comparator input in the Hardware Configuration block.
If the compare method is to compare to a constant value, Input B needs to be connected to ground in the
schematic. If the compare method is to compare to a DAC output, Input B needs to be connected a comparator
DAC output. In both cases, the corresponding ADC/AIO port can be used for other functions.
Image:
out1
out2
Attributes:
Parameters Description
Comparator i Output Output port position of the ith comparator. It can be:
- For Comparator A: GPIO1, 20, or 42
- For Comparator B: GPIO3, 21, 34, or 43
- For Comparator C: GPIO34
A comparator output block must be used together with a comparator input block. When a comparator outupt
channel is used, the corresponding comparator input channel must be defined.
Image:
in1 out1
in2 out2
Attributes:
Parameters Description
DAC i Range The upper limit of the input signal range of the ith comparator DAC. The lower
limit is 0.
Use Ramp Generator Define if the ramp generator is used in the comparator DAC.
Total Ramp The total compensation of the ramp generator in one PWM period. It represents the
Compensation total decrease of the ramp in one cycle.
Outputs of the comparator DAC can only be connected to the corresponding inverting inputs (Input B) of the
comparator in a comparator input block. That is, node out1 can only be connected to node B1 of the comparator
input block, and node out2 to node B2, and node out3 to B3. Also, a comparator DAC block cannot be used
alone. It must be used in conjunction with a comparator input block.
If the ramp generator is not used, the input value is applied directly to DAC output immediately. The output
range is from 0 to 3.3V, and the output can be calculated as follows:
DAC Output = DAC Input * 3.3 / DAC Range
If the ramp generator is used, the input value is saved and used as the initial output value in the next PWM
period. The comparator DAC output decreases linearly within the PWM period, and the total decrease is equal
to the total ramp compensation value.
When the ramp generator is used, the sampling rate associated with the comparator DAC input must be the
same as the frequency of the PWM generator that uses the comparator.
Image:
D0 D0 D0 D0
D1 D1 D1 D1
D2 D2 D2 D2
D3 D3 D3 D3
D4 D4 D4 D4
D5 D5 D5 D5
D6 D6 D6 D6
D7 D7 D7 D7
F2802x
Parameters Description
Port Position for Input i The port position of the Input i. It can be one of the 21 GPIO ports or one
of the 6 AIO ports.
Use as External Interrupt Indicate if this port is used as an external interrupt input.
Parameters Description
Port Position for Output i The port position of the Output i. It can be one of the 21 GPIO ports or one
of the 6 AIO ports.
Note that each GPIO and AIO port can be used for one function only. If an IO port is used as a digital input port,
it can not be used as a digital output or any other peripheral port. For example, if Port GPIO1 is assigned as
digital input and it is also used as PWM1 output, an error will be reported.
F2802x supports 3 masked external interrupts (XINT1 to XINT3). There are no dedicated pins for the external
interrupts. XINT1, XINT2, and XINT3 interrupts can accept inputs from GPIO0 to GPIO31 pins.
Image:
Capture
Parameters Description
Capture Source Source of the capture may come from one of the GPIO ports as listed below:
- Capture 1 (GPIO5)
- Capture 1 (GPIO19)
Event Filter Prescale Event filter prescale. The input signal is divided by the selected prescale.
Timer Mode Capture counter timer mode. It can be either Absolute time or Time difference.
Parameters Description
Capture Source Source of the capture. It has only one source Capture1.
The Capture State block output is either 1 or 0, where 1 means the rising edge and 0 means the falling edge.
Image:
SCI
Config
F2802x
Attributes:
Parameters Description
SCI Port Define the SCI port. These GPIO ports can be used for SCI, as listed below:
SCIA: GPIO28, 7, and 18 in combination with GPIO29, 12, and 19
Speed (bps) SCI communication speed, in bps (bits per second). A list of preset speeds is
provided at 200000, 115200, 57600, 38400, 19200, or 9600 bps. Or one can
specify any other speed manually.
Parity Check The parity check setting for error check in communication. It can be either None,
Odd, or Even.
Output Buffer Size Size of the data buffer allocated in DSP for SCI. The buffer is located in the RAM
area, and each buffer cell stores one data point which consists of three 16-bit words
(that is, 6 bytes, or 48 bits, per data point).
Note that the buffer size should be properly selected. On one hand, a large buffer is preferred in order to collect
more data points so that more variables can be monitored over a longer period of time. On the other hand, the
internal DSP memory is limited, and the buffer should not be too large to interfere with the normal DSP
operation.
For more information on how to select the buffer size, please refer to the document "Tutorial - Using SCI for
Real-Time Monitoring.pdf".
Image:
in
Attributes:
Parameters Description
Initial Value Initial value of the SCI input variable.
Image:
out
F2802x
Attributes:
Parameters Description
Data Point Step It defines how frequent data is collected. If the Data Point Step is 1, every data
point is collected and transmitted. If the Data Point Step is 10, for example, only
one point of out every 10 points is collected and transmitted.
Note that if the Data Point Step is too small, there may be too many data points and it may not be possible to
transmit them all. In this case, some data points will be discarded during the data transmission.
Also, the Data Point Step parameter is used only when then DSP Oscilloscope is in the continuous mode. When
it is in the snap-shot node, this parameter is ignored and every point is collected and transmitted.
In simulation, the SCI output behaviors as a voltage probe.
Image:
CS0
CS1
CS2
CS3
Parameters Description
SPI Port Define the SPI port from the options:
- SPIA (GPIO 16-19)
- SPIA (GPIO 3, 5, 18, 19)
- SPIB (GPIO 12-15)
- SPIB (GPIO 24-27)
Chip Select Pin0, 1, 2, The GPIO port of the chip select pin. PSIM supports up to 16 SPI devices, which
and 3 requires four GPIO pins for chip select, as defined by Chip Select Pin0 to Pin3.
These GPIO ports and the SPI slave transmit-enable pin SPISTE are used to
generate the chip select signal.
SPI Buffer Size The buffer size of the SPI commands. Each memory cell of the buffer saves the
index of a SPI command. Normally, one can specify the buffer size as 1 plus the
number of SPI commands (i.e. Start Conversion Command, Receiving Data
Command, Sending Data Command, and Sync. Command) in all SPI Input/Output
elements.
Image:
CS0
CS1
CS2 Intr
CS3
Sync
Attributes:
Parameters Description
Chip Select Pins The state of the chip select pins corresponding to the SPI device. When the chip
select pins are at this state, this SPI device is selected.
Communication Speed SPI communication speed, in MHz.
(MHz)
Clock Type SPI clock type, as determined by the SPI hardware device. It can be one of the
following:
- Rising edge without delay: The clock is normally low, and data is latched at the
clock rising edge.
- Rising edge with delay: The clock is normally low, and data is latched at the
clock rising edge with delay.
- Falling edge without delay: The clock is normally high, and data is latched at
the clock falling edge.
- Falling edge with delay: The clock is normally high, and data is latched at the
clock falling edge with delay.
Command Word Word length, or the length of the significant bits, of SPI communication
Length commands. It can be from 1 to 16 bits.
Image:
in
SPI
Attributes:
Parameters Description
Device Name Name of the SPI input device.
Start Conversion Command to start conversion, in hex numbers, separated by comma (for example,
Command 0x23,0x43,0x00).
Receiving Data Command to receive data, in hex numbers, separated by comma (for example,
Command 0x23,0x43,0x00).
Data Bit Position Define where the data bits are in the receiving data string. The format is:
ElementName = {Xn[MSB..LSB]}
where
- ElementName is the name of the SPI input device. If it is the current SPI input
device, use y instead.
- {} means that the item in the bracket repeats multiple times.
- Xn is the nth word received from the SPI input device, and n start from 0.
- MSB..LSB defines the position of the significant bits in the word.
Input Range Specify the parameter Vmax that defines the input range. This parameter is valid
only when the SPI device is an A/D converter. If the device conversion mode is
DC, the input ranges from 0 to Vmax. If the device conversion mode is AC, the
input ranges from -Vmax/2 to Vmax/2.
Scale Factor Output scale factor Kscale. If the scale factor is 0, the SPI device is not an A/D
converter, and the result will be exactly the same as what DSP receives from SPI
communication. Otherwise, the SPI device is an A/D converter, and the result is
scaled based on this factor and the A/D conversion mode.
ADC Mode The A/D conversion mode of the device. It can be either DC or AC. Note that this
parameter is valid only when the device is an A/D converter.
Initial Value The initial value of the input.
The formula for the Data Bit Position defines the data length of a SPI input device. For example,
y=x1[3..0]x2[7..0], means that the data length is 12, and the result is the lower 4 bits of the 2nd word and the
lower 8 bits of the 3rd word. If the received data string is 0x12,0x78,0xAF, then the result is 0x8AF.
If the scale factor is not 0, the output will be scaled based on the following:
In the DC conversion mode:
- In simulation: Output = Input K scale
Data_Length
2
) V max Ksc al e
- In hardware: Output = (Result – 2Data_Length-1 ------- ---------
-----------------------
The parameter Data_Length is calculated from the Data Bit Position formula.
Image:
out
SPI
Attributes:
Parameters Description
Device Name Name of the SPI output device.
Scale Factor Output scale factor Kscale. If the scale factor is 0, the SPI device is not a D/A
converter, and the result will be exactly the same as what DSP receives from SPI
communication. Otherwise, the SPI device is an D/A converter, and the result is
scaled based on this factor and the D/A conversion mode.
Output Range Specify the parameter Vmax that defines the output range. This parameter is valid
only when the SPI device is an D/A converter. If the device conversion mode is
DC, the input ranges from 0 to Vmax. If the device conversion mode is AC, the
input ranges from -Vmax/2 to Vmax/2.
DAC Mode The D/A conversion mode of the device. It can be either DC or AC. Note that this
parameter is valid only when the device is a D/A converter.
Sending Data Command to send the output data, in hex numbers, separated by comma (for
Command example, 0x23,0x43,0x00).
Data Bit Position Define where the data bits are in the sending data string. The format is:
ElementName = {Xn[MSB..LSB]}
where
- ElementName is the name of the SPI output device. If it is the current SPI
output device, use y instead.
- {} means that the item in the bracket repeats multiple times.
- Xn is the nth word sent to the SPI output device, and n start from 0.
- MSB..LSB defines the position of the significant bits in the word.
Sync. Command The command to synchronize output channels of the SPI output device, in hex
numbers, separated by comma (for example, 0x23,0x43,0x00). This command is
used when the SPI output device does not have the synchronization signal
The formula for the Data Bit Position defines the data length of a SPI output device. For example,
y=x1[3..0]x2[7..0], means that the data length is 12, and the data is the lower 4 bits of the 2nd word and the
lower 8 bits of the 3rd word. If the sending data string is 0x12,0x78,0xAF, then the data is 0x8AF.
If the scale factor is not 0, the output will be scaled based on the following:
185 Chapter 9: F2802x Hardware Target
In the DC conversion mode:
- In simulation: Output = Input K scale
V max
In the AC conversion mode:
--------------------------- -----------
V max
The parameter Data_Length is calculated from the Data Bit Position formula.
Attributes:
Parameters Description
Time Output Method Define how interrupt time is measured. It can be one of the following:
- SCI (time used): Using SCI. Time used by the interrupt service routine, in
DSP clock count, is measured and is sent out via SCI output.
- SCI (time remaining): Using SCI. Time remaining in the interrupt service
routine, in DSP clock count, is measured and is send out via SCI output. The
time remaining is defined as the time from the end of the current interrupt to
the beginning of the next interrupt.
- GPIO0 to GPIO44, or AIO2 to AIO14: Using a GPIO port. A pulse is
generated at the specified GPIO port. The pulse is set to high when entering the
interrupt, and set to low when exiting the interrupt. An oscilloscope can be
used to measure the width of the pulse.
Sampling Frequency Sampling frequency of the interrupt service routine, in Hz.
When SCI is used, the value is the count of the DSP clock. For example, if the value is 6000, for a 60-MHz DSP
clock, the interrupt time will be: 6000 / 60M = 100 us.
Project Setting:
In the Code Composer Studio project file, the following settings are provided:
- RAM Debug: To compile the code in the debug mode and run it in the RAM memory
- RAM Release: To compile the code in the release mode and run it in the RAM memory
- Flash Release: To compile the code in the release mode and run it in the flash memory
- Flash RAM Release: To compile the code in the release mode and run it in the RAM memory
When RAM Debug or RAM Release is selected, CCS uses the linker command file F2802x_RAM_Lnk.cmd to
allocate the program and data space.
When Flash Release is selected, CCS uses the linker command file F2802x_FLASH_Lnk.cmd to allocate the
program and data space.
When Flash RAM Release is selected, CCS uses the linker command file F2802x_FLASH_RAM_Lnk.cmd to
allocate the program and data space. The memory allocation is the same as in RAM Release.
The code compiled in the release mode is faster than the code in the debug mode. Also, the code in RAM
Release or Flash RAM Release is the fastest. The code in RAM Debug is slower, and the code in Flash Release
is the slowest. In a development, normally one would start with RAM Debug for easy debugging. Then switch
to RAM Release and consequently to Flash Release or Flash RAM Release.
Memory Allocation:
In the generated link files, the memory allocation is defined in the following way.
With the RAM Debug, RAM Release, and Flash RAM Release settings:
RAM Memory
0x0000 - 0x07FF (2K)
interrupt vectors
stack
0x8000 - 0x9FFF (8K*)
program and data space
Notes:
* The RAM memory predefined by SimCoder for program and data space is:
- For F28027, F28026, F28023, and F28022: From 0x8000 to 0x9FFF (8K)
- For F28021: From 0x8000 to 0x8BFF (6K)
- For F28020 and F280200: From 0x8000 to 0x83FF (2K)
10.1 Overview
With the F2837x Hardware Target, SimCoder can generate code that is ready to run on any hardware boards
based on Texas Instruments’ F2837x fixed-point DSP.
The F2837x Hardware Target will work with all F2837x packages.
The F2837x Hardware Target library includes the following function blocks:
- PWM generators: 3-phase, 2-phase, 1-phase, and APWM
- Variable frequency PWM
- Start/Stop functions for PWM generators
- PWM trip-zone and trip-zone state
- A/D converter
- ADC voltage reference
- Comparator input, output, and DAC
- DAC converter
- Digital input, output, and sample time
- Input X-BAR, output X-BAR, and PWM X-BAR
- Encoder, encoder state, and encoder index/strobe position
- Up/Down counter
- Capture and capture state
- SCI configuration, Input, and output
- SPI configuration, device, input, and output
- CAN configuration, input, output, and remote request
- Interrupt Time
- DSP clock
- Hardware configuration
When generating the code for a system that has multiple sampling rates, SimCoder will use the interrupts of the
PWM generators for the PWM sampling rates. For other sampling rates in the control system, it will use the
Timer 1 interrupt first, and then Timer 2 interrupt if needed, If there are more than three sampling rates in the
control system, the corresponding interrupt routines will be handled in the main program by software.
In TI F2837x, PWM generators can generate hardware interrupt. SimCoder will search and group all the
elements that are connected to the PWM generator and have the same sampling rate as the PWM generator.
These elements will be automatically placed and implemented in an interrupt service routine in the generated
code.
In addition, digital input, encoder, capture, and trip-zone can also generate hardware interrupt. Each hardware
interrupt must be associated with an interrupt block (described in Section 4.5 of this Manual), and each interrupt
block must be associated with an interrupt service routine (a subcircuit that represents the interrupt service
routine). For example, if a PWM generator and a digital input both generate interrupt, there should be one
interrupt block and one interrupt service routine for each of them.
The definitions of the elements in the F2837x Hardware Target library are described in this Chapter.
The figure below shows the F2837x 100-pin PZP port assignment. Only the GPIO functions are show on GPIO
pins. The other port functions will be explained in next section about hardware configuration.
Image:
The Hardware Configuration block is for user to specify the I/O ports usage of the F2837x hardware. Every port
in use must be assigned correctly. The ports not in use can be left unchecked.
To make changes, click on the button Unlock. After changes are made, click on Lock to lock the configuration.
For each GPIO port, a check box is provided for each of its available function. When a box is checked, the
GPIO port is configured for that particular function. Only one box can be checked for each GPIO port. For
example, if the checkbox for "Digital Input" is checked for port GPIO1, this port is configured as a digital input,
and hence, cannot be used for any other functions. If it is used as a PWM output in the PSIM circuit schematic,
an error message will be generated.
Image:
Attributes:
Parameters Description
DSP Clock Source There are three ways of providing system clock to F2837x:
- Internal oscillator 1
- Internal oscillator 2
- External oscillator
External Clock (MHz) Frequency of the external clock on the DSP board, in MHz. The frequency must be
an integer, and the maximum frequency allowed is 20 MHz. This parameter is
ignored if the DSP clock source is selected to be internal oscillator 1 or 2.
DSP Speed (MHz) DSP Speed, in MHz. The speed must be an integer, and must be an integer
multiple of the external clock frequency. The maximum DSP speed allowed is
194MHz when using internal oscillators, and is 200MHz when using external
oscillator.
If a DSP Configuration block is not used in a schematic, the default values of the DSP Configuration block will
be used:
• External oscillator
• 20MHz
• 200MHz
10.4.1 3-Phase PWM, 1-phase PWM, and 1-phase PWM (phase shift)
The 3-phase PWM generator consists of three 1-phase PWM blocks of consecutive order. Therefore, the
attributes for 3-phase PWM block, 1-Phase PWM block and 1-phase PWM (phase shift) block are mostly
the same.
The difference between the 1-Phase PWM and 1-phase-PWM (phase shift) blocks is how the phase shift is
defined. The 1-phase PWM block defines the phase shift through a parameter which is a constant, while the 1-
Phase PWM (phase shift) block reads the phase shift from an external input (labeled as "phase" in the image).
The phase shift is in degree.
In the 3-phase PWM generator image, "u", "v", and "w" refer to the three phases (alternatively they are called
phase "a", "b", and "c"). The letter "p" refers to the positive output, and "n" refers to the negative output. For
example, for 3-phase PWM 123, "up" is PWM1A, and "un" is PWM1B.
Image:
Attributes:
Parameters Description
PWM Source Source of the PWM generator. Each 1-phase PWM block has two outputs (PWM A
and PWM B) assigned to two GPIO pins. Each 3-phase PWM module consists of
three 1-phase PWM blocks. For example, 3-phase PWM 123 (GPIO0) consists of
PWM1, PWM2, an PWM3. Therefore, each 3-phase PWM has 6 GPIO pins.
Output Mode Output mode of the PWM generator. It can be one of the following:
(Not used for 3-phase) - Use PWM A&B: Both PWM outputs A and B are used, and they are
complementary.
- Use PWM A: Only PWM output A is used.
- Use PWM B: Only PWM output B is used.
- No PWM output: No PWM output is used (As a timer).
Sampling Frequency Sampling frequency of the PWM generator, in Hz. The calculation is done and the
PWM signal duty cycle is updated based on this frequency.
PWM Freq. Scaling The ratio between the PWM switching frequency and the sampling frequency. It
Factor can be from 1 to 15. For example, if the sampling frequency is 50 kHz and the
scaling factor is 3, the PWM switching frequency will be 150 kHz. That is switches
will operate at 150 kHz. But gating signals will be updated at 50 kHz, or once per 3
switching cycles.
Carrier Wave Type Carrier wave type and the initial PWM output state. It can be one of the following:
- Triangular (start low): Triangular wave, and the initial PWM output state is
low.
- Triangular (start high): Triangular wave, and the initial output state is high.
- Sawtooth (start low): Sawtooth wave, and the initial output state is low.
- Sawtooth (start high): Sawtooth wave, with the initial output state is high.
Trigger ADC Setting whether for the PWM generator to trigger the A/D converter. It can be one
of the followings:
- Do not trigger ADC: PWM does not trigger the A/D converter.
- Trigger ADC: PWM will trigger A/D converter.
ADC Trigger Position A/D trigger position ranges from 0 to a value less than 1. When it is 0, the A/D
converter is triggered at the beginning of the PWM cycle, and when it is 0.5, the A/
D converter is triggered at the 180o position of the PWM cycle.
Use Trip-Zone 1, 2, 3 Define whether the PWM generator uses the trip-zone signal or not. It can be one
of the followings:
- Do not use: Disable the ith trip-zone signal.
- One shot: The PWM generator uses the trip-zone signal in the one-shot
mode. Once triggered, the PWM must be started manually.
- Cycle by cycle: The PWM generator uses the trip-zone signal in the cycle-by-
cycle basis. The trip-zone signal is effective within the current cycle, and PWM
will automatically re-start in the next cycle.
Select Trip Events Specify the combination of DC trip events applied to the current PWM. It can be
one or any combination of DCAEVT1, DCAEVT2, DCBEVT1, and DCBEVT2.
Trip Action Define how the PWM generator responds to the trip action. It can be one of the
followings:
- High impedance: PWM outputs in high impedance
- PWM A high & B low: Set PWM A high and B low.
- PWM A low & B high: Set PWM A low and B high.
- PWM A both high: Set both PWM A and B high (not used for 3-phase).
- PWM A both low: Set both PWM A and B low (not used for 3-phase).
- No action: No action taken.
Peak-to-Peak Value Peak-to-peak value Vpp of the carrier wave
Chapter 10: F2837x Hardware Target 194
Offset Value DC offset value Voffset of the carrier wave
Phase Shift Phase shift of the output with respect to the reference PWM generator output, in
(for 1-phase only) deg. For example, when the phase shift is -30, the output will be shifted to the right
(lagging) by 30 deg. with respect the reference PWM output.
Initial Input Value Initial value of the PWM block. For three initial input values are set for 3-phase
PWM block’s three inputs u, v, and w.
Use HRPWM Define the high-resolution PWM. It can be one of the followings:
(Not used for 3-phase) - Do not use HRPWM: Do not use high-resolution PWM
- Use HRPWM without calibration: Use high-resolution PWM without
calibration
- Use HRPWM with calibration: Use high-resolution PWM with calibration
Start PWM at When it is set to Start, PWM will start right from the beginning. If it is set to Do not
Beginning start, one needs to start PWM using the Start PWM block.
Simulation Output The simulation output mode can be set to either of the followings:
Mode - Switching mode: the outputs of the PWM block are PWM signals.
- Average mode: the outputs of the PWM block are average mode signals.
In the average mode, if the carrier wave is from negative to positive, and the
absolute values of the negative peak and the positive peak are equal (for example,
the carrier wave is from -1 to +1, or from -5 to +5), the modulation is considered as
an ac signal modulation. Otherwise, the modulation is considered as a dc signal
modulation. For example, modulation in a 3-phase or single-phase inverter is an ac
modulation, and modulation in a buck converter is a dc modulation.
In the ac signal modulation, if the input u of the PWM block is Vu, the output up
and un in average mode will be:
Vup = Vu / (Vpp + Voffset)
Vun = -Vup
In this case, Vu is between -(Vpp+Voffset) and (Vpp+Voffset), and Vup is between -1 to
+1.
In the dc signal modulation, the output up and un in average mode will be:
Vup = (Vu - Voffset) / Vpp
Vun = 1 - Vup
In this case, Vu is between Voffset and Vpp+Voffset, and Vup is between 0 to +1.
When it is set to the average mode, the PWM block outputs can be connected to a
converter/inverter in the average mode model.
Phase Shift
A 1-phase PWM generator can generate PWM signal that is phase shifted with respect to another PWM signal.
The way how PWM blocks are defined for phase shift is explained in Section 8.4.5.
The phase shift value is in degrees. When the value is -30o, the output will be shifted to the right (lagging) by
30o of the switching cycle with respect to the reference PWM generator output. This is equivalent to shifting the
PWM carrier wave to the right by 30o. When the phase value is 30o, the output will be shifted to the left
(leading) by 30o.
Carrier Wave
There are two types of carrier waveforms: triangular wave (with equal rising and falling slope intervals) and
sawtooth wave. In addition, there are two operation modes: start-low and start-high modes, as explained below.
PWM Vpp H m L
input vm Vpp
VL
VVoffset
L
Voffset t t
P
Td PWMxA WMxA
x = 1, 2, ..., 6
Td PWMxB PWMxB
The input and output waveforms of a PWM generator with the sawtooth carrier wave are shown below:
PWM Vpp H m L
input vm Vpp
VL VL
Voffset t t
Td Voffset
PWMxA PWMxA
x = 1, 2, ..., 6
Td PWMxB
PWMxB
The figures above show how the dead time is defined, and the time sequence when the PWM generator triggers
the A/D converter. If triggering the A/D converter is selected, from the start of the PWM cycle, after a certain
delay defined by the A/D trigger position, the A/D conversion will start. After the A/D conversion is completed,
the PWM interrupt service routine will start.
If the PWM generator does not trigger the A/D converter, the PWM interrupt service routine will start at the
Chapter 10: F2837x Hardware Target 196
beginning of the PWM cycle.
The figures above also show how the start-high and start-low modes work. Assume that the PWM input is vm,
and the lowest value of the carrier wave is VL and the highest value is VH. In the start-high mode, the PWM
positive output PWMA is high at the beginning of the switching cycle, and it remains high as long as the input
vm is greater than the carrier wave. For example, for a carrier wave from 0 to 1, VL=0, and VH=1. If vm=0.2, the
PWM output PWMA will remain high as long as the carrier is less than 0.2.
On the other hand, in the start-low mode, the PWM positive output PWMA is low at the beginning of the
Conditioning circuit
Note: In the start-low mode, the PWM input vm is converted to VH-(vm-VL) internally before it is compared with
the carrier wave to generate the PWM signal. With the conversion, both the start-low and start-high modes will
have the same duty cycle expression. For example, for a sawtooth wave with VL=0 and VH=1, or for a triangular
wave with VL= -VH, the duty cycle D of the PWMA output in both the start-low and start-high modes is:
D = vm/VH.
The PWM dead band acts as below.
Image:
Attributes:
Parameters Description
PWM Source Source of the PWM generator. It can be PWM 1 to PWM 8.
Dead Band Type The type of PWM dead band, it can be either Active high or Active low.
Sampling Frequency Sampling frequency of the PWM generator, in Hz. The calculation is done and the
PWM signal duty cycle is updated based on this frequency.
PWM Freq. Scaling The ratio between the PWM switching frequency and the sampling frequency. It
Factor can be from 1 to 100. For example, if the sampling frequency is 50 kHz and the
scaling factor is 3, the PWM switching frequency will be 150 kHz. That is switches
will operate at 150 kHz. But gating signals will be updated at 50 kHz, or once per 3
switching cycles.
Carrier Wave Type Carrier wave type and the initial PWM output state. It can be one of the following:
- Sawtooth: Sawtooth wave.
- Triangular: Triangular wave.
Use Trip-Zone 1, 2, 3 Define whether the PWM generator uses the trip-zone signal or not. It can be one
of the followings:
- Do not use: Disable the ith trip-zone signal.
- One shot: The PWM generator uses the trip-zone signal in the one-shot
mode. Once triggered, the PWM must be started manually.
- Cycle by cycle: The PWM generator uses the trip-zone signal in the cycle-by-
cycle basis. The trip-zone signal is effective within the current cycle, and PWM
will automatically re-start in the next cycle.
Select Trip Events Specify the combination of DC trip events applied to the current PWM. It can be
one or any combination of DCAEVT1, DCAEVT2, DCBEVT1, and DCBEVT2.
Cycle-by-cycle Lock Specify when to clear the lock when in cycle-by-cycle mode:
Clear - At PWM valley
- At PWM valley/peak.
The 2-phase PWM generator generates two PWM signals with specific configurations for typical power
converter applications. The PWM carrier wave is either sawtooth or triangular, it ranges from 0 to the peak
value Vpk.
PWM module's control flow is as follows:
Image:
Attributes:
Parameters Description
PWM Source Source of the PWM generator. It can be any from APWM1 to APWM6
PWM Frequency Frequency of the PWM generator, in Hz
Carrier Wave Type The carrier wave type and the initial PWM output state. It can be one of the
following:
- Sawtooth (start low): Sawtooth wave, with the PWM output in the low state
initially.
- Sawtooth (start high): Sawtooth wave, with the PWM output in the high state
initially.
Image:
Parameters Description
PWM Source Source of the PWM generator. It can be one listed in the pull-down menu.
Adjust Interrupt Pos. Specify if the interrupt position is adjusted with the frequency. It can be one of the
following:
- Do not adjust: The interrupt position will remain unchanged as calculated with
the base frequency.
- Adjust: The interrupt position will be recalculated at the beginning of
each cycle based on the new frequency.
Adjust Ramp Specify if the ramp compensation of the comparator DAC block is adjusted with
Compensation the frequency. It can be one of the following:
- Do not adjust: The ramp compensation will remain unchanged as calculated
with the base frequency.
- Adjust: The ramp compensation will be recalculated at the beginning of
each cycle based on the new frequency.
The sampling frequency of the corresponding PWM block will be changed at the beginning of the next PWM
period as follows:
PWM_Frequency = PWM_Base Frequency / Input_Value
where PWM_Base_Frequency is the sampling frequency of the corresponding PWM block, and Input_Value is
the input value of this block.
If the interrupt position is to be adjusted, the interrupt position will be recalculated in each cycle. Since
adjusting the interrupt position takes time, if the frequency change is small, it is recommended not to adjust the
interrupt position.
Similarly, if the ramp compensation is to be adjusted, the ramp compensation will be recalculated in each cycle.
Since adjusting the ramp compensation takes time, if the frequency change is small, it is recommended not to
adjust the ramp compensation.
Image:
Attributes:
Parameters Description
PWM Source The source of the PWM generator. It can be any of PWM blocks or captures in the
pull-down list
Image:
Parameters Description
PWM Source Source of the PWM generator. It can be any of the PWM blocks in the pull-
down list.
DC Trip Src1(DCAH) Digital compare (DC) trip source DCAH for PWMxA. The PWM channel
may have up to two DC trip sources: DCAH and DCAL. The trip source can
be one of the following:
- Do not use: PWM doesn't use this signal.
- TZi(Ti): PWM uses trip-zone i as the digital compare input signal,
where i=1, 2, 3.
- TRIPi(Ti): PWM uses TRIPi as the digital compare input signal, where
i=4, 5, 7 - 12.
- Other combinations: PWM uses one of the trip signal combinations.
If the PWM source is a 3-phase PWM generator, PWMA refers to the outputs
"up", "vp", and "wp" for the 3 top switches.
PWMA DC Trip Digital compare (DC) trip source DCAL for PWMxA. The trip source can be
Src2(DCAL) one of the following:
- Do not use: PWM doesn't use this signal.
- TZi(Ti): PWM uses trip-zone i as the digital compare input signal,
where i=1, 2, 3.
- TRIPi(Ti): PWM uses TRIPi as the digital compare input signal, where
i=4, 5, 7 - 12.
- Other combinations: PWM uses one of the trip signal combinations.
PWMA 1-shot Evt Define how the one-shot signal is used for the DC trip signal of PWMA. The
(DCAEVT1) active level of the DC trip signal can be selected from the following:
- Do not use: PWM doesn't use this signal.
- Trip source 1 is low: PWM is tripped if the source signal 1 is low.
- Trip source 1 is high: PWM is tripped if the source signal 1 is high.
- Trip source 2 is low: PWM is tripped if the source signal 2 is low.
- Trip source 2 is high: PWM is tripped if the source signal 2 is high.
- Trip source 1 low & source 2 high: PWM is tripped if the source 1 signal
is low and at the same time source 2 signal is high.
Note: when defining the interrupt block associate with trip-zone, the "Device Name" parameter of the interrupt
block should be the name of the PWM generator, not the trip-zone block name. For example, if a PWM
generator called "PWM_G1" uses trip-zone 1 in the trip-zone block "TZ1". The "Device Name" of the
corresponding interrupt block should be "PWM_G1", not "TZ1". The "Channel Number" parameter in the
interrupt block is not used in this case.
The trip-zone interrupt can be generated in either one-shot mode of cycle-by-cycle mode, as defined in the
PWM generator parameter input. In the cycle-by-cycle mode, the interrupt only affects the PWM output within
the current PWM cycle. On the other hand, in the one-shot mode, interrupt triggers a trip action when the input
signal is low (0). will set the PWM output permanently, and the PWM generator must be restarted to resume the
operation.
Parameters Description
PWM Source Source of the PWM generator. It can be any one in the pull-down list
The trip-zone state element is usually used in the trip-zone interrupt routine to indicate the operation mode of
the trip-zone signal. When the output of this element is 1, it means that the trip-zone signal is in one-shot mode.
When the output is 0, the trip-zone signal is in cycle-by-cycle mode.
Image:
Parameters Description
ADC-x High Voltage Ref Specify high voltage reference for ADC block x, where x is A, B, C, and D.
ADC-x Low Voltage Ref Specify low voltage reference for ADC block x, where x is A, B, C, and D.
This value must be set to 0.
Use ADC-B0 as VDAC Specify if ADC-B0 is used as VDAC.
DAC Voltage Ref Specify the voltage reference value of VDAC.
All high voltage reference (include VDAC) can be set in the range of 2.4V to 3.3V. All low voltage reference
must be set to 0.
If ADC-B0 is used as VDAC, the DACs and Comparator DACs can use VDAC as voltage reference; otherwise
VDAC can not be selected in the DACs and Comparator DACs parameter dialogs. PSIM does not need ADC-
B0 to connect a voltage reference in schematic, but in a target system, ADC-B0 must connect to a voltage
reference.
Image:
Attributes:
Parameters Description
ADC Source Specify ADC source, it can be one of the followings: ADC-A, ADC-B, ADC-C
and ADC-D.
Chn i Gain Gain of the ith A/D converter channel, where i ranges from 0 to 5, 14, and 15.
Chn i Sample Time Specify the sample time of the A/D converter channel i, where i ranges from 0 to 5,
(us) 14 and 15.
All four ADC converters have Chn14 and Chn15, but these two channels are the same inputs. Therefore, they
can be used only in one ADC converter.
The output of the A/D converter is scaled based on: Vout = Gain * Vin, where Vin is the value at the input port
of the A/D converter.
Each ADC converter has its own voltage reference, these voltage references are specified in an ADC Voltage
Reference block. High voltage reference can be set from 2.4V to 3.3V, low voltage reference must be set to 0V.
An A/D converter can be triggered by one or more of the PWM generators, by Timer1 or by Timer2. In a
schematic, if an A/D channel is not associated with a PWM, one should connect a ZOH block at the output of
the A/D channel so that SimCoder will use the selected timer as trigger source.
Each ADC converter has up to 4 interrupts, one is in PIE Group1 with the highest interrupt priority, other 3 are
in PIE Group10 with lower interrupt priority.
If any sampling rate uses any ADC channels, SimCoder assigns an ADC interrupt for the sampling rate. If
setting parameter 'High Priority PIE Selection' to PIE group 1, SimCoder assigns the highest sampling rate to
PIE1 ADC interrupt, the other lower sampling rates use PIE group 10; If setting parameter 'High Priority PIE
Selection' to PIE group 10, SimCoder assigns the all sampling rates related to this ADC converter use PIE group
10.
If the same sampling rate uses in multiple ADC converters, SimCoder checks the total conversion time on this
sampling rate for all ADC converters, and sets the ADC converter with the longest conversion time to cause
interrupt, the other ADC converters do not need to cause interrupt. In this way all related conversions are done
10.10 Comparator
In F2837x, there are 8 comparators. They share the same ports with ADC input channels. PSIM will report an
error if a port is defined as a comparator input but is used as a A/D converter input.
Only one function can be designated for each port. Simcoder will report error if a port is defined as comparator
input but is also used as a A/D converter channel in the same PSIM circuit schematic.
Each comparator has 2 side comparators: high side and low side. For each side comparator, Input A is always
from an external analog input, side comparator's another input or the output of inner DAC. If Input B is not used
in the current element, it can be used as an ADC input.
Image:
Attributes
Parameters Description
Comparator Source Specify Comparator source, it can be one of the followings: Comparator1,
Comparator2, ..., Compartor8.
PWM Sync. Source Specify the synchronization PWM of this Comparator, it can be No PWM
sync. used or one of the PWM generators in the pull-down list
PWM’s Sync. Pos (us) Specify PWM synchronization position of this Comparator, in us. The
comparator uses the latest input value for Comparator DAC when it
receives the synchronization signal.
Comparator Usage Specify which signal is used. it can be one of the followings:
- Use TRIPH signal: Only TRIPH (TRIPOUTH) has been used.
- Use TRIPL signal: Only TRIPL (TRIPOUTL) has been used.
- Use TRIPH/TRIPL signal: Both TRIPH (TRIPOUTH) and TRIPL
(TRIPOUTL) have been used.
Input Hysteresis Selection Specify the type of hysteresis applied for input signal. This information is
ignored in simulation. It can be one of the followings:
- None: No hysteresis applied.
- Typical hysteresis: Typical hysteresis applied.
- 2x hysteresis: 2 times of hysteresis applied.
- 3x hysteresis: 3 times of hysteresis applied.
- 4x hysteresis: 4 times of hysteresis applied
High Output Invert Specify if inverting the output of high side comparator.
High Output Sync. Specify if synchronization mode of the output of high side comparator. It
can be one of the followings:
- Asynchronous: No synchronization applied.
- Sync. by SysClk: Input signal is synchronized by system clock.
- Digital filter result: Input signal is filtered.
- Latched result: Input signal is filtered and is latched when it
becomes active.
High Filter Width (us) Specify the filter window width for high side comparator, in us. This
information is valid only when 'High Output Sync.' is selected as 'Digital
filter result' or 'Latched result'.
Image:
Attributes:
Parameters Description
Comparator Source Comparator source, it can be any of the 8 comparators.
DAC Voltage Reference Voltage reference of inner DACs, it can be either 'Use VDDA(3.3V)' or
'Use VDAC'.
Image:
Attributes:
Parameters Description
Usage of DAC-x The voltage reference used by DAC-x, where x is A, B, or C. It can be one
of the followings:
- Do not use DAC-A: DAC-x is not used.
- ADC Voltage Reference: DAC-x is used in the system and ADC-x
voltage reference is chose by DAC-x.
- VDAC Voltage Reference: DAC-x is used in the system and VDAC
voltage reference is chose by DAC-x.
DAC-x Input Range The input range of DAC-x, where x is A, B, or C.
Use PWM Sync. for ADC-x Specify if DAC-x is synchronized with a PWM block, where x is A, B, or
C. The choices are Do not use or one of the PWM blocks in the pull-down
list.
DAC-x Initial Value Initial value of DAC-x, where x is A, B, or C.
If using VDAC as voltage reference, DACs and Comparator DACs can use VDAC as voltage reference;
otherwise VDAC can not be selected by DACs and Comparator DACs. Psim does not need ADC-B0 to connect
a voltage reference in schematic, but in target system, ADC-B0 must connect a voltage reference.
The voltage reference of DACs can be VDAC or the voltage reference of ADC-A/B. If VDAC is chose, ADC-
B0 must be set as VDAC. In Psim schematic, this should be only specified in Voltage Reference block, no need
to link a voltage source to ADC-B0. But in target hardware, a voltage reference should be linked to ADC-B0.
The output can be calculated as follows:
To use VDAC (the voltage reference is specified in Voltage Reference block):
DAC_Output = DAC_Input * VDAC / DAC_Range
To use ADC-A voltage reference (for DAC-A and DAC-B only):
DAC_Output = DAC_Input * Vref_ADC-A / DAC_Range
To use ADC-B voltage reference (for DAC-C only):
DAC_Output = DAC_Input * Vref_ADC-B / DAC_Range
Images:
Images:
Parameters Description
Port Position for Input i The port position of the Input i, where i is from 0 to 7. It can be any one of
the GPIO ports.
Invert the Input i Specify if the signal at Input i is inverted or not.
Parameters Description
Port Position for Output i The port position of the Output i, where i is from 0 to 7. It can be any one
of the GPIO ports.
Port Mode for Output i Port mode of the output i, where i ranges from 0 to 7. It can be any of the
followings:
- Normal output
- Output with pull-up resistor
- Open drain output
Note that each GPIO port can be used for one function only. If a GPIO port is used as a digital input port, it can
not be used as a digital output or any other peripheral port. For example, if Port GPIO1 is assigned as digital
input and it is also used as PWM1 output, an error will be reported.
Image:
Attributes:
Parameters Description
Set Gpio8*i - 8*i+7 Sample Specify if setting sample time is used for GPIO group i, where ranges from
Time 0 to 21.
Gpio8*i - 8*i+7 Sample Time The sample time for GPIO group i, where i ranges from 0 to 21. The
(us) sampling time unit is us.
Attributes:
Parameters Description
GPIO No. for Input i Specify which GPIO port is used as input X-Bar signal i
Any GPIO port used as Input X-Bar signal can also be used as any other functionality. For example, GPIO0 is
used as PWM1A, but it can also be used as Input X-Bar signal.
There are 14 input X-Bar signals, They are INPUT1, INPUT2, ..., INPUT14.
• INPUT1, INPUT2 and INPUT3 can be used as trip-zone signals: TZ1, TZ2 and TZ3.
• INPUT4, INPUT5, INPUT6, INPUT13 and INPUT14 can be used as external interrupt sources: XINT1,
XINT2, XINT3, XINT4 and XINT5.
• INPUT7, INPUT8, INPUT9, INPUT10, INPUT11 and INPUT12 can be used as capture input signals, the
corresponding input capture are Capture1, Capture2, Capture3, Capture4, capture5 and Capture6.
• INPUT1 - INPUT6 can be also used in PWM X-Bar and Output X-Bar by the following names:
INPUTXBAR1 - INPUTXBAR6.
• INPUT7 - INPUT12 can be also used in PWM X-Bar and Output X-Bar by the following names: E
CAP1OUT - ECAP6OUT.
Attributes:
Parameters Description
Output X-BAR No. Specify Output X-Bar signal. It can be one of Output1 through Output8. E
ach output can be linked to one of multiple pre-decided GPIO ports.
Invert the Output Specify if to invert the output.
SimCoder only supports the following signals as the source of the output X-Bar. Multiple input sources are
allowed. The output is the OR of all selected sources.
Attributes:
Parameters Description
PWM X-BAR No. Specify PWM X-Bar signal. It can be one of the followings: TRIP4,
TRIP5, and TRIP7 through TRIP12. There is no TRIP6.
Invert the Output Specify if to invert the output.
Signal Selection for MUXi Specify the PWM X-Bar signal, as explained below.
There are 11 PWM X-Bar signals, They are TRIP1 - TRIP5, TRIP7 - TRIP12. There is no TRIP6 signal. These
signals are used as DC trip-zone signals for PWM.
TRIP1 - TRIP3 are directly wired to TZ1 - TZ3 in Input X-Bar. The other signals need to set in the PWM X-Bar
element. SimCoder only supports the following signals as PWM X-Bar input source. Multiple input sources are
Images:
Parameters Description
Encoder Source The source of the encoder. It can be any of the 3 encoders and with any of the
GPIO port options.
Use Z Signal Define if the encoder uses the Z (or index) signal.
Use Strobe Signal Define if the encoder uses the strobe signal.
Counting Direction The counting direction
- Forward: the encoder counts up.
- Reverse: the encoder counts down.
Z Signal Polarity Define the trigger polarity of Z signal.
- Active High
- Active Low.
Strobe Signal Polarity Define the trigger polarity of strobe signal.
- Active High
- Active Low.
Encoder Resolution The resolution of the external encoder hardware. If it is 0, the encoder counter will
keep on counting and will not reset. If for example, the resolution is set to 4096,
the counter will be reset to 0 after it reaches 4095.
Parameters Description
Encoder Source The source of the encoder. It can be any of the 3 encoders and with any of the
GPIO port options.
Parameters Description
Encoder Source The source of the encoder. It can be any of the 3 encoders and with any of the
GPIO port options.
Latch Position Specify the kept counter type, choose from the followings:
- IndexPos, if the setting "Use Z Signal" is not "No" in Encoder
- StrobePos, if the setting "Use Strobe Signal" is not "No" in Encoder
Type of Position This can be chosen from the followings:
- The first latched position, or
- The current latched position
Image:
Parameters Description
Counter Source The source of the counter. It can be any of the 3 encoders and with any of the
GPIO port options listed in the pull-down menu.
There are two inputs for Up/Down Counter:
• Input "Clk" refers to the input clock signal.
• Input "Dir" refers defines the counting direction.
When the "Dir" input is 1, the counter counts forward (up), and when the input is 0, the counter counts
backward (down).
The output of the up/down counter is the counter value.
Note that the up/down counter shares the same input GPIO ports with the encoder. Therefore, using both
encoder and up/down counter on the same GPIO ports is not allowed.
Image:
Parameters Description
Capture Source Source of the capture. It may come from one of the six captures.
Event Filter Prescale Event filter prescale. The input signal is divided by the selected prescale.
Timer Mode Capture counter timer mode. It can be one of the followings:
- Absolute time: The output is the absolute time in system clock
- Time difference (clock): The output is the difference between the current event
and the previous event, in system clock.
- Time Difference (us): The output is the difference between the current event and
the previous event, in us.
A capture can generate interrupt, and the interrupt trigger mode is defined in the interrupt block. If there is no
the corresponding interrupt block in the schematic, Capture will catch rising edge only.
Capture input comes from Input X-Bar, so if a capture is used in the system, the corresponding input signal of
Input X-Bar must be defined too.
Parameters Description
Capture Source Source of the capture. It has only one source Capture1.
The Capture State block indicates the triggering state of the capture. Its output is either 1 or 0. 1 means the
rising edge and 0 means the falling edge.
Images:
Attributes:
Parameters Description
Port Selection F2803x has 4 groups of ports that can be used for SCI functions: Group A, B, D
and D. Each group has different port options, as listed in the pull-down menu.
Speed (bps) SCI communication speed, in bps (bits per second). A list of preset speeds is
provided at 200000, 115200, 57600, 38400, 19200, or 9600 bps. Or one can
specify any other speed manually.
Parity Check The parity check setting for error check in communication. It can be either None,
Odd, or Even.
Output Buffer Size Size of the data buffer allocated in DSP for SCI. The buffer is located in the RAM
area, and each buffer cell stores one data point which consists of three 16-bit words
(that is, 6 bytes, or 48 bits, per data point).
Note that the buffer size should be properly selected. On one hand, a large buffer is preferred in order to collect
more data points so that more variables can be monitored over a longer period of time. On the other hand, the
internal DSP memory is limited, and the buffer should not be too large to interfere with the normal DSP
operation.
Attributes:
Parameters Description
Initial Value The initial value of the SCI input variable.
In the schematic, the SCI input behaviors as a constant. While its value can be changed at runtime when the
code is running on the DSP target. The value will be fixed at the initial value in simulation.
Attributes:
Parameters Description
Data Point Step It defines how frequent data is collected. If the Data Point Step is 1, every data
point is collected and transmitted. If the Data Point Step is 10, for example, only
one point out of every 10 points is collected and transmitted.
Note that if the Data Point Step is too small, there may be too many data points and it may not be possible to
transmit them all. In this case, some data points will be discarded during the data transmission.
Also, the Data Point Step parameter is used only when then DSP Oscilloscope is in the continuous mode. When
it is in the snap-shot node, this parameter is ignored and every point is collected and transmitted.
In simulation, the SCI output behaviors as a voltage probe.
Images:
Attributes:
Parameters Description
SPI Port Define the SPI port from the options. There are three SPI ports: SPIA, SPIB, and
SPIC. Each SPI port has a few GPIO pin selections listed in the pull-down menu.
Attributes:
Parameters Description
Chip Select Pins The state of the chip select pins corresponding to the SPI device. When the chip
select pins are at this state, this SPI device is selected.
Communication Speed SPI communication speed, in MHz.
(MHz)
Clock Type SPI clock type, as determined by the SPI hardware device. It can be one of the
following:
- Rising edge without delay: The clock is normally low, and data is latched at the
clock rising edge.
- Rising edge with delay: The clock is normally low, and data is latched at the
clock rising edge with delay.
- Falling edge without delay: The clock is normally high, and data is latched at
the clock falling edge.
- Falling edge with delay: The clock is normally high, and data is latched at the
clock falling edge with delay.
Command Word Word length, or the length of the significant bits, of SPI communication
Length commands. It can be from 1 to 16 bits.
Sync. Active Mode The triggering mode of the synchronization signal of the SPI device. It can be
either Rising edge or Falling edge.
SPI Initial Command The SPI command that initializes the SPI device.
Hardware Interrupt Specify the type of the interrupt signal that the SPI device generates. This is valid
Mode only when the SPI device’s interrupt output node is connected to the input of a
digital output element. It can be one of the following:
- No hardware interrupt
- Rising edge
- Falling edge
Attributes:
Parameters Description
Device Name Name of the SPI input device.
Start Conversion Command to start conversion, in hex numbers, separated by comma (for example,
Command 0x23,0x43,0x00).
Receiving Data Command to receive data, in hex numbers, separated by comma (for example,
Command 0x23,0x43,0x00).
Scale Factor Output scale factor Kscale. If the scale factor is 0, the SPI device is not an A/D
converter, and the result will be exactly the same as what DSP receives from SPI
communication. Otherwise, the SPI device is an A/D converter, and the result is
scaled based on this factor and the A/D conversion mode.
ADC Mode The A/D conversion mode of the device. It can be either DC or AC. Note that this
parameter is valid only when the device is an A/D converter.
Initial Value The initial value of the input.
The formula for the Data Bit Position defines the data length of a SPI input device. For example,
y=x1[3..0]x2[7..0], means that the data length is 12, and the result is the lower 4 bits of the 2nd word and the
lower 8 bits of the 3rd word. If the received data string is 0x12,0x78,0xAF, then the result is 0x8AF.
If the scale factor is not 0, the output will be scaled based on the following:
In the DC conversion mode:
- In simulation: Output = Input K scale
Data_Length
2
In the AC conversion mode:
) V max Ksc al e
- In hardware: Output = (Result – 2Data_Length-1 ------- ---------
-----------------------
The parameter Data_Length is calculated from the Data Bit Position formula.
Attributes:
Parameters Description
DAC Mode The D/A conversion mode of the device. It can be either DC or AC. Note that this
parameter is valid only when the device is a D/A converter.
Sending Data Command to send the output data, in hex numbers, separated by comma (for
Command example, 0x23,0x43,0x00).
Data Bit Position Define where the data bits are in the sending data string. The format is:
ElementName = {Xn[MSB..LSB]}
where
- ElementName is the name of the SPI output device. If it is the current SPI
output device, use y instead.
- {} means that the item in the bracket repeats multiple times.
- Xn is the nth word sent to the SPI output device, and n start from 0.
- MSB..LSB defines the position of the significant bits in the word.
Sync. Command The command to synchronize output channels of the SPI output device, in hex
numbers, separated by comma (for example, 0x23,0x43,0x00). This command is
used when the SPI output device does not have the synchronization signal
The formula for the Data Bit Position defines the data length of a SPI output device. For example,
y=x1[3..0]x2[7..0], means that the data length is 12, and the data is the lower 4 bits of the 2nd word and the
lower 8 bits of the 3rd word. If the sending data string is 0x12,0x78,0xAF, then the data is 0x8AF.
If the scale factor is not 0, the output will be scaled based on the following:
In the DC conversion mode:
- In simulation: Output = Input K scale
V max
In the AC conversion mode:
--------------------------- -----------
V max
The parameter Data_Length is calculated from the Data Bit Position formula.
Images:
Parameters Description
CAN Source There are 2 sets of CAN devices on F2837x MCU: CAN A and CAN B. Each has
multiple GPIO selections in the pull-down list.
CAN Speed Communication speed, in Hz. It can be set to one of the following preset values:
125kHz, 250kHz, 500kHz, and 1MHz
Or you can set the speed manually by typing the text in the parameter field. Note
that the speed should not exceed 1MHz.
Data Byte Order The order of the data bytes. It can be one of the following:
- Least significant byte 1st: the least significant byte is placed first
- Most significant byte 1st: the most significant byte is placed first.
Number of Input Number of input mailboxes
Mailboxes
Checking Receive Mail If it is set to Enable, the error report function "_ProcCanAErrReport(nErr)" (for
Lost CAN A) will be called if the received mail is lost. This function will return the
value of the error status nErr from the CAN register CANGIF0.
If it is set to Disable, the error report function will not be called.
Checking Bus Off If it is set to Enable, the error report function "_ProcCanAErrReport(nErr)" (for
CAN A) will be called if the bus is in the off state. This function will return the
value of the error status nErr from the CAN register CANGIF0.
If it is set to Disable, the error report function will not be called.
Error Check Mode The error check mode can be either Passive or Active. If it is in the error-passive
mode, an interrupt will be generated when the error count reaches 128. If it is in
the error-active mode, an interrupt will be generated every time.
The returned status nErr in the function "_ProcCanAErrReport(nErr)" (for CAN A) is a 32-bit integer. It obtains
its value from the Global Interrupt Flag Register CANGIF0. After returning from the function "_ProcCanAE
rrReport(nErr)", the register CANGIF0 will be cleared.
Also, if you wish to take actions on a specific error, you can add your own code within the "_ProcCanAE
rrReport(nErr)" function.
Attributes:
Parameters Description
Number of Inputs Number of CAN inputs. It can have up to 8 inputs.
CAN Source The source of CAN input, either CAN A or CAN B
Use Extension ID If this is set to Yes, the ID of a message is a 29-bit integer. If this is set to No, the ID
of a message is a 11-bit integer.
Message ID The ID of a message. It is an integer, for example, 0x23.
Local Mask The mask for the message. It is an integer. If the bits of the message ID matches
the bits of the mask, the message will be received. Otherwise, it will be ignored.
For example, if the mask is 0x380 and the message ID is 0x389, this message will
be received. But if the message ID is 0x480, the message will be ignored.
Attributes:
Parameters Description
Number of Outputs Number of CAN outputs. It can have up to 8 outputs.
CAN Source The CAN source can be either CAN A or CAN B.
Use Extension ID If this is set to Yes, the ID of a message is a 29-bit integer. If this is set to No, the ID
of a message is a 11-bit integer.
Message ID The ID of a message. It is an integer, for example, 0x23.
Trigger Type The trigger type can be one of the following:
- No trigger: No triggering
- Rising edge: Triggering occurs at the rising edge of the trigger source.
- Falling edge: Triggering occurs at the falling edge of the trigger source.
- Rising/falling edge: Triggering occurs at both the rising edge and the falling
edge of the trigger source.
A rising/falling edge is considered to have occurred if the difference between the
current value of the trigger source and the value at the last triggering instant is
equal to or greater than 1.
Attributes:
Parameters Description
CAN Source The source of CAN input, either CAN A or CAN B
Use Extension ID If this is set to Yes, the ID of a message is a 29-bit integer. If this is set to No, the ID
of a message is a 11-bit integer.
Message ID The ID of a message. It is an integer, for example, 0x23.
Trigger Type The trigger type can be one of the following:
- No trigger: No triggering.
- Rising edge: Triggering occurs at the rising edge of the trigger source.
- Falling edge: Triggering occurs at the falling edge of the trigger source.
- Rising/falling edge: Triggering occurs at both the rising edge and the falling
edge of the trigger source. A rising/falling edge is considered to have occurred
if the difference between the current value of the trigger source and the value at
the last triggering instant is equal to or greater than 1.
Trigger Source A trigger source can be either a constant or a global variable depending on the
Trigger Type.
If the Trigger Type is set to "No trigger", the trigger source defines the counter
limit. For example, if the trigger source is a constant or a global value, and the
value is 5, it means that triggering will occur once out of every 5 times. In another
word, the data will be sent out once per every 5 cycles.
If the Trigger Type is set to edge trigger, the trigger source can only be a global
variable. Triggering will occur when the global variable has the rising or falling
edge or both depending on the Trigger Type.
Frequency The sampling frequency.
Attributes:
Parameters Description
Time Output Method Define how interrupt time is measured. It can be one of the following:
- SCI (time used): Using SCI. Time used by the interrupt service routine, in DSP
clock count, is measured and is sent out via SCI output.
- SCI (time remaining): Using SCI. Time remaining in the interrupt service
routine, in DSP clock count, is measured and is send out via SCI output. The
time remaining is defined as the time from the end of the current interrupt to
the beginning of the next interrupt.
- GPIO0 to GPIO44, or AIO2 to AIO14: Using a GPIO port. A pulse is
generated at the specified GPIO port. The pulse is set to high when entering the
interrupt, and set to low when exiting the interrupt. An oscilloscope can be
used to measure the width of the pulse.
Sampling Frequency Sampling frequency of the interrupt service routine, in Hz.
When SCI is used, the value is the count of the DSP clock. For example, if the value is 7500, for a 90-MHz DSP
clock, the interrupt time will be:
7500 / 90M = 83.33us
Project Setting:
In the Code Composer Studio project file, the following settings are provided:
- RAM Debug: To compile the code in the debug mode and run it in the RAM memory
- RAM Release: To compile the code in the release mode and run it in the RAM memory
- Flash Release: To compile the code in the release mode and run it in the flash memory
11.1 Overview
With the F28004x Hardware Target, SimCoder can generate code that is ready to run on any hardware boards
based on Texas Instruments’ F28004x 32-bit floating-point microcontroller unit (MCU).
This chapter describes the definitions and usage of the elements in the F28004x Hardware Target library.
The F28004x Hardware Target library includes the following function blocks:
- PWM generators: 3-phase, 2-phase, 1-phase, and APWM
- Variable frequency PWM
- Start/Stop functions for PWM generators
- PWM trip-zone and trip-zone state
- A/D converter
- ADC voltage reference
- PGA and PGA gain
- Comparator input, output, and DAC
- DAC converter
- Digital input, output, and sample time
- Input X-BAR, output X-BAR, and PWM X-BAR
- Encoder, encoder state, and encoder index/strobe position
- Up/Down counter
- Capture and capture state
- SCI configuration, Input, and output
- SPI configuration, device, input, and output
- CAN configuration, input, output, and remote request
- Interrupt Time
- DSP clock
- Hardware configuration
When generating the code for a system that has multiple sampling rates, SimCoder will use the interrupts of the
PWM generators for the PWM sampling rates. For other sampling rates in the control system, it will use the
Timer 1 interrupt first, and then Timer 2 interrupt if needed, If there are more than three sampling rates in the
control system, the corresponding interrupt routines will be handled in the main program by software.
In TI F28004x, PWM generators can generate hardware interrupt. SimCoder will search and group all the
elements that are connected to the PWM generator and have the same sampling rate as the PWM generator.
These elements will be automatically placed and implemented in an interrupt service routine in the generated
code.
In addition, digital input, encoder, capture, and trip-zone can also generate hardware interrupt. Each hardware
interrupt must be associated with an interrupt block (described in Section 4.5 of this Manual), and each interrupt
block must be associated with an interrupt service routine (a subcircuit that represents the interrupt service
routine). For example, if a PWM generator and a digital input both generate interrupt, there should be one
interrupt block and one interrupt service routine for each of them.
The F28004x Hardware Target will work with all F28004x packages. The figure below shows the F28004x 100-
pin PZ package port assignment. Only the GPIO functions are show on GPIO pins. The other port functions will
be explained in next section about hardware configuration.
Image:
The Hardware Configuration block is for user to specify the I/O ports usage of the F28004x hardware. Every
port in use must be assigned correctly. The ports not in use can be left unchecked.
To make changes, click on the button Unlock. After changes are made, click on Lock to lock the configuration.
Analog Subsystem:
In the analog subsystem, each port has several functionalists, and each functionality is independent of others.
One may use any or all functions in one system.
For example, Pin "A2/B6/PGA1_OF" can be used accepting inputs from: ADC-A2, AC-B6, and PGA1_OF.
And it can be used as AIO224 input/output.
If multiple functionality boxes are checked, in corresponding ports/pins must be connected in the circuit
schematic.
GPIO Ports:
All GPIO ports are set to low at the start up by default. If any GPIO needs to start high, the box "Initial High"
must be checked.
For each GPIO port, a check box is provided for each of its available function. Multiple boxes can be checked if
Image:
Attributes:
11.4.1 3-Phase PWM, 1-phase PWM, and 1-phase PWM (phase shift)
The 3-phase PWM generator consists of three 1-phase PWM blocks of consecutive order. Therefore, the
attributes for 3-phase PWM block, 1-Phase PWM block and 1-phase PWM (phase shift) block are mostly
the same.
The difference between the 1-Phase PWM and 1-phase-PWM (phase shift) blocks is how the phase shift is
defined. The 1-phase PWM block defines the phase shift through a parameter which is a constant, while the 1-
Phase PWM (phase shift) block reads the phase shift from an external input (labeled as "phase" in the image).
The phase shift is in degree.
In the 3-phase PWM generator image, "u", "v", and "w" refer to the three phases (alternatively they are called
phase "a", "b", and "c"). The letter "p" refers to the positive output, and "n" refers to the negative output. For
example, for 3-phase PWM 123, "up" is PWM1A, and "un" is PWM1B.
Image:
Attributes:
Parameters Description
PWM Source Source of the PWM generator. Each 1-phase PWM block has two outputs (PWM A
and PWM B) assigned to two GPIO pins. Each 3-phase PWM module consists of
three 1-phase PWM blocks. For example, 3-phase PWM 123 (GPIO0-5) consists of
PWM1, PWM2, an PWM3. Therefore, each 3-phase PWM uses 6 GPIO pins.
Output Mode Output mode of the PWM generator. It can be one of the following:
(Not used for 3-phase) - Use PWM A&B: Both PWM outputs A and B are used,.
- Use PWM A: Only PWM output A is used.
- Use PWM B: Only PWM output B is used.
- No PWM output: No PWM output is used (As a timer).
Sampling Frequency Sampling frequency of the PWM generator, in Hz. The calculation is done and the
PWM signal duty cycle is updated based on this frequency.
PWM Freq. Scaling The ratio between the PWM switching frequency and the sampling frequency. It
Factor can be from 1 to 15. For example, if the sampling frequency is 50 kHz and the
scaling factor is 3, the PWM switching frequency will be 150 kHz. That is switches
will operate at 150 kHz. But gating signals will be updated at 50 kHz, or once per 3
switching cycles.
Carrier Wave Type Carrier wave type and the initial PWM output state. It can be one of the following:
- Triangular (start low): Triangular wave, and the initial PWM output state is
low.
- Triangular (start high): Triangular wave, and the initial output state is high.
- Sawtooth (start low): Sawtooth wave, and the initial output state is low.
- Sawtooth (start high): Sawtooth wave, with the initial output state is high.
Trigger ADC Setting whether for the PWM generator to trigger the A/D converter. It can be one
of the followings:
- Do not trigger ADC: PWM does not trigger the A/D converter.
- Trigger ADC: PWM triggers the A/D converter channel (channels)
connected to this PWM module.
ADC Trigger Position A/D trigger position ranges between 0 and 1. When it is 0, the A/D converter is
triggered at the beginning of the PWM cycle, and when it is 0.5, the A/D converter
is triggered at the 180o position of the PWM cycle.
Use Trip-Zone 1, 2, 3 Define whether the PWM generator uses the trip-zone signal or not. It can be one
of the followings:
- Do not use: Disable the ith trip-zone signal.
- One shot: The PWM generator uses the trip-zone signal in the one-shot
mode. Once triggered, the PWM must be started manually.
- Cycle by cycle: The PWM generator uses the trip-zone signal in the cycle-by-
cycle basis. The trip-zone signal is effective within the current
cycle, and PWM will automatically re-start in the next cycle.
Select Trip Events Specify the combination of DC trip events applied to the current PWM. It can be
one or any combination of DCAEVT1, DCAEVT2, DCBEVT1, and DCBEVT2.
Trip Action Define how the PWM generator responds to the trip action. It can be one of the
followings:
- High impedance: PWM outputs in high impedance
- PWM A high & B low: Set PWM A high and B low.
- PWM A low & B high: Set PWM A low and B high.
- PWM A both high: Set both PWM A and B high (not used for 3-phase).
- PWM A both low: Set both PWM A and B low (not used for 3-phase).
- No action: No action taken.
Peak-to-Peak Value Carrier wave peak-to-peak value Vpp, in V.
239 Chapter 11: F28004x Hardware Target
Offset Value Carrier wave DC offset value Voffset, in V.
Initial Input Value (u, Initial value of the PWM block. For three initial input values are set for 3-phase
v, w for 3-phase) PWM block’s three inputs u, v, and w.
Phase Shift Phase shift of the output with respect to the reference PWM generator output, in
(for 1-phase only) deg. For example, when the phase shift is -30, the output will be shifted to the right
(lagging) by 30 deg. with respect the reference PWM output.
Use HRPWM Define the high-resolution PWM. It can be one of the followings:
(Not used for 3-phase) - Do not use HRPWM: Do not use high-resolution PWM
- Use HRPWM without calibration: Use high-resolution PWM without
calibration
- Use HRPWM with calibration: Use high-resolution PWM with calibration
Start PWM at When it is set to Start, PWM will start right from the beginning. If it is set to Do not
Beginning start, one needs to start PWM using the Start PWM block.
Simulation Output The simulation output mode can be set to either of the followings:
Mode - Switching mode: the outputs of the PWM block are PWM signals.
- Average mode: the outputs of the PWM block are average mode signals.
In the average mode, if the carrier wave is from negative to positive, and the
absolute values of the negative peak and the positive peak are equal (for example,
the carrier wave is from -1 to +1, or from -5 to +5), the modulation is considered as
an ac signal modulation. Otherwise, the modulation is considered as a dc signal
modulation. For example, modulation in a 3-phase or single-phase inverter is an ac
modulation, and modulation in a buck converter is a dc modulation.
In the ac signal modulation, if the input u of the PWM block is Vu, the output up
and un in average mode will be:
Vup = Vu / (Vpp + Voffset)
Vun = -Vup
In this case, Vu is between -(Vpp+Voffset) and (Vpp+Voffset), and Vup is between -1 to
+1.
In the dc signal modulation, the output up and un in average mode will be:
Vup = (Vu - Voffset) / Vpp
Vun = 1 - Vup
In this case, Vu is between Voffset and Vpp+Voffset, and Vup is between 0 to +1.
When it is set to the average mode, the PWM block outputs can be connected to a
converter/inverter in the average mode model.
Phase Shift
A 1-phase PWM generator can generate PWM signal that is phase shifted with respect to another PWM signal.
The way how PWM blocks are defined for phase shift is explained in Section 8.4.5.
The phase shift value is in degrees. When the value is -30o, the output will be shifted to the right (lagging) by
30o of the switching cycle with respect to the reference PWM generator output. This is equivalent to shifting the
PWM carrier wave to the right by 30o. When the phase value is 30o, the output will be shifted to the left
(leading) by 30o.
Carrier Wave
There are two types of carrier waveforms: triangular wave (with equal rising and falling slope intervals) and
sawtooth wave. In addition, there are two operation modes: start-low and start-high modes, as explained below.
PWM Vpp H m L
input vm Vpp
VL
VVoffset
L
Voffset t t
P
Td PWMxA WMxA
x = 1, 2, ..., 6
Td PWMxB PWMxB
The input and output waveforms of a PWM generator with the sawtooth carrier wave are shown below:
PWM Vpp H m L
input vm Vpp
VL VL
Voffset t t
Td Voffset
PWMxA PWMxA
x = 1, 2, ..., 6
Td PWMxB
PWMxB
The figures above show how the dead time is defined, and the time sequence when the PWM generator triggers
the A/D converter. If triggering the A/D converter is selected, from the start of the PWM cycle, after a certain
delay defined by the A/D trigger position, the A/D conversion will start. After the A/D conversion is completed,
the PWM interrupt service routine will start.
If the PWM generator does not trigger the A/D converter, the PWM interrupt service routine will start at the
beginning of the PWM cycle.
241 Chapter 11: F28004x Hardware Target
The figures above also show how the start-high and start-low modes work. Assume that the PWM input is vm,
and the lowest value of the carrier wave is VL and the highest value is VH. In the start-high mode, the PWM
positive output PWMA is high at the beginning of the switching cycle, and it remains high as long as the input
vm is greater than the carrier wave. For example, for a carrier wave from 0 to 1, VL=0, and VH=1. If vm=0.2, the
PWM output PWMA will remain high as long as the carrier is less than 0.2.
On the other hand, in the start-low mode, the PWM positive output PWMA is low at the beginning of the
switching cycle, and it is high when the carrier wave is greater than the value VH-(vm-VL). For example, for a
Conditioning circuit
Note: In the start-low mode, the PWM input vm is converted to VH-(vm-VL) internally before it is compared with
the carrier wave to generate the PWM signal. With the conversion, both the start-low and start-high modes will
have the same duty cycle expression. For example, for a sawtooth wave with VL=0 and VH=1, or for a triangular
wave with VL= -VH, the duty cycle D of the PWMA output in both the start-low and start-high modes is:
D = vm/VH.
The PWM dead band acts as below.
Image:
Attributes:
Parameters Description
PWM Source Source of the PWM generator. It can be PWM 1 to PWM 8.
Sampling Frequency Sampling frequency of the PWM generator, in Hz. The calculation is done
and the PWM signal duty cycle is updated based on this frequency.
PWM Freq. Scaling Factor The ratio between the PWM switching frequency and the sampling
frequency. It can be from 1 to 15. For example, if the sampling frequency
is 50 kHz and the scaling factor is 3, the PWM switching frequency will be
150 kHz. That is switches will operate at 150 kHz. But gating signals will
be updated at 50 kHz, or once per 3 switching cycles.
Carrier Wave Type There are 2 kind of carrier wave types: Sawtooth and Triangular
PWMxA Output Mode PWMxA and PWMxB output mode can be one of the followings:
PWMxB Output Mode - Do nothing: PWM output is not affected by PWM duty cycle
value.
- Toggle at valley: PWM output toggles at the beginning of PWM
period.
- Toggle at peak: PWM output toggles at the peak of PWM carrier
wave.
- Toggle at peak/valley: PWM output toggles at both of the peak/valley
of PWM carrier wave.
- Set/Reset at valley/peak: PWM output set to high at the valley, and reset
to low at the peak of the carrier wave
- Reset/Set at valley/peak: PWM output reset to low at the valley, and set
to high at the peak of the carrier wave.
- Set at valley: PWM output set to high at the beginning of PWM period.
- Reset at valley: PWM output reset to low at the beginning of PWM
period.
- Set at peak: PWM output set to high at the peak of the carrier wave.
- Reset at peak: PWM output reset to low at the peak of the carrier wave.
Trigger ADC Setting whether for the PWM generator to trigger the A/D converter. It can
be one of the following:
- Do not trigger ADC: PWM does not trigger the A/D converter.
- Trigger ADC: PWM will trigger the A/D converter.
ADC Trigger Position A/D trigger position ranges from 0 to a value less than 1. When it is 0, the
A/D converter is triggered at the beginning of the PWM cycle, and when it
is 0.5, the A/D converter is triggered at the 180o position of the PWM
cycle.
T1 Source T1 and T2 event sources for PWM trip actions, can be one of the
T2 Source followings:
- Do not use,
- DCAEVT1,
- DCAEVT2,
- DCBEVT1,
- DCBEVT2,
- TZ1,
- TZ2,
- TZ3.
PWMxA Action at T1(Up) PWMxA (PWMxB) output can be forced at the following actions when T1
PWMxA Action at T1(Down) (T2) event occurs at PWM waveform up (down) count period:
- Do nothing,
PWMxB Action at T1(Up)
- Clear,
PWMxB Action at T1(Down) - Set,
PWMxA Action at T2(Up) - Toggle.
PWMxA Action at T2(Down)
PWMxB Action at T2(Up)
PWMxB Action at T2(Down)
The 2-phase PWM generator generates two PWM signals with specific configurations for typical power
converter applications. The PWM carrier wave is either sawtooth or triangular, it ranges from 0 to the peak
value Vpk.
PWM module's control flow is as follows:
Image:
Attributes:
Parameters Description
PWM Source Source of the PWM generator. It can be any from APWM1 to APWM7
PWM Frequency Frequency of the PWM generator, in Hz
Carrier Wave Type The carrier wave type and the initial PWM output state. It can be one of the
following:
- Sawtooth (start low): Sawtooth wave, with the PWM output in the low state
initially.
- Sawtooth (start high): Sawtooth wave, with the PWM output in the high state
initially.
Stop Action The output status when the PWM generator is stopped. It can be one of the
following:
- Output low: The PWM output will be set to low.
- Output high: The PWM output will be set to high.
Peak-to-Peak Value Peak-to-peak value of the carrier wave
Offset Value DC offset value of the carrier wave
Phase Shift Phase shift of the output with respect to the reference PWM generator, in deg.
Initial Input Value Initial value of the input
Start PWM at When it is set to Start, PWM will start right from the beginning. If it is set to Do
Beginning not start, one needs to start PWM using the Start PWM block.
Similar to 1-phase PWM generators, an APWM generator can generate a PWM signal that has a phase shift
with respect to another PWM generator. The way how PWM blocks are defined for phase shift is explained in
Section 11.4.4.
- The master PWM can be EPWM1, EPWM4, EPWM7, APWM1, APWM4 and APWM6.
- Any subsequent EPWM or APWM can be slave block of the preceding EPWMs or APWMs in E
PWM1, EPWM4, EPWM7, APWM1, APWM4 and APWM6 series.
- Any EPWM or APWM that is not master EPWM or APWM can be the slave if its close preceeding E
PWM or APWM block is a master EPWM or APWM.
- Any EPWM or APWM that is not master EPWM or APWM can be the salave if its preceding EPWM
or APWM is a slave EPWM or APWM block
The correct phase shift sequences are as follows:
1. EPWM1, EPWM2, EPWM3
2. EPWM1, EPWM2, EPWM4, EPWM5, EPWM6
3. EPWM4, EPWM7, EPWM8
4. EPWM1, APWM1, APWM2, APWM3
5. EPWM7, APWM4, APWM5, APWM6, APWM7
Image:
Parameters Description
PWM Source Source of the PWM generator. It can be one listed in the pull-down menu.
Adjust Interrupt Pos. Specify if the interrupt position is adjusted with the frequency. It can be one of the
following:
- Do not adjust: The interrupt position will remain unchanged as calculated with
the base frequency.
- Adjust: The interrupt position will be recalculated at the beginning of
each cycle based on the new frequency.
Adjust Ramp Specify if the ramp compensation of the comparator DAC block is adjusted with
Compensation the frequency. It can be one of the following:
- Do not adjust: The ramp compensation will remain unchanged as calculated
with the base frequency.
- Adjust: The ramp compensation will be recalculated at the beginning of
each cycle based on the new frequency.
The sampling frequency of the corresponding PWM block will be changed at the beginning of the next PWM
period as follows:
PWM_Frequency = PWM_Base Frequency / Input_Value
where PWM_Base_Frequency is the sampling frequency of the corresponding PWM block, and Input_Value is
the input value of this block.
If the interrupt position is to be adjusted, the interrupt position will be recalculated in each cycle. Since
adjusting the interrupt position takes time, if the frequency change is small, it is recommended not to adjust the
interrupt position.
Similarly, if the ramp compensation is to be adjusted, the ramp compensation will be recalculated in each cycle.
Since adjusting the ramp compensation takes time, if the frequency change is small, it is recommended not to
adjust the ramp compensation.
Image:
Attributes:
Parameters Description
PWM Source The source of the PWM generator. It can be any of PWM blocks or captures in the
pull-down list
Image:
Parameters Description
PWM Source Source of the PWM generator. It can be any of the PWM blocks in the
pull-down list.
DC Trip Source1(DCAH) Specify the digital compare (DC) trip source DCAH for PWMxA. The
DC Trip Source2(DCAL) PWM channel may have up to two DC trip sources: DCAH and DCAL.
The trip source can be one of the following:
DC Trip Source1(DCBH)
- Do not use: PWM doesn't use this signal.
DC Trip Source2(DCBL)
- TZ1(T1): PWM uses trip-zone 1 as digital compare input signal.
- TZ2(T2): PWM uses trip-zone 2 as digital compare input signal.
- TZ3(T3): PWM uses trip-zone 3 as digital compare input signal.
- TRIP4(T4): PWM uses TRIP4 as digital compare input signal.
- TRIP5(T5): PWM uses TRIP5 as digital compare input signal.
- TRIP7(T7): PWM uses TRIP7 as digital compare input signal.
- TRIP7(T8): PWM uses TRIP8 as digital compare input signal.
- TRIP7(T9): PWM uses TRIP9 as digital compare input signal.
- TRIP10(T10): PWM uses TRIP10 as digital compare input signal.
- TRIP11(T11): PWM uses TRIP11 as digital compare input signal.
- TRIP12(T12): PWM uses TRIP12 as digital compare input signal.
- T1 - T5
- T7 - T12
- T5 | T8 | T11.
Note: when defining the interrupt block associate with trip-zone, the "Device Name" parameter of the interrupt
block should be the name of the PWM generator, not the trip-zone block name. For example, if a PWM
generator called "PWM_G1" uses trip-zone 1 in the trip-zone block "TZ1". The "Device Name" of the
corresponding interrupt block should be "PWM_G1", not "TZ1". The "Channel Number" parameter in the
interrupt block is not used in this case.
The trip-zone interrupt can be generated in either one-shot mode of cycle-by-cycle mode, as defined in the
PWM generator parameter input. In the cycle-by-cycle mode, the interrupt only affects the PWM output within
the current PWM cycle. On the other hand, in the one-shot mode, interrupt triggers a trip action when the input
signal is low (0). will set the PWM output permanently, and the PWM generator must be restarted to resume the
operation.
Parameters Description
PWM Source Source of the PWM generator. It can be any one in the pull-down list
The trip-zone state element is usually used in the trip-zone interrupt routine to indicate the operation mode of
the trip-zone signal. When the output of this element is 1, it indicates that the trip-zone signal is in one-shot
mode. When the output is 0, the trip-zone signal is in cycle-by-cycle mode.
Image:
Attributes:
Parameters Description
ADC-A Vol. Ref. Usage Specify the voltage reference to be used for each A/D converter,:
ADC-B/C Vol. Ref. Usage External VRef
Internal VRef (1.65V)
Internal VRef (2.5V)
ADC-A High Voltage Ref. Specify the external high voltage reference for ADC. The value must be in
ADC-B/C High Voltage Ref. the range of 2.4V to 3.3V.
All high voltage reference (include VDAC) can be set to 2.4V to 3.3V.
If "Use ADC-B3 as VDAC" is set as Yes, DACs and Comparator DACs can use VDAC as voltage reference.
Otherwise, VDAC can not be selected by DACs and Comparator DACs. PSIM does not need ADC-B3 to
connect a voltage reference in schematic, but in target system, ADC-B3 must connect a voltage reference.
Attributes:
Parameters Description
ADC Source Specify ADC source, it can be one of ADC-A, ADC-B and ADC-C.
Chn i Gain Gain of the ith A/D converter channel, where i ranges from 0 to 15.
Chn i Sample Time (us) Specify the sample time of the A/D converter channel i, where i ranges
from 0 to 15.
Conversion Order Order of the A/D conversion. If the field is left blank (undefined), the
conversion will be done based on the sequential numbers of the A/D
channel. For example, if A0, A2, A4, A14, and A15 are used, the
conversion will be done in this order: A0, A2, A4, A14, and A15.
To rearrange the sequence, write the order here. For example, if the
conversion order is defined as:
A4,A0,A2,A14,A15
The conversion order will be A4 before A0, and A0 before A2, and so on.
Any channels can be specified multiple times, as long as the total
conversion number does not exceed 16. For example, if the order is
A4,A4,A4,A0,A2,A14,A15
Channel A4 will be converted 3 times, then A0, A2, etc.
If there is a '-' prefix before any channel name, this channel will be
converted but the data will be discarded. For example, if the order is
-A4,A4,A4,A0,A2,A14,A15
Channel A4 will be converted 3 times, but its first conversion data will be
discarded.
If any channel is converted multiple times, the channel's final data will be
the average value in this conversion sequence (the discarded conversion
data is not included).
High Priority PIE Selection Specify if the highest priority interrupt uses PIE Group1 or PIE Group10.
In this table:
(1)(2) Internal connection only, does not come to a device pin.
(3) PGA functionality not available on 64-pin or 56-pin packages.
SimCoder allows one input signal used by multiple devices, for example, from the table above, there is a pin
named A2/B6/PGA1_OF, that means PGA1_OF has internally connected to ADCA2 and ADCB6. If the
schematic uses PGA1 then ADCA2 and/or ADCB6 can be use PGA1_OF by connecting PGA1_OF to ADCA2
and/or ADCB6. Since PGA1_OF connects to PGA1 output through a resistor, SimCoder doesn't report an error
message if ADCA2 and/or ADCB6 use another signal other than PGA1_OF, but ADCA2 and ADCB6 should
use the same input signal if the schematic uses both channels.
Some ADC input channels are connected to PGAx_OUT internally, one can only connect PGAx_OUT to the
ADC channel, connect any other signal to this kind of ADC channels results an error message reported on
SimCoder.
Each ADC converter has up to 4 interrupts, one is in PIE1 with the highest interrupt priority, other 3 are in PIE
10 with lower interrupt priority.
If any sampling rate uses any ADC channels, SimCoder assigns an ADC interrupt for the sampling rate. If
Images:
Attributes of PGA:
Parameters Description
PGA Source Specify PGA source, it can be one of the followings: PGA1, PGA2, ...,
PGA7.
Default Gain Specify PGA's default gain. The options are: 3 times, 6 times, 12 times and
24 times.
Filter Usage Specify the resistor between PGA output and PGAx_OF. The options are:
Disabled, 200ohm, 160ohm, 130ohm, 100ohm, 80ohm and 50ohm.
Attributes for PGA Gain:
Parameters Description
PGA Source Specify PGA source, it can be one of the followings: PGA1, PGA2, ...,
PGA7.
For each PGA, the voltage reference is VDDA(+3.3V). Each PGA has 2 outputs, one named PGAx_OUT and it
is internally connected to ADC input channel, or comparator input; another is PGAx_OF which shares the same
pin with the specific channels of ADC and Comparator.
The gain of a PGA can be controlled but the PGA Gain block. The input and the gain relationship is defined as:
Input Gain
0 or less 3 times
1 6 times
2 12 times
3 or greater 24 times
Image:
Attributes
Parameters Description
Comparator Source Specify Comparator source, it can be one of the followings: Comparator1,
Comparator2, ..., Compartor7.
High Side Positive Input Specify Comparator high side positive source. The options are:
Do not use,
CMPx_HP0(PGAx_OF)
CMPx_HP1(Gx_ADCC)
CMPx_HP2(PGAx_IN)
CMPx_HP3(Gx_ADCAB)
CMPx_HP4(PGAx_OUT)
High Side Negative Input Specify Comparator high side negative source. The options are:
Use inner DAC
CMPx_HN0(Gx_ADCAB)
CMPx_HN1(Gx_ADCC)
Low Side Positive Input Specify Comparator high side positive source. The options are:
Do not use,
CMPx_LP0(PGAx_OF)
CMPx_LP1(Gx_ADCC)
CMPx_LP2(PGAx_IN)
CMPx_LP3(Gx_ADCAB)
CMPx_LP4(PGAx_OUT)
Low Side Negative Input Specify Comparator high side negative source. The options are:
Use inner DAC
CMPx_LN0(Gx_ADCAB)
CMPx_LN1(Gx_ADCC)
For example, assume that one needs to specify comparator 1's high side positive signal, From F28004x CompIn
block, there are five choices for this input, they are
• CMPx_HP0(PGAx_OF),
• CMPx_HP1(Gx_ADDCC),
• CMPx_HP2(PGAx_IN),
• CMPx_HP3(Gx_ADCAB) and
• CMPx_HP4(PGAx_OUT).
Since this is comparator 1, one can choose high side positive signal from CMP1_HP0, CMP1_HP1,
CMP1_HP2, CMP1_HP3, CMP1_HP4. From the table about, we know:
• CMP1_HP0 is PGA1_OF,
• CMP1_HP1 is ADCC0,
• CMP1_HP2 is PGA1_IN,
• CMP1_HP3 is ADCA3
• and CMP1_HP4 is PGA1_OUT.
Here if one choose CMP1_HP0(PGA1_OF), comparator 1's high positive should connect to PGA1's PGA1_OF
signal, otherwise SimCoder will report error message; if one choose CMP1_HP4(PGA1_OUT), comparator 1's
high positive should connect to PGA1's PGA1_OUT signal, otherwise SimCoder will report error message.
Note: For F28004x 100-pin package, CMPx_HP1 and CMPx_HP2 are different pins except comparator 6, but
Image:
Attributes:
Parameters Description
Comparator Source Comparator source, it can be any of the 7 comparators.
DAC Voltage Reference Voltage reference of inner DACs, it can be either 'Use VDDA(3.3V)' or
'Use VDAC'.
DACH Usage The other signal of the high side comparator:
- Do not use DACH: The high side inner DAC is not used, the other
signal of high side comparator is Input B if the high side comparator is
used.
- Use constant DAC value: High side inner DAC is used but the DAC
output is a constant. The generated program only sets this constant
value in the initialization.
- Use variable DAC value: High side inner DAC is used and the
generated program sets inner DAC value according to its sampling
frequency.
- Use ramp(Constant): High side inner DAC is set by ramp generator,
the maximum value of ramp generator is a constant. The generated
program only sets this constant value in the initialization.
- Use ramp(Variable): High side inner DAC is set by ramp generator, the
generated program sets the maximum value of ramp generator
according to its sampling frequency.
DACH Range The input range of high side inner DAC.
Initial DACH Value Initial value of high side inner DAC. This value is set at the initialization
to DACH/Ramp if DACH/Ramp only uses a constant value.
Total Ramp Compensation Total compensation of the ramp generator in one PWM period. It
represents the total decrease of the ramp in one cycle.
Ramp Delay (us) The delay time in the beginning of PWM period, Ramp decreases when
delay time is over, in us.
Image:
Parameters Description
Usage of DAC-x The voltage reference used by DAC-x, where x is A, B, or C. It can be one
of the followings:
- Do not use DAC-x: DAC-x is not used.
- ADC Voltage Reference: DAC-x is used in the system and ADC-x
voltage reference is chose by DAC-x.
- VDAC Voltage Reference: DAC-x is used in the system and VDAC
voltage reference is chose by DAC-x.
DAC-x Input Range The input range of DAC-x, where x is A or B.
DAC-x Output Gain Specify the output gain of DAC-x. It can be 1 or 2 times. 2 times is
allowed only if DAC-A uses ADC voltage reference and ADC voltage
reference is set to internal +1.65V.
Use PWM Sync. for ADC-x Specify if DAC-x is synchronized with a PWM block, where x is A, B, or
C. The choices are Do not use or one of the PWM blocks in the pull-down
list.
DAC-x Initial Value Initial value of DAC-x, where x is A, B, or C.
All external high voltage reference (include VDAC) can be set in the range of 2.4V to 3.3V. The internal ADC
voltage reference can be set to either 1.65V or 2.5V. DAC should use 2time gain if internal 1.65V is selected.
All low voltage references are zero.
If DAC-B uses ADC voltage reference, and the ADC voltage reference is set to be external voltage reference,
different CPU packages will have different voltage reference for DAC-B, as show in the table below:
If using VDAC as voltage reference, DACs and Comparator DACs can use VDAC as voltage reference;
otherwise VDAC can not be selected by DACs and Comparator DACs. PSIM does not need ADC-B0 to
connect a voltage reference in schematic, but in target system, ADC-B0 must connect a voltage reference.
The voltage reference of DACs can be VDAC or the voltage reference of ADC-A/B. If VDAC is chose, ADC-
B0 must be set as VDAC. In Psim schematic, this should be only specified in Voltage Reference block, no need
to link a voltage source to ADC-B0. But in target hardware, a voltage reference should be linked to ADC-B0.
The output can be calculated as follows:
To use VDAC (the voltage reference is specified in Voltage Reference block):
DAC_Output = DAC_Input * VDAC / DAC_Range
To use ADC-A voltage reference (for DAC-A and DAC-B only):
DAC_Output = DAC_Input * Vref_ADC-A / DAC_Range
To use ADC-B voltage reference (for DAC-C only):
DAC_Output = DAC_Input * Vref_ADC-B / DAC_Range
Images:
Images:
Parameters Description
Port Position for Input i The port position of the Input i, where i is from 0 to 7. It can be any one
of the GPIO ports.
Invert the Input i Specify if the signal at Input i is inverted or not.
Use Pull-Up Resistor for Input i Specify if the Input i has a pull-up resistor at the GPIO port.
Qualification for Input i There are following qualification options:
- Synchronize to CPU clock
- 3 sampling period
- 6 sampling period
- No sync. or qualification
Parameters Description
Port Position for Output i The port position of the Output i, where i is from 0 to 7. It can be any one
of the GPIO ports.
Port Mode for Output i Port mode of the output i, where i ranges from 0 to 7. It can be any of the
followings:
- Normal output
- Output with pull-up resistor
- Open drain output
Note that each GPIO port can be used for one function only. If a GPIO port is used as a digital input port, it can
not be used as a digital output or any other peripheral port. For example, if Port GPIO0 is assigned as digital
input and it is also used as PWM1 output, an error will be reported.
Parameters Description
Set Gpio x Sample Time Specify if setting sample time is used for GPIO group x. where x=(8*i) -
(8*i+7) with i ranges from 0 to 7.
Gpio x Sample Time (us) The sample time for GPIO group x.
Set Aio x Sample Time Specify if setting sample time is used for AIO group x, where x =200 +
[(i*8) - (8*i+7)], and i ranges from 3 to 5
AIO x Sample Time (us) The sample time for AIO group x.
Images:
Attributes:
Parameters Description
GPIO No. for Input i Specify which GPIO/AIO port is used as input X-Bar signal i
Only one Input X-Bar block is allowed in each F28004x system, accepting 16 input X-Bar signals.
• Any GPIO/AIO port used as Input X-Bar signal can also be used as any other functionality. For example,
GPIO0 is used as PWM1A, but it can also be used as Input X-Bar signal.
• INPUT1, INPUT2 and INPUT3 can be also used as TZ1, TZ2 and TZ3.
• INPUT4, INPUT5, INPUT6, INPUT13 and INPUT14 can be also used as XINT1, XINT2, XINT3, XINT4
and XINT5.
All input X-Bar signals can be also used as input capture signals.
Attributes:
Parameters Description
Output X-BAR No. Specify Output X-Bar signal. It can be one of Output1 through Output8. E
ach output can be linked to one of multiple pre-decided GPIO ports.
Invert the Output Specify if to invert the output.
Output Type Specify GPIO output type. It can be one of the followings:
- Normal Output: Normal output without pull-up resistor.
- Output with pull-up: GPIO port links to an inner pull-up resistor.
- Open drain output: GPIO port is an open drain output (SimCoder
doesn't support this feature in simulation).
Signal Selection for MUXi Specify the PWM X-Bar signal, as explained below.
SimCoder only supports the following signals as the source of the output X-Bar. Multiple input sources are
allowed. The output is the OR of all selected sources.
Attributes:
Parameters Description
PWM X-BAR No. Specify PWM X-Bar signal. It can be one of the followings: TRIP4,
TRIP5, and TRIP7 through TRIP12. There is no TRIP6.
Invert the Output Specify if to invert the output.
Signal Selection for MUXi Specify the PWM X-Bar signal, as explained below.
There are 11 PWM X-Bar signals, They are TRIP1 - TRIP5, TRIP7 - TRIP12. There is no TRIP6 signal. These
signals are used as DC trip-zone signals for PWM.
TRIP1 - TRIP3 are directly wired to TZ1 - TZ3 in Input X-Bar. The other signals need to set in the PWM X-Bar
element. SimCoder only supports the following signals as PWM X-Bar input source. Multiple input sources are
allowed. The output is the logic OR of all selected input sources.
Images:
Parameters Description
Encoder Source The source of the encoder. It can be any of the 2 encoders and with any of the
GPIO port options.
Use Z Signal Define the encoder to use the Z (or index) signal to initialize or latch the position
counter on the occurrence of a desired event on the index pin. The options are:
No: do not use Z signal
Yes (rising edge): use Z signal and latch on rising edge.
Yes (falling edge): use Z signal and latch on falling edge.
Use Strobe Signal Define the encoder to use the strobe signal to initialize or latch the position counter
on the occurrence of a desired event on the strobe pin. The options are:
No: do not use strobe signal
Yes (rising edge): use strobe signal and latch on rising edge.
Yes (falling edge): use strobe signal and latch on falling edge.
Counting Direction The counting direction
- Forward: the encoder counts up.
- Reverse: the encoder counts down.
Z Signal Polarity Define the trigger polarity of Z signal.
- Active High
- Active Low.
Strobe Signal Polarity Define the trigger polarity of strobe signal.
- Active High
- Active Low.
Encoder Resolution The resolution of the external encoder hardware. If it is 0, the encoder counter will
keep on counting and will not reset. If for example, the resolution is set to 4096,
the counter will be reset to 0 after it reaches 4095.
Parameters Description
Encoder Source The source of the encoder. It can be any of the 2 encoders and with any of the
GPIO port options.
Parameters Description
Encoder Source The source of the encoder. It can be any of the 3 encoders and with any of the
GPIO port options.
Latch Position Specify the kept counter type, choose from the followings:
- IndexPos, if the setting "Use Z Signal" is not "No" in Encoder
- StrobePos, if the setting "Use Strobe Signal" is not "No" in Encoder
Type of Position This can be chosen from the followings:
- The first latched position, or
- The current latched position
Image:
Attributes:
Parameters Description
Counter Source The source of the counter. It can be any of the 2 encoders and with any of the
GPIO port options listed in the pull-down menu.
There are two inputs for Up/Down Counter:
• Input "Clk" refers to the input clock signal.
• Input "Dir" refers defines the counting direction.
When the "Dir" input is 1, the counter counts forward (up), and when the input is 0, the counter counts
backward (down).
The output of the up/down counter is the counter value.
Note that the up/down counter shares the same input GPIO ports with the encoder. Therefore, using both
encoder and up/down counter on the same GPIO ports is not allowed.
Image:
Parameters Description
Capture Source Source of the capture. It may come from one of the seven captures.
Event Filter Prescale Event filter prescale. The input signal is divided by the selected prescale.
Timer Mode Capture counter timer mode. It can be one of the followings:
- Absolute time: The output is the absolute time in system clock
- Time difference (clock): The output is the difference between the current event
and the previous event, in system clock.
- Time Difference (us): The output is the difference between the current event and
the previous event, in us.
A capture can generate interrupt, and the interrupt trigger mode is defined in the interrupt block. If there is no
the corresponding interrupt block in the schematic, Capture will catch rising edge only.
Capture input comes from Input X-Bar, so if a capture is used in the system, the corresponding input signal of
Input X-Bar must be defined too.
Parameters Description
Capture Source Source of the capture. It has only one source Capture1.
The Capture State block indicates the triggering state of the capture. Its output is either 1 or 0. 1 means the
rising edge and 0 means the falling edge.
Images:
Attributes:
Parameters Description
SCI RX Port Select SCI Receiving port.
SCI TX Port Select SCI transmission port. This port should be in the same SCI group with SCI
receive port.
Speed (bps) SCI communication speed, in bps (bits per second). A list of preset speeds is
provided at 200000, 115200, 57600, 38400, 19200, or 9600 bps. Or one can
specify any other speed manually.
Parity Check The parity check setting for error check in communication. It can be either None,
Odd, or Even.
Output Buffer Size The buffer size that is allocated in the DSP RAM area for SCI data. Each buffer
cell uses three 16-bit words. (that is, 6 bytes, or 48 bits, per data point).
Note that the buffer size should be properly selected. On one hand, a large buffer is preferred in order to collect
more data points so that more variables can be monitored over a longer period of time. On the other hand, the
internal DSP memory is limited, and the buffer should not be too large to interfere with the normal DSP
operation.
Attributes:
Parameters Description
Initial Value The initial value of the SCI input variable.
The SCI input element provides a convenient way to change the values of a variables such as a reference or
controller parameters in real-time operation.
In PSIM schematic, the SCI Input behaves as a constant for simulation. The value is determined by the initial
value in the parameter block. When code is generated, on the DSP oscilloscope provide by PSIM, the SCI
inputs are listed as input variables. The user may change the values while the code is running in real time.
Attributes:
Parameters Description
Data Point Step It defines how frequent data is collected. If the Data Point Step is 1, every data
point is collected and transmitted. If the Data Point Step is 10, for example, only
one point out of every 10 points is collected and transmitted.
Images:
Attributes:
Parameters Description
SPI SIMO Port Specify SIMO(SPI data output) port.
SPI SOMI Port Specify SOMI(SPI data input) port. This port should have the same SPI source
with SIMO port.
SPI CLK Port Specify CLK(SPI clock) port. This port should have the same SPI source with
SIMO port.
SPI STE Port Specify STE(SPI STE) port. This port should have the same SPI source with
SIMO port.
Attributes:
Parameters Description
Chip Select Pins The state of the chip select pins corresponding to the SPI device. When the chip
select pins are at this state, this SPI device is selected.
Communication Speed SPI communication speed, in MHz.
(MHz)
Clock Type SPI clock type, as determined by the SPI hardware device. It can be one of the
following:
- Rising edge without delay: The clock is normally low, and data is latched at the
clock rising edge.
- Rising edge with delay: The clock is normally low, and data is latched at the
clock rising edge with delay.
- Falling edge without delay: The clock is normally high, and data is latched at
the clock falling edge.
- Falling edge with delay: The clock is normally high, and data is latched at the
clock falling edge with delay.
Command Word Word length, or the length of the significant bits, of SPI communication
Length commands. It can be from 1 to 16 bits.
Sync. Active Mode The triggering mode of the synchronization signal of the SPI device. It can be
either Rising edge or Falling edge.
SPI Initial Command The SPI command that initializes the SPI device.
Hardware Interrupt Specify the type of the interrupt signal that the SPI device generates. This is valid
Mode only when the SPI device’s interrupt output node is connected to the input of a
digital output element. It can be one of the following:
- No hardware interrupt
- Rising edge
- Falling edge
Conversion Type Specify the conversion type of this SPI device. It can be one of following:
Conversion in series: All SPI conversions are in series.
Conversion in parallel: All SPI conversions are in parallel.
Command Gaps (ns) The gap between two SPI commands, in nanosecond. This can be also used as
ADC conversion time.
Conversion Sequence Arrange the names of the SPI input elements, separated by comma, in the
conversion sequence. Note that this parameter is valid only when the SPI device
generates multiple interrupts in series
Attributes:
Parameters Description
Device Name Name of the SPI input device.
Start Conversion Command to start conversion, in hex numbers, separated by comma (for example,
Command 0x23,0x43,0x00).
Receiving Data Command to receive data, in hex numbers, separated by comma (for example,
Command 0x23,0x43,0x00).
Data Bit Position Define where the data bits are in the receiving data string. The format is:
ElementName = {Xn[MSB...LSB]}
where
- ElementName is the name of the SPI input device. If it is the current SPI input
device, use y instead.
- {} means that the item in the bracket repeats multiple times.
- Xn is the nth word received from the SPI input device, and n start from 0.
- MSB...LSB defines the position of the significant bits in the word.
Input Range Specify the parameter Vmax that defines the input range. This parameter is valid
only when the SPI device is an A/D converter. If the device conversion mode is
DC, the input ranges from 0 to Vmax. If the device conversion mode is AC, the
input ranges from -Vmax/2 to Vmax/2.
Scale Factor Output scale factor Kscale. If the scale factor is 0, the SPI device is not an A/D
converter, and the result will be exactly the same as what DSP receives from SPI
communication. Otherwise, the SPI device is an A/D converter, and the result is
scaled based on this factor and the A/D conversion mode.
ADC Mode The A/D conversion mode of the device. It can be either DC or AC. Note that this
parameter is valid only when the device is an A/D converter.
Initial Value The initial value of the input.
The formula for the Data Bit Position defines the data length of a SPI input device. For example,
y=x1[3..0]x2[7..0], means that the data length is 12, and the result is the lower 4 bits of the 2nd word and the
lower 8 bits of the 3rd word. If the received data string is 0x12,0x78,0xAF, then the result is 0x8AF.
Data_Length
2
In the AC conversion mode:
) V max Ksc al e
- In hardware: Output = (Result – 2Data_Length-1 ------- ---------
-----------------------
The parameter Data_Length is calculated from the Data Bit Position formula.
Attributes:
Parameters Description
DAC Mode The D/A conversion mode of the device. It can be either DC or AC. Note that this
parameter is valid only when the device is a D/A converter.
Sending Data Command to send the output data, in hex numbers, separated by comma (for
Command example, 0x23,0x43,0x00).
Data Bit Position Define where the data bits are in the sending data string. The format is:
ElementName = {Xn[MSB..LSB]}
where
- ElementName is the name of the SPI output device. If it is the current SPI
output device, use y instead.
- {} means that the item in the bracket repeats multiple times.
- Xn is the nth word sent to the SPI output device, and n start from 0.
- MSB..LSB defines the position of the significant bits in the word.
Sync. Command The command to synchronize output channels of the SPI output device, in hex
numbers, separated by comma (for example, 0x23,0x43,0x00). This command is
used when the SPI output device does not have the synchronization signal
The formula for the Data Bit Position defines the data length of a SPI output device. For example,
y=x1[3..0]x2[7..0], means that the data length is 12, and the data is the lower 4 bits of the 2nd word and the
lower 8 bits of the 3rd word. If the sending data string is 0x12,0x78,0xAF, then the data is 0x8AF.
If the scale factor is not 0, the output will be scaled based on the following:
V max
In the AC conversion mode:
--------------------------- -----------
V max
The parameter Data_Length is calculated from the Data Bit Position formula.
Images:
Parameters Description
Attributes:
Parameters Description
Number of Inputs Number of CAN inputs. It can have up to 8 inputs.
CAN Source The source of CAN input, either CAN A or CAN B
Use Extension ID If this is set to Yes, the ID of a message is a 29-bit integer. If this is set to No, the ID
of a message is a 11-bit integer.
Message ID The ID of a message. It is an integer, for example, 0x23.
Local Mask The mask for the message. It is an integer. If the bits of the message ID matches
the bits of the mask, the message will be received. Otherwise, it will be ignored.
For example, if the mask is 0x380 and the message ID is 0x389, this message will
be received. But if the message ID is 0x480, the message will be ignored.
Overwrite Protection It can be set to Allow overwrite or Do not allow overwrite.
Flag Assume a mailbox is configured to accept a message, and there is a new message
coming from the CAN bus, while the old message is still in the mailbox and has
not been processed yet. If the flag is set to "Allow overwrite", the new message
will be accepted, and the old message will be overwritten. If the flag is set to "Do
not allow overwrite", the new message will not be accepted, and the old one will
be kept.
Receive Message Rate The number of messages received by the input block in a specific period of time.
For example, there are two input blocks, with the first input block receiving 20
messages per second, and the second input block receiving 30 messages per
second. The parameter "Receive Message Rate" will be set to 20 for the first block,
and 30 for the second block.
Inputi Gain The gain to the ith input where i can be 1 to 8. The output is the input multiplied by
the gain.
Inputi Data Start A message can have up to 8 data points. A data point can have 1 bit up to 32 bits.
Position This defines the start position of the current data point in the message.
Inputi Data End This defines the end position of the current data point in the message.
Position
Attributes:
Parameters Description
Number of Outputs Number of CAN outputs. It can have up to 8 outputs.
CAN Source The CAN source can be either CAN A or CAN B.
Use Extension ID If this is set to Yes, the ID of a message is a 29-bit integer. If this is set to No, the
ID of a message is a 11-bit integer.
Message ID The ID of a message. It is an integer, for example, 0x23.
Trigger Type The trigger type can be one of the following:
- No trigger: No triggering
- Rising edge: Triggering occurs at the rising edge of the trigger source.
- Falling edge: Triggering occurs at the falling edge of the trigger source.
- Rising/falling edge: Triggering occurs at both the rising edge and the falling
edge of the trigger source.
A rising/falling edge is considered to have occurred if the difference between the
current value of the trigger source and the value at the last triggering instant is
equal to or greater than 1.
Trigger Source A trigger source can be either a constant of a global variable depending on the
Trigger Type.
If the Trigger Type is set to "No trigger", the trigger source defines the counter
limit. For example, if the trigger source is a constant or a global value, and the
value is 5, it means that triggering will occur once out of every 5 times. In another
word, the data will be sent out once per every 5 cycles.
If the Trigger Type is set to edge trigger, the trigger source can only be a global
variable. Triggering will occur when the global variable has the rising or falling
edge or both depending on the Trigger Type.
Outputi Gain The gain to the ith output where i can be 1 to 8. The output is the output multiplied
by the gain.
Outputi Data Start A message can have up to 8 data points. A data point can have 1 bit up to 32 bits.
Position This defines the start position of the current data point in the message.
Outputi Data End This defines the end position of the current data point in the message.
Position
Outputi Data Type The data type can be either Float, Integer, or IQ1 to IQ30.
Outputi Default Data The initial value of the SCI output variable.
Parameters Description
CAN Source The source of CAN input, either CAN A or CAN B
Use Extension ID If this is set to Yes, the ID of a message is a 29-bit integer. If this is set to No, the ID
of a message is a 11-bit integer.
Message ID The ID of a message. It is an integer, for example, 0x23.
Trigger Type The trigger type can be one of the following:
- No trigger: No triggering.
- Rising edge: Triggering occurs at the rising edge of the trigger source.
- Falling edge: Triggering occurs at the falling edge of the trigger source.
- Rising/falling edge: Triggering occurs at both the rising edge and the falling
edge of the trigger source. A rising/falling edge is considered to have occurred
if the difference between the current value of the trigger source and the value at
the last triggering instant is equal to or greater than 1.
Trigger Source A trigger source can be either a constant or a global variable depending on the
Trigger Type.
If the Trigger Type is set to "No trigger", the trigger source defines the counter
limit. For example, if the trigger source is a constant or a global value, and the
value is 5, it means that triggering will occur once out of every 5 times. In another
word, the data will be sent out once per every 5 cycles.
If the Trigger Type is set to edge trigger, the trigger source can only be a global
variable. Triggering will occur when the global variable has the rising or falling
edge or both depending on the Trigger Type.
Frequency The sampling frequency.
Image:
Attributes:
Parameters Description
Time Output Method Define how interrupt time is measured. It can be one of the following:
- SCI (time used): Using SCI. Time used by the interrupt service routine, in DSP
clock count, is measured and is sent out via SCI output.
- SCI (time remaining): Using SCI. Time remaining in the interrupt service
routine, in DSP clock count, is measured and is send out via SCI output. The
time remaining is defined as the time from the end of the current interrupt to
the beginning of the next interrupt.
- GPIOi, or AIOi: Using a GPIO or an AIO port. A pulse is generated at the
specified GPIO port. The pulse is set to high when entering the interrupt, and
set to low when exiting the interrupt. An oscilloscope can be used to measure
the width of the pulse.
Sampling Frequency Sampling frequency of the interrupt service routine, in Hz.
Project Setting:
To load .projectspec project, please use CCS 5.3 or latter CCS versions. In CCS main menu, choose Project/
Import CCS project..., then browse the project folder in the dialog. CCS will automatically load the project in
the folder.
In the Code Composer Studio project file, the following settings are provided:
- RAM Debug: To compile the code in the debug mode and run it in the RAM memory
- RAM Release: To compile the code in the release mode and run it in the RAM memory
- Flash Release: To compile the code in the release mode and run it in the flash memory
- Flash RAM Release: To compile the code in the release mode and run it in the RAM memory
When RAM Debug or RAM Release is selected, CCS uses the linker command file F28004x_RAM_Lnk.cmd
to allocate the program and data space.
When Flash Release is selected, CCS uses the linker command file F28004x_FLASH_Lnk.cmd to allocate the
program and data space.
When Flash RAM Release is selected, CCS uses the linker command file F28004x_FLASH_RAM_Lnk.cmd
to allocate the program and data space. The memory allocation is the same as in RAM Release.
The code compiled in the release mode is faster than the code in the debug mode. Also, the code in RAM
Release or Flash RAM Release is the fastest. The code in RAM Debug is slower, and the code in Flash Release
is the slowest. In a development, normally one would start with RAM Debug for easy debugging. Then switch to
RAM Release and consequently to Flash Release or Flash RAM Release.
12.1 Overview
With the PE-Expert4 Hardware Target, SimCoder can generate the code for the PE-Expert4 DSP development
platform from Myway with the following boards:
- DSP Board: MWPE4-C6657, the core DSP board
- PEV Board: MWPE4-PEV, the PWM generation board
- PSPWM Board: Extension boards including MWPE4-FPGA24 and MWPE4-FPGA6
- ADC Board: MWPE4-ADC, the analog signal input extension board
When generating the code for a system that has multiple sampling rates, SimCoder will use the PWM generator
interrupts for the PWM sampling rates. It will then first use the Timer 0 interrupt, and then Timer 1 interrupt if
needed, for other sampling rates in the control system. If there are more than three sampling rates in the control
system, the corresponding interrupt routines will be handled in the main program by software.
In the PE-Expert4 system, digital input, encoder, and capture can also generate hardware interrupts. An
interrupt must be associated with an interrupt service routine (a subcircuit that represents the interrupt service
routine) through the interrupt block as described in Section 5.4 of this Manual. In PE-Expert4, since interrupts
generated by digital input, encoder, and capture are handled by the same interrupt service routine, all the
interrupt blocks must connect to the same subcircuit block.
The hardware functions and elements of the PE-Expert4 Hardware Target are described in the sections below.
Images:
Attributes:
Parameters Description
Board No. The number of the PEV board that contains the PWM generator to be started
Board Type The board type of Expert4 board, can be either the PEV board or the PSPWM
board.
To start PWM, apply a high logic signal (1) to the input of the "Start PWM" element. To stop PWM, apply a
high logic signal (1) to the input of the "Stop PWM" element.
Image:
LED0
LED3
Note that this element is for hardware implementation only, and it will be ignored in the simulation. To display
the LED value in the simulation, connect a voltage probe to the input node.
Image:
Attributes:
Parameters Description
Interrupt Priority of Specify interrupt priority of Timer0. Options are from 4 (highest) to 13 (lowest).
Timer0
Interrupt Priority of Specify interrupt priority of Timer1.
Timer1
This element is optional. The priority can be set from 4 (highest) to 13 (lowest). If no Timer Interrupt Priority
element is in the schematic, SimCoder will set interrupt priority 10 to timer0, interrupt priority 11 to timer1.
Image:
Attributes:
Parameters Description
Board No. The board number (0 to4) of the PEV board that contains these elements.
Interrupt Source of inti Select the interrupt source that uses inti in the current system. The options are:
ADC, PWM, Encoder, Capture, and Digital Input.
Interrupt Priority of inti Select the interrupt priority that uses inti in the current system. The options are
from 4 (highest) to 13 (lowest).
This element specifies all interrupt signals used by interrupt sources, for each interrupt signal, one can specify
its interrupt priority, too.
For the interrupt sources of ADC/PWM combination, if PWM does not trigger ADC, the interrupt source
should be set as PWM. If PWM triggers ADC, the interrupt source should be set as ADC.
Images:
Attributes:
Parameters Description
Board No. The board number of the PEV board that contains the PWM generator.
Scaling Factor Scaling Factor is an integer that ranges from 1 to 1000, specifies the number of
PWM period between two PWM-caused-interrupts.
Initial Amplitude Initial amplitude value of the PWM generator, for Space Vector PWM only.
Initial Angle Initial angle of the PWM generator, in rad., for Space Vector PWM only.
Start PWM at It can be set to either Start or Do not start. When it is set to Start, PWM will start
Beginning right from the beginning. If it is set to Do not start, one needs to start PWM using
the "Start PWM" function.
The element PWM generates sinusoidal-modulated PWM signals for a three-phase system. The inputs "u", "v",
and "w" are for three-phase input modulation signals. The input ranges are between -1 to 1. That is, when the
input is -1, the duty cycle is 0, and when the input is 1, the duty cycle is 1. With the input at 0, the duty cycle is
0.5. The carrier wave is a triangular wave with 0.5 duty cycle (the intervals of the rising slope and the falling
slope are equal).
The element Space Vector PWM generates PWM signals for a three-phase system based on space vector PWM
technique. The input "amp" is for the space vector amplitude, and the range is from 0 to 1. The input "ang" is for
the space vector phase angle, and the range is from -2 to 4.
Because the input range of the PWM generator is between -1 and 1, while in PSIM simulation, normally PWM
signals are generated by comparing a modulation signal with a carrier signal, and the modulation signal range
may not be from -1 to 1, scaling may be needed before the modulation signal is sent to the PWM generator.
The element PWM (sub) consists of a PWM element and the input scaling-offset circuit, as shown below. It
1
a
K up
PWM fs
u up un
U2
2/Vpk un b 1
b z
K v vp vp
vn fs
U3 vn
2/Vpk w wp c 1
c wn z
K fs
wp
fs wn
Vpk
1+2*Voffset/Vpk
fs
0.5
Voffset
0
0
The circuit on the left shows the details of the PWM (sub) element. It consists of a scaling-offset circuit and the
hardware PWM element. With the scaling, ranges of the inputs a, b, and c are no longer limited to -1 and 1.
Similar to the definition of a carrier voltage source, the peak-to-peak value and the dc offset can be defined
directly.
The circuit on the right shows the equivalent circuit of the PWM (sub) element, implemented in PSIM using
comparators and a triangular carrier voltage source. The carrier source parameters are:
V_peak_to_peak: Vpk
Frequency: fs
Duty Cycle: 0.5
DC Offset: Voffset
Tstart: 0
Phase Delay: 0
Note the inclusion of three unit delay blocks U1, U2, and U3, as they are used to model the one-cycle delay
effect existing in the hardware PWM element. Also, the carrier wave duty cycle is fixed at 0.5, as the carrier
wave in the hardware PWM element is of triangular type.
The Scaling factor specifies how often the PWM-caused-interrupt occurs.
The parameter "Control Frequency" specifies the sampling frequency. This frequency may or may not be the
same as the PWM switching frequency.
The relationship between the Control Frequency fsmp, the Scaling Factor Kscale, and the PWM carrier
frequency fsw is calculated as below:
If the parameter "Interrupt Mode" is set as "Interrupt at peak" or "Interrupt at valley":
fsw = Kscale * fsmp
For example, if Kscale = 3, the PWM-caused-interrupt occurs once in every 3 PWM period.
If the parameter "Interrupt Mode" is set as "Interrupt at peak/valley":
fsw = Kscale * fsmp/2
For example, if Kscale = 3, the PWM-caused-interrupt occurs once in every 3*2=6 PWM period.
Please note that when the PWM and PWM (sub) generators are simulated, the dead time is ignored and is not
considered in the simulation.
Image:
Attributes:
Parameters Description
Board No. The board number of the PEV board that contains the A/D converter.
Conversion Mode ADC conversion mode. It can be either Continuous or PWM triggered.
Ch Ai Output Range The output range Vrange of the ith A/D channel (i = 0 to 7)
Ch Ai Offset The output offset Voffset of the ith A/D channel (i = 0 to 7)
The input range of the A/D converter is from -5V to +5V, and the output range is from -Vrange to Vrange. The
output is scaled based on the following:
Vo = Vi * Vrange / 5 - Voffset
For example, if the A/D input Vi = 2, Vrange = 20, and Voffset = 0.5, then
Vo = 2 * 20 / 5 - 0.5 = 7.5 V
Images:
Digital Input Up/Down Counter External Interrupt
Parameters Description
Board No. The board number of the PEV board that contains the element.
Input/Capture i The index i changes from 0 to 3, corresponding to Inputs D0 to D3 respectively.
The parameter can be defined as one of the following:
- Digital Input i: Input pin Di will be a digital input.
- Capture i: Input pin Di will be the input of Capture i, and the output pin Di will be
the counter output of Capture i. The captions of the input/output pins will be
changed to Capi and Cnti.
As a Capture:
The capture element has 4 inputs. When an input changes from low to high (from 0 to 1), it will capture the
counter value of the source, and output it through the output pin. The counter source can be either the general-
purpose timer (which is the 32-bit free-run counter on the PEV Board), or the encoder.
As a Counter:
The counter has two modes of operations: up/down mode and direction/pulse mode. When the counter is in the
"Up/down" mode, the counter will count up when there is a pulse at the "up" input, and will count down when
there is a pulse at the "dn" input.
When the counter is in the "Direction/pulse" mode, and when there is a pulse at the "pulse" input, the counter
will count up when the "Dn" input is 0, and will count down when the "Dn" input is 1.
As an External Interrupt:
When Input pin D6 is defined as the input of the external interrupt, when the input changes from 0 to 1, an
interrupt will be generated.
Image:
Attributes:
Parameters Description
Board No. The board number of the PEV board that contains the element.
12.3.6 Encoder
An encoder is used for position measurement in a motor drive system. It can operate in either "Open Collector"
or "Differential Mode" mode.
Image:
Attributes:
Parameters Description
Board No. The board number of the PEV board that contains the encoder.
Use Z Signal Specify if the Z signal is used.
Counting Direction It can be either Forward or Reverse. When it is set to "Forward", the encoder
counts up, and when set to "Reverse", the encoder counts down
Encoder Resolution Specify encoder resolution. The Encoder counter will count up/down between 1
and Resolution-1.
The output of the encoder output gives the counter value. Also, an interrupt can be generated by the input signal
Z+ and Z-.
An encoder can trigger an interrupt by the Z signal. TO implement an encoder interrupt routine, one needs to
use an interrupt element that specifies the interrupt source (by filling the name of the Encoder element) and
which edge triggers interrupt (it can be falling edge, rising edge, or rising/falling edge). This element links to an
event subcircuit by an event connection wire.
Image:
Attributes:
Parameters Description
Board No. The board number of the PSPWM board that contains these elements (it ranges
from 0 to 4).
Interrupt Source of inti Select the interrupt source that uses inti in the current system.
Interrupt Priority of inti Select interrupt priority that uses inti in the current system.
This element specifies all interrupt signals used by interrupt sources, for each interrupt signal, one can specify
its interrupt priority, too. The priority options are from 4 (highest) to 13 (lowest).
Parameters Description
Board No. The board number of the PEV board that contains the PWM generator.
Board Type Specify PSPWM board type, it can be PSPWM-24 or PSPWM-144.
Scaling Factor Scaling Factor is an integer that ranges from 1 to 1000, specifies the number of
PWM period between two PWM-caused-interrupts.
Reference Update Mode The reference update mode can be set to one of the following:
- At each carrier: The real modulation value is applied at each carrier.
- At the first carrier: The real modulation value is applied at the first carrier.
Reference Update Time The reference update time can be set to one of the following:
- At peak: The new modulation value is applied at each carrier or the first
carrier's peak.
- At valley: The new modulation value is applied at each carrier or the first
carrier's valley.
- At peak/valley: The new modulation value is applied at each carrier or the
first carrier's peak and valley.
Interrupt Mode The interrupt mode can be set to one of the following:
- Interrupt at peak: Interrupt occurs at the peak of the carrier wave
- Interrupt at valley: Interrupt occurs at the valley of the carrier wave
- Interrupt at peak/valley: Interrupt occurs at both the peak and valley of the
carrier wave
When the interrupt mode is set to both peak and valley, the interrupt occurs at two
times the rate of the carrier wave. In another word, if the carrier frequency is
10kHz, the interrupt rate will be 20kHz.
Interrupt Position The interrupt position ranges from -0.5 to +0.5. If the value is positive, it is after
the beginning of the PWM cycle. If the value is negative, it is before the
beginning of the PWM cycle.
If the A/D converter is used and its conversion mode is set to 'PWM Triggered',
this parameter specifies the position that PWM triggers ADC for conversion. If
PWM does not trigger the A/D converter, it is the trigger position for the PWM
interrupt.
When this parameter is 0, the A/D converter (or PWM interrupt) is triggered at
the beginning of the PWM cycle. When it is +0.5, the A/D converter (or PWM
interrupt) is triggered at the half position of the PWM cycle.
Number of Converter Specifies how many levels the converter has.
Levels
PWM outputs are assigned from the first output pin, phase U outputs are assigned, next phase V then phase W.
For example, for 3-phase, 5-level and half bridge cell, PWM outputs are assigned as follows:
U1P, U1N, U2P, U2N, U3P, U3N, U4P, U4N,
V1P, V1N, V2P, V2N, V3P, V3N, V4P, V4N,
W1P, W1N, W2P, W2N, W3P, W3N, W4P, W4N
where
U1P connects to S1p of phase U's first cell,
U1N connects to S1n of phase U's first cell.
For 1-phase, 5-level and full bridge cell, PWM outputs are assigned as follows:
U1P1, U1N1, U1P2, U1N2,
U2P1, U2N1, U2P2, U2N2,
U3P1, U3N1, U3P2, U3N2,
U4P1, U4N1, U4P2, U4N2,
the rest 8 outputs are not used.
Here
U1P1 connects to S1p of phase U's first cell,
U1N2 connects to S1n of phase U's first cell,
U1P2 connects to S2p of phase U's first cell,
U1N2 connects to S2n of phase U's first cell.
To start PWM, apply a high logic signal (1) to the input of the "Start PWM" element. To stop PWM, apply a
high logic signal (1) to the input of the "Stop PWM" element.
Images:
Cell for 2 Switches Cell for 4 Switches Cell for 2 Switches Cell for 4 Switches
(quick write) (quick write)
Attributes:
Parameters Description
Board No. Board number of the main PSPWM board that supports the extension boards.
Phase Specifies phase No., it can be Phase U, Phase V, or Phase W
Cell No. Specifies cell No., it can be Cell 1, Cell 2, ..., or Cell 12.
Each PSPWM board (main FPGA board) can control up to 8 PSPWM extension boards. Each extension board
controls multiple 2-switch cells or 4-switch cells in power stage.
The cells are assigned sequentially from extension board 1, 2, ..., 8. On each extenion board, the cells are
assigned in the order of phase U, V and W. In each phase, cells are assigned sequencilly cell 1, cell 2, ..., until
cell 12.
Cell for 2 Switches and Cell for 2 Switches (quick write) can be used only if the PSPWM block specifies the
operation mode to "Diode clamped/Flying cap" or "MMC (Chopper)". The outputs links to s1 and s1p of a
switch cell.
Cell for 4 Switches and Cell for 4 Switches (quick write) can be used only if the PSPWM block specifies the
operation mode to "MMC (H-bridge)". The outputs links to s1, s1p, s2 and s2p of a switch cell.
Image:
Parameters Description
Board No. The board number of the PEV board that contains the A/D converter.
Conversion Mode ADC conversion mode. It can be either Continuous or PWM triggered.
Ch Ai Range The output range Vrange of the ith A/D channel (i = 0 to 7)
Ch Ai Offset The output offset Voffset of the ith A/D channel (i = 0 to 7)
The input range of the A/D converter is from -5V to +5V, and the output range is from -Vrange to Vrange. The
output is scaled based on the following:
Vo = Vi * Vrange / 5 - Voffset
For example, if the A/D input Vi = 2, Vrange = 20, and Voffset = 0.5, then Vo = 2 * 20 / 5 - 0.5 = 7.5 V
This A/D converter can not be triggered by synchronization signal. It can be only triggered by the same
PSPWM board.
Image:
Attributes:
Parameters Description
Board No. The board number of the PSPWM board that contains the element.
Images:
Parameters Description
Board No. The board number of the PEV board that contains these elements.
Interrupt Source of inti Specify interrupt source that uses inti in the current system.
Interrupt Priority of inti Specify interrupt priority that uses inti in the current system.
This element specifies all interrupt signals used by interrupt sources, for each interrupt signal, one can specify
its interrupt priority, too.
Parameters Description
Board No. The board number of the PEV board that contains the A/D converter.
Conversion Mode ADC conversion mode. It can be either Continuous or Trigger by Ext. Sync. i,
where i is from 1 to 8.
Ch Ai Range The output range Vrange of the ith A/D channel (i = 0 to 11)
Ch Ai Offset The output offset Voffset of the ith A/D channel (i = 0 to 11)
The input range of the A/D converter is from -5V to +5V, and the output range is from -Vrange to Vrange. The
output is scaled based on the following:
Vo = Vi * Vrange / 5 - Voffset
For example, if the A/D input Vi = 2, Vrange = 20, and Voffset = 0.5, then Vo = 2 * 20 / 5 - 0.5 = 7.5 V
13.1 Overview
The SimCoder library supports the TI Digital Motor Control (DMC) library versions V4.0, V4.1 and V4.2. User
may select the version in the Simulation Control under the SimCoder tab. Note that only one version can be
used at a time. Once a version is selected, elements that are not supported in that version will be disabled.
SimCoder’s TI DMC Library contains the function blocks listed in the table below. A brief description of these
blocks are given in this Chapter. For more detailed description, please refer to the document from Texas
Instruments.
Image:
Parameters Description
Stator Resistance Rs Motor stator resistance, in ohm
Stator Inductance Ls Motor stator inductance, in H
Rotor Resistance Rr Motor rotor resistance, in ohm
Rotor Inductance Lr Motor rotor inductance, in H
Magnetizing Inductance Lm Motor magnetizing inductance, in H
Base Phase Voltage Vb Motor base phase voltage, in volt
Base Phase Current Ib Motor base phase current, in ampere
PI Proportional Gain Kp PI controller proportional gain
PI Integral Gain Ki PI controller integral gain
Sampling Frequency System sampling frequency
Image:
Attributes:
Parameters Description
Rotor Resistance Rr Motor rotor resistance, in ohm
Rotor Inductance Lr Motor rotor inductance, in H
Filter Cut-off Frequency fc Cut-off frequency of the low pass filter, in Hz
Base Electrical Frequency fb Base electrical frequency, in Hz
Base Speed in rpm Base motor speed in rpm
Sampling Frequency System sampling frequency
Image:
Attributes:
Parameters Description
Angle Range Define the range of angle output.
0 to +1.0: wrap angle within 0 and 2 (1.0)
-0.5 to +0.5: wrap angle within - (-0.5) and + (+0.5)
Image:
Clarke Clarke
a al a al
b
b be c be
TI DMC TI DMC
Attributes:
Parameters Description
Number of Input Phase Define the number of input phases.
- 2-Phase: Inputs are Phases a and b;
- 3-phase: Inputs are Phases a, b, and c.
If the number of input phase is selected as 3-Phase, the transformation equations are:
v = va
vb – vc
v = --------------
3
Attributes:
Parameters Description
Noise Windows Delta Noise windows delta
Noise Windows Threshold Noise windows dynamic threshold
Image:
Parameters Description
Rotor Resistance Rr Motor rotor resistance, in ohm
Rotor Inductance Lr Motor rotor inductance, in H
Base Electrical Frequency Base electrical frequency in Hz
Sampling Frequency System sampling frequency
Image:
Image:
Image:
Image:
Attributes:
Parameters Description
Out-of-Phase Adjustment Specify if the input phase signals are out of phase with respect of output.
- Yes if 3-phase input signals are from the lower switching functions.
- No if 3-phase input signals are from upper switching functions
Without Reset
PID
ref
fb
fbk fbk fbk fbk fbk TI DMC
TI DMC TI DMC TI DMC TI DMC TI DMC
With Reset
PI PI (pos) PI_REG4 PI_POS_REG4 PID_REG3
ref ref
fbk fbk fbk
rst rst rst
TI DMC TI DMC TI DMC TI DMC TI DMC
Parameters Description
Proportional Gain Kp Proportional loop gain
Integral Gain Ki Integral gain
Maximum Output Maximum output limit Umax
Minimum Output Minimum output limit Umin
Attributes:
Parameters Description
Proportional Gain Kp Proportional loop gain
Integral Gain Ki Integral gain
Maximum Output Maximum output limit
Minimum Output Minimum output limit
Parameters Description
Proportional Gain Kp Proportional loop gain
Integral Gain Ki Integral gain
Maximum Output Maximum output limit
Minimum Output Minimum output limit
Attributes:
Parameters Description
Proportional Gain Kp Proportional loop gain
Integral Gain Ki Integral gain
Attributes:
Parameters Description
Proportional Loop Gain Kp Proportional loop gain
Integral Gain Ki Integral gain
Derivative Gain Kd Derivative gain
Integral Correction Gain Kc Integral correction gain
Maximum Output Maximum output limit
Minimum Output Minimum output limit
Parameters Description
Proportional Ref Weight Kr Reference weighting on proportional path
Proportional Loop Gain Kp Proportional loop gain
Integral Gain Ki Integral gain
Derivative Gain Kd Derivative gain
Derivative Ref. Weight Km Derivative reference weighting
Cut-off Frequency fc Cut-off frequency for the first order filter on derivative path
Maximum Output Umax Maximum output limit
Minimum Output Umin Minimum output limit
Sampling Frequency System sampling frequency, in Hz
Image:
Attributes:
Parameters Description
Base Frequency fb Base frequency, in Hz
Sampling Frequency Sampling frequency, in Hz
Images:
Example:
SetpointValue = 0 (initial value), TargetValue = 1000 (user specified), RampDelayMax = 500 (user specified),
and sampling loop time period Ts = 0.000025 sec.
This means that the time delay for each ramp step is Td = 500x0.000025 = 0.0125 sec. Therefore, the total ramp
time will be Tramp = 1000x0.0125 = 12.5 sec.
Parameters Description
Max Delay Rate Delay rate for each ramp step, in number of sampling time period
Minimum Output Minimum output limit
Maximum Output Maximum output limit
Example:
Out = 0 (initial value), DesiredInput = 1000 (user specified), Ramp2Delay = 500 (user specified), and sampling
loop time period Ts = 0.000025 sec.
This means that the time delay for each ramp step is Td = 500x0.000025 = 0.0125 sec. Therefore, the total ramp
time will be Tramp = 1000x0.0125 = 12.5 sec.
Attributes:
Parameters Description
Delay in # of Period The delay rate for each ramp step, in number of sampling time period.
Minimum Output Minimum output limit
Maximum Output Maximum output limit
Initial Output Value Initial output value
Example:
Out=500(initial value), DesiredInput=20(user specified),
Ramp3Delay=100(user specified), sampling loop time period Ts=0.000025 Sec.
This means that the time delay for each ramp step is Td=100x0.000025=0.0025 Sec. Therefore, the total ramp
down time will be Tramp=(500-20)x0.0025 Sec=1.2 Sec
Attributes:
Parameters Description
Delay in # of Period The delay rate for each ramp step, in number of sampling time period.
Maximum Output Maximum output limit
Minimum Output Minimum output limit
Initial Output Value Initial output value
Image:
Attributes:
Parameters Description
Sliding-Mode Control Gain Sliding-mode control gain (Kslide).
Sliding-Mode Filter Gain Sliding -mode filter gain (Kslf).
Images:
Differentiable
range
Differentiable
range
Attributes:
Parameters Description
Filter Cut-off Frequency fc The cut-off frequency of the low-pass filter at the output variable, in Hz
Base Frequency fb Base frequency, in Hz
Bask Speed (rpm) Base speed, in rpm
Sampling Frequency System sampling frequency, in Hz
Input and Output Signals:
Attributes:
Parameters Description
Filter Cut-off Frequency fc The cut-off frequency of the low-pass filter at the output variable, in Hz
Base Frequency fb Base frequency, in Hz
Bask Speed (rpm) Base speed, in rpm
Sampling Frequency System sampling frequency, in Hz
Parameters Description
# of Sprocket Teeth The number of sprocket teeth, an integer number
Bask Speed (rpm) Base speed, in rpm
Sampling Frequency System sampling frequency, in Hz
Images:
SV Gen SV Gen (comm) SV Gen (DPWM) SV Gen (M/F)
al Ta al Ta al Ta f Ta
Tb Tb Tb o Tb
be Tc be Tc be Tc k Tc
TI DMC TI DMC TI DMC TI DMC
For Blocks SVGEN, SVGEN_COMM, and SVGEN_DPWM: There are no parameters for these blocks.
Attributes:
Parameters Description
Base Frequency Base frequency, in Hz
Sampling Frequency System sampling frequency, in Hz
Attributes:
Parameters Description
Low Frequency (pu) Low frequency fmin, in per unit
High Frequency (pu) High frequency frated at the rated voltage Vrated, in per unit
Low Freq. Voltage (pu) Voltage at the low frequency fmin, in per unit