7 - Embedded Application Development
7 - Embedded Application Development
sT Embed Training
Ric Kolk
Altair Engineering
[email protected]
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 2
Topics:
2
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 3
Software Installation
Step 1: Install the “code composer” software from Texas Instruments available at the following
link:
http://processors.wiki.ti.com/index.php/Download_CCS#Code_Composer_Studio_Version_6_Do
wnloads
Select the "Off-line Install“ and install with all recommended options. After
completing, verify the installation by going to the Start menu and confirming
you see the following (right)
Step 2: Install “solid Thinking Embed” software available at the following link:
http://www.vissim.com
3
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 4
Host Target
Debug Model: A “.vsm” model, part of which is executed on the Target and
communicates, in real time, with the remaining part of the Debug model,
residing on the Host PC.
Automatic C-Code Generation,
Compilation, linking, and downloading
The Debug Model part residing on the Host contains a “Target Interface
Block” whose inputs and outputs communicate with the Target through the
Interactive Data Exchange.
Target Interface VisSim
The Target Update time is controlled either by “Time Step” or as a parameter block Generated
Interactive .out file
in the “Target Interface Block”. Data & RTOS &
Exchange Debug Plant
Debug Model
blocks
Normally the Debug Model name is the Source Model name appended with “– - signal monitoring
- Interactive gains
d” (for debug), ex; the source model myModel.vsm would have a debug model - Plots
named myModel-d.vsm
Host Target
4 4
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 5
Host Target
With Interactive Data Exchange: BOTH a Source Model and a Debug Model are needed:
Interactive
1. Create the target algorithm as a compound block in a Source Model. Add Input and Output
Data pins to the compound block to send and receive data from the Host to the Target
Exchange
Target Interface Auto 2. CodeGen and Compile the Source Model to create an executable (.out) file
block Generated 3. Create a Debug Model consisting of a “Target Interface” block configured to read the
.out file
Debug Model
& RTOS & Plant executable (.out) file from step 2. Onceconfigured, the “Target Interface” block will have
- signal monitoring
- Interactive gains
Debug the same input and output pins defined in Step 1. You can connect these with “signal
blocks
- Plots producers” and “signal consumers” to sendcommands to the target or plot or display
Host Target data from the target. Click “Go” in the Debug Model to initiate target execution.
5 5
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 6
6
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 7
7
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 8
8
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 9
9
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 10
NOTE: The F28069M board has two LED’s accessed through the
following channel and port information;
Red LED = Channel 34, Port B
Blue LED = Channel 39, Port B
NOTE: Port A has 32 bits, so channel 34 is on Port B
10
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 11
11
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 12
12
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 13
Step 2. Code Generation - Lasso the “Target Calculations” compound block and
then;
13
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 14
Edit the Debug model and delete or disconnect the “Target Calculations” compound
block. In its place, add a “Target Interface” block from the
(“Embedded/Picollo/Target Interface”) menu. The “Target Interface” block will have
the same input and output pins as specified in the “Target Calculations” compound
block in the source model. Connect the “slider” to the input pin of the “Target
Interface” block.
Click “Go”, and, after a brief handshake, the Target will begin executing blinking
the red LED at the frequency specified by the “slider”.
14
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 15
15
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 16
16
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 17
17
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 18
Step 2. Code Generation - Lasso the “Target Calculations” compound block and then;
18
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 19
Edit the Debug model and delete or disconnect the “Target Calculations” compound
block. In its place, add a “Target Interface” block from the (“Embedded/Picollo/Target
Interface”) menu. The “Target Interface” block will have the same input and output
pins as specified in the “Target Calculations” compound block in the source model.
Connect the “slider” to the input pin of the “Target Interface” block and the “plot” to the
output pin.
19
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 20
Setting the “slider” block at a 5 Hz frequency value, the “plot” block (right)
displays the measured “:OnTime” of 0.1 seconds +/- .01 seconds. The variation
is due to the “Sample Rate (Hz)” setting being used.
20
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 21
Checking the “Show CPU Usage” option in the “Target Interface” block adds an output pin to the
“Target Interface” block entitled “%CPUusage. This output provides a dynamic value for the
Target CPU utilization in percent .
The BlinkLEDwithControlledFrequencyAndOnTimeCalculation-
d.vsm model (from the previous example) is modified to plot the
“%CPU usage” at three “Sample Rate (Hz)” values; 100 Hz, 1000
Hz, and 10000 Hz.
21
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 22
The “Monitor Buffer Read” and “Monitor Buffer Write” blocks provide a mechanism for a Debug model to buffer a large volume of data
acquired on the Target at the Target “Sample Rate (Hz)”, transmit the data periodically over the slower JTAG interface from the Target to the
Host, and then make the buffer contents available as a vector of data at regular intervals on the Host application.
The following figure illustrates the buffer mechanism to capture, transmit, and display a buffer of 1001 elements using Buffer ID 0. The Target
Update Rate = 10,000 Hz, and the Host “Time Step” = 0.01 seconds. The Target “Monitor Buffer Write” is triggered at 0.01 second intervals.
Sequence of Operation:
1. “Monitor Buffer Write 0” “trig” input outputs a pulse every 0.01 seconds
2. “Monitor Buffer Write 0” begins recording a new “buffer” of data when two conditions are met: (1) “trig” = 1 and (2) “buffer” is
empty. NOTE: recording continues uninterrupted until the “buffer” is full.
3. When “buffer” is full; “Monitor Buffer Read 0” “Trig” output produces a “1” pulse and the “buffer” is emptied into the “plot” block and
“buffer” is cleared and ready to accept new data.
4. Steps 2 and 3 are repeated.
22
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 23
Step 1: Source Model “MonitorBufferTriggerAndTimeCheck.vsm” - Add and configure the “F28x Config …” block. “Time Step” is set to
0.0001 seconds. A compound block named “Target Calculations” is created with the following contents;
23
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 24
24
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 25
25
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 26
Step 1: Source Model “MonitorBufferControlledFrequencySinWavevsm” - Add and configure the “F28x Config …” block. “Time Step” is
set to 0.0001 seconds. A compound block named “Target Calculations” is created with the following contents;
26
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 27
Step 3. Debug
Model - Create the
debug model by “slider” defines sin wave
frequency (Hz), bounds =
renaming the [100 – 1000] Hz.
source model to
“MonitorBufferCont
rolledFrequencySin
Wave-d.vsm” and
X-axis: Based on 200 samples at .0001 sec.
edit as shown intervals = 20msec
below (“Time Step”
= 0.001 sec)
View debug model in VisSim
27
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 28
The VisSim fixed point block library (“Blocks/Fixed Point”), contains block functions for fixed point operations.
This library contains one “const” signal producer block. The
“const” block properties are defined as;
Where:
Const: constant value in decimal form.
Radix Point (bits): Location of the radix point in the binary
number (# of bits from the left, or the integer part)
Word Size (bits): Length of the binary number (bits)
28
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 29
Precision is the smallest difference between two consecutive binary values, is determined by the least significant (rightmost) bit.
Then, the number of bits to the right of the radix point = 14, the number of bits to the left = 2, and the precision = 2^-14
When converting a decimal (floating point) value to a fixed point equivalent, precision determines how accurate the result is. sTE uses
truncation if the magnitude of the binary equivalent is less than the original decimal value.
Many of the Texas Instruments blocks use 1.16 format which has a range between -1 to .99997 and the precision = 3.0518e-005
29
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 30
The time required for a CPU cycle (or a clock cycle time) is 1/CPU speed, in units of seconds.
For example, an 80MHz CPU speed would have a clock cycle time = 1/80e6 = 1.25e-8 seconds = .0125
microseconds.
A Timer keeps track of how many clock ticks occur without having to write specific code to keep track of time.
A Timer needs to be initialized and enabled. It will then proceed to count the clock ticks to a predefined value and then
start over. You can set the Timer to generate events at multiple times along the way to its end value; these events
could be an interrupt when it hits a certain number of clock ticks, or it can toggle, set, or clear a specialized pin.
By default, a CPU operates at the manufacturer’s clock frequency, however, overclocking can be used to increase the
CPU speed. Overclocking will use more power and generate more heat but will improve the speed performance of
the CPU.
30
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 31
To set the CPU in overclock mode, the “Multiple of Crystal Freq” (below right) is selected to be 9x instead of the
normal 8x value (to produce the 90MHz rate overclock CPU speed).
manufacturer’s CPU
Speed = 80MHz Overclocked CPU Speed =
90MHz
31
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 32
The ADC Configuration block is used to associate the ADC with a PWM generated Start Of
Conversion (SOC) signal.
32
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 33
33
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 34
No deadband is needed
34
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 35
Return Value Type: Specifies the data type of the variable. If you choose hardware register, VisSim
Embedded will only create a reference in the code and not an external declaration. The remaining
data types are described in the block help file.
35
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 36
Expression Block
http://www.cplusplus.com/reference/cmath/
The Extern Read block only allows built-in C data types. This means, for
example, that you would specify the unsigned short data type in the
Extern Read block to match a uint16 user-defined data type.
The Extern Write block only allows built-in C data types. This means, for
example, that you would specify the unsigned short data type in the
Extern Write block to match a uint16 user-defined data type.
37
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 38
To configure the ADC to read the chip temperature on ADCINA, the following
sequence of instructions is executed
EALLOW
ADCCTL1 bit 0 = 1 (bit 0 =TEMPCONV, setting bit 0 =1 causes temp sensor connected to ADCINA5)
EDIS Execution Order: VisSim will execute in
“top down” order so the vertical placement
The equivalent VisSim block diagram is implemented using the “extern function”, of the blocks is critical
“extern write”, and “extern read” block previously discussed
38
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 39
Order of Execution
sTE will execute in “top down” order based on the vertical placement of blocks
Order of execution
In situations where the top down ordering is not adequate, sTE provides an “execOrder” block (“Blocks/Signal Consumers”)
39
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 40
Step 1: Source Model “ChipTempOnF28069M.vsm” - Add and configure the “F28x Config …” block. “Time Step” is set to 0.005 seconds.
A compound block named “Target Calculations” is created with the following contents;
First Pass
Logic
Read
ADC5 Linear Scaling to get degC
40
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 41
41
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 42
42
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 43
Encoder
The F28069M LaunchPad board has inputs for two quadrature encoders. Quadrature encoders measure rotational
angles by counting discrete “ticks”.
Typically, an encoder will have between 256 to 4000 ticks per revolution.
The A and B outputs consist of discrete values, 1 or 0, and are out of phase by 90 degrees, this allows the direction of
rotation to be determined:
43
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 44
Encoder
The F28069M LaunchPad board has
encoder peripherals that manage the
encoder count value and reset the count
value each time an “index pulse” occurs.
Encoder 1
Encoder 2 Connection (pin 1 is
Connection leftmost pin)
44
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 45
Encoder – Startup
An incremental encoder begins counting “ticks” at power up, it’s information is not accurate until an “index pulse” occurs. The “index
pulse” occurs 1x/revolution. When used for motor control, incremental encoders must be rotated initially in “open loop” mode until the
“index pulse” is sensed.
A VisSim model to detect the “index pulse” is presented below, In this model, the “index pulse” is named “EncoderIndexHasOccured”
QEPSTS is the
quadrature encoder
status register
45
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 46
= “Index Pulse”
“AngleElectricalNormalized” =
normalized (0-1 = 0-360 degrees)
electrical angle
“AngleMechanicalNormalized” =
normalized (0-1 = 0-360 degrees)
mechanical angle
46
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 47
47
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 48
Teknic M-2310P-LN-
24V, 3A
04K Low voltage
power supply
servo motor with
encoder
http://www.ti.com/tool/l
vservomtr
48
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 49
TI BOOSTXL-
DRV8301
http://www.ti.com/too
l/boostxl-drv8301
TI LAUNCHXL-F28069M
49
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 50
Step 1: Source Model “Motor Position Control - LaunchPadDRV8301-pmsm-28069M.vsm” - Add and configure the
“F28x Config …” block. “Time Step” is set to 0.0001 seconds. A compound block named “PMSM Control” is created
with the following contents;
Step 2. Code Generation - Lasso the “Target Calculations” compound block and then;
50
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company. 51
Click “Go”, and, after a brief handshake, the Target will begin executing.
Setting the “slider” block to different position setpoint values will cause the motor to rotate until the
setpoint value is achieved.
51
© 2016 solidThinking, Inc. Proprietary and Confidential. All rights reserved. An Altair Company.
End of Section