File Exchange

image thumbnail

Motor Control with TI LaunchPad

version 1.4.0.0 (86.8 KB) by Antonin
Permanent Magnet Synchronous Motor Field-Oriented Control with TI LaunchPad and BOOSTXL-DRV8301

79 Downloads

Updated 27 Jul 2018

View License

This example shows how to use a closed-loop Field-Oriented Control (FOC) algorithm to regulate the speed and torque of a three-phase Permanent Magnet Synchronous Motor (PMSM). This example uses C28x peripheral blocks and C28x DMC library blocks from the Embedded Coder Support Package for Texas Instruments C2000 Processors.
For newer versions and other hardware setup, check the shipping version of this example on this page: https://www.mathworks.com/help/supportpkg/texasinstrumentsc2000/examples/permanent-magnet-synchronous-motor-field-oriented-control.html
Required Hardware:
- TI F28027 LaunchPad
- BOOSTXL-DRV8301 with a 3-phase brushless motor and a 12-24V power supply.
More information on how the models have been created and how to use them in the following video:
http://youtu.be/wxYTLbYfBP0

Comments and Ratings (88)

Sumit Patil

Hi Antonin;
i am trying to develop a motor control system ,would u plz help me by conveying that how i compute my motor data so that my motor gets going with the c28027 launchpad and booster pack DRV8305.plzz help me,i am stuck with this problem.

Hi Venkatesh and Antonin,
I an trying to get an induction motor instead of pmsm motor in c2808pmsmsim model. However it is showing an algebraic loop error with various controller blocks. How can I get solve it?

Hi Antonin,
I want to know if this model can further be used for the simulation of an induction motor in real world. I am trying to convert it into a speed control of an induction motor.

Hi Antonin,
I have another question: Can I use the encoder provided in the Tecnik motor even though in the TI F28027 LaunchPad with the BOOSTXL-DRV8305 I don't have the ENCA-ENCB-ENCI input? If yes how?

Hi Antonin,

I'm trying to do this example with an F28379 and a DRV8305; I changed the Hardware Configuration on Configuration Parameters and the ADC & ePWM blocks in the FOC Algorithm, but when I click on "Deploy to Hardware" nothing happens. Do I have to do something else?
Thanking you in advance,

Elisa

Antonin

Hi Shaomu,
You can scale the ADC counts to engineering units. if you do so you would have to find the right fixed-point format for the units and adjust that fixed-point format as you operate on the signals or switch to floating point which is less efficient. While per-unit sounds complicated at first sight, it makes things much simpler and more efficient. The same algorithm can work for multiple motors by adjusting the per unit scalers, fixed-point format can stay the same throughout the model. We picked Q17 which provides enough resolution while allowing some integer part in the rare cases where operations go above the [-1 to 1] range. The ranges of intermediate calculation results rarely change as multiplying a signal that ranges from [-1 to 1] by another signal ranging from [-1 to 1] leads to a result ranging from [-1 to 1]. If you use engineering units, you will have to switch to floating point to avoid complicated fixed-point format conversions. It's feasible but you will reduce the performance and you may lose accuracy in the results while multiplying large quantities with small quantities. Best is to learn how to work with per-unit, which is what I'm showing in this example.
The ePMW block is a sink driver block. Providing a simulation output to this block is challenging and would force the simulation step to run at the processor frequency level which would inevitably drastically slow down the simulation. I would recommend to start using an average model for simulation like it is done in c2808pmsmsim.
I hope it helps,
Antonin.

Shaomu Zhu

Hi Antonin and Venkatesh,

If I understand correctly, the function of the subsystem “Input Scaling” is to convert the measured ADC currents to the per-unit value. What should I do if I want to use the real value rather than per-unit value of the measured ADC currents? Is it feasible to directly use the data from the outputs of the two ADC blocks for that purpose? I am looking forward to your insights!

Shaomu Zhu

Hi Antonin and Venkatesh,

I would like to know why the data type has been set for fixdt(1,32,17). I have noticed that the blocks provided by TI library are designed for 32-bit signed fixed-point number. But why is it important to have a Q value of 17? Is there any reason for that?

Shaomu Zhu

Hi Antonin and Venkatesh,

I have another question regarding ePWM block. I notice that there is no output of this block. I would like to know if it is possible to read or display the output of this ePWM block in Simulink?

Shaomu Zhu

Hi Antonin and Venkatesh,

I have some questions regarding the subsystem "PWM Scaling".

1. The input of this subsystem are the duty cycles. Could you please tell me why we should add 1 to the duty cycle and then multiply half of the PWM counter period?

2. I have built a control system where the MOSFETs are driven directly through on/off signals. However, I found out that the block "ePWM" is based on duty cycle. Is it possible to control the MOSFET directly based on on/off signals with the "ePWM" block? Or do I need to use another block to realize this? To make it more clear, for a conventional SVPWM, after the duty cycles are calculated, we use triangle waveforms for comparison to generate the on/off signals for MOSFETs. Why is it decided to input the duty cycles to the "ePWM" block not the final on/off signals? Which configurations should be done if the inputs are on/off signals instead of duty cycles?

Thank you!

Hi Riley,

Please consider using the 'c2808pmsmsim' model which provides a good starting point for simulation to verify the Motor control logic. Please update the motor parameters and control loop parameters in the model inline with your desired motor parameter and this way you can get close to tuning the real world Motor. The Simulation model provides convenient way to tune Motor and control logic parameters to get the model working that will generate desired outputs. Once you have got it working in the simulation stage, you can take these settings forward to the actual model that is supposed to do real time control of the actual Motor. Running this simulation model requires you to have the Simscape library without which you can't proceed. You can replace the Motor in the simulation model with Motor from Simscape library that matches your real world motor. Please go ahead with this simulation model to get a good estimation of the various parameter values.

HTH,
Venkatesh C

Hi Antonin,

I have been trying to implement your Simulink model to control a 12V BLDC hobby motor. I have completed a motor identification using TI’s Motorware and have included the retrieved parameters in my c28027pmsmfoc.m setup file. I am able to compile the code with the same process you have described in the video; however, it seems that my motor shaft is pulsing between two poles at a steady rate during operation. Do you think this is an initialisation error that is causing the problem? I would really appreciate it if you could suggest some steps that I could take to help identify the problem I am currently facing?

Kind Regards,
Riley

Antonin

Hi Arun Ashok,
1) The PWMxB outputs are enabled via the PWM Deadband Unit tab where you specify that B is the active high complementary of A. So you shouldn't have to manually enable the ePWMxB outputs, not sure why you had to do this.
2) Yes, there is a factor of 2 difference in the speed. This is a bug that we fixed in the version of this example that ships with the support package, I need to update the version in this file exchange submission. In the meantime, the best way to fix this is to specify the output data as fixdt(1,32,15) instead of fixdt(1,32,16) in the following block:
"c28027pmsmfoc/FOC Alogrithm/Torque Control Algorithm/Generating Space Vectors/Generating Raw Space Vectors/Sliding Mode Observer (SMO)/Debounce/Data Type Conversion1"
I'll fix the submission as soon as possible.
Thanks for your comments.
Best regards,
Antonin.

Arun Ashok

Hi Antonin,
I was able to run this model on F28027 Launchpad + 8301 booster pack only after a few modifications:
1. I had to enable ePWMxB in all the three PWMs and configure to operate complimentary to ePWMxA (changing the set and clear in CMPA compare field and do nothing elsewhere).
2. The actual speed was 600 RPM(measured using a tachometer), eventhough we set it for 0.5(300 rpm).This is due to the scaling factor 2 in Speed_loop_delay and Max_measurable_speed calculations ( atanPU in BEMF estimation has an output 0 to 1 and not -1 to 1). Please correct me if I am wrong.

Best Regards,
Arun Ashok

Arun Ashok

Hi Antonin,
Thanks for the reply. I will try that on our custom board and see the results. Meanwhile I would like to know why the embedded coder is still based on controlsuite and not the updated motorware suite? Is that due to licensing issues or closed code(like the FAST estimator)?

Best regards,
Arun Ashok

Antonin

Hi Arun,

Good question, you can profile your code using our execution profiling functionality. Here is a link to an example that explains the technique:

https://www.mathworks.com/help/supportpkg/texasinstrumentsc2000/examples/real-time-code-execution-profiling.html

Note that on the F28069 which runs at 90MHz we spin 2 motors and run twice the FOC algorithm within 50µS. I vaguely remember that it takes about 17µs to run the current control loop on the F28069 and about 25µS to run the control loop on the F28027. It's going to be hard to run at 100kHZ. To achieve this rate, you should upgrade to a faster device (F28379D - 200MHz), simplify the control logic (you could remove the sensorless and use position sensors) and consider offloading some of the processing to the CLA.

I hope it helps,

Antonin.

Arun Ashok

Hi,
I am trying to create FOC control for a PMSM. I see that in your example your PWM runs at 20Khz(50 usec), then I assume that your control loop with be running at 25 microsec or lesser. Is there any way to measure the loop execution time before actually deploying the code to the target board?
I want to try and test PWM code at 100khz or more, then my control loop time should be < 5usec. Will it be possible to do this in simulink or should I try coding in CCS directly to achieve this? Correct me if I am wrong.
Thanks in Advance!

Hi , how to control the angle in a BLDC

Antonin

Hi Rahul,

I would recommend starting with the TI documentation that lives inside controlSuite.
If you don't have controlsuite, download it here: www.ti.com/tool/controlsuite
Once installed go to the motor control library documentation. On my machine:
"C:\ti\controlSUITE\libs\app_libs\motor_control\math_blocks\v4.3\~Docs\DMC MATH_v13.1.pdf"
You can also look at:
http://www.ti.com/lit/ug/spru485a/spru485a.pdf and http://cache.freescale.com/files/microcontrollers/doc/ref_manual/DRM099.pdf
At a high level, you should look at: https://en.wikipedia.org/wiki/Sliding_mode_control
I hope it helps,
Thanks,
Antonin.

Hello Antonin,

can you share how did you make sliding mode observer? If you can provide any source which can help to construct the SMO then it will be very helpful for my project.

Thank you

regards
Rahul Lukhi

Suhwan Kim

Hi Antonin,
Thank you for your sensorless control logic. I would like to check theta information by using an integrator at speed, but there is an error "Only constant (inf) or inherited (-1) sample times are allowed in the asynchronous subsystem". Because this logic is asynchronous structure with hardware interrupts, it can not be working with continuous blocks. I tried to change the solver for continuous blocks, but it does not change any. Is there any way that I can check theta information in this logic?
Many Thanks,
Suhwan Kim
skim67@sheffield.ac.uk

Hello Antonin, thank you for your work and time, I have some question that, in my opinion, would be useful for all.
First of all my setup:
-motor: BLDC-42BF01 rs=1.1 ohm , ls = 454e-6 H, peak current 5.7A, (rated current 1.9A), voltage 24V...first question: what is the BASE FREQUENCY and how do you compute it?
-LaunchXL-F28069M with one DRV8301 and modified simulink model
The sysyem is working, i.d. the motor is spinning but sometimes it moves for few steps and then it stops, I think it's due to the set of the varoius parameters of the model. In particular can you explain each of them (Speed_rpm_scaler, Macx_measurable_speed, Max_ideal_measurable and so on)? and how to compute them?

Secondly, I managed to use the host.rx, why is the desired speed equal to 0.5? Is it a normalized value wrt to some parameter? how can we change it?
Thank you very much, indeed.
Christian

Hello Antonin,

Thank you very much for the video and the example!
I would like to ask you for help...I am running a control similar to the one of this example but my problem is that I cannot get the ADCs to read IA and IB currents. They are reading Vref (1.65V) all the time, as if there were not current...I suspect the problem is in the SOC, but I have all the settings of the PWM and the ADC like yours, I can send you some screenshots if you give me your email (you can write me at: lcdiaz@unizar.es) ...what can I be doing wrong?
I have already asked for help in TI forum, but nobody has replied. I am a little bit stuck here and I would really appreciate your help.

Thank you!
Lucía.

meriam mira

Hi Antonin,
i'm sorry for bothering, but i'm having trouble with the connection between Matlab R2016a and CCSv6, here's my checkEnvSetup('ccs', 'f28069', 'check')

1. CCS (Code Composer Studio)
Your version :
Required version: 3.3.82.13
Required for : Automation and Code Generation

2. CGT (Texas Instruments C2000 Code Generation Tools)
Your version :
Required version: 5.2.1
Required for : Code generation

3. DSP/BIOS (Real Time Operating System)
Your version :
Required version: 5.33.05
Required for : Real-Time Data Exchange (RTDX)

4. 2806x C/C++ Header Files
Your version : 1.51
Required version: 1.36
Required for : Code generation
DSP2806x_INSTALLDIR="C:\ti\controlSUITE\device_support\f2806x\v151"

5. Flash Tools (TMS320F2806x Piccolo(TM) Flash API)
Your version : 1.00a
Required version: 1.00
Required for : Flash Programming
FLASH_2806X_API_INSTALLDIR="C:\ti\controlSUITE\libs\utilities\flash_api\2806x\v100a"

Best regards,
Meriam

Thank you so much Antonin. it's working now. all I needed is a 20V Power supply with a higher amp instead of the 24V that I've been using.

Hi Antonin,

I tried it right now but still not working, I connected the MCU to the laptop with all jumpers off and built the program then connected the MCU to the drive and powered the drive but still not working.

I wanna send you a screenshot with the results, can you send me your email? or email me at tarek.m.yehia@gmail.com

Antonin

Hi Tarek,

I tested the model with the Teknic M-2310P-LN-04K and the motor spins smoothly.

One point to keep in mind: You need to apply the 20V (or 24V) prior to starting the program (or at the same time). The program has a few integrators and if it starts without the 20V power, these integrators will rail to their maximum very quickly. A simple way to avoid this is to unplug the USB cable after the code is flashed, make sure nothing is powered at this point and enable the 20V power to the booster pack. This will power your controller as well as your power modules and your motor should spin.

I hope it helps,

Antonin.

Antonin

Hi Stefan,

The reason for this type of license is because this is a standard shipping example of our Embedded Coder Support Package for TI C2000 Processors. Start from the model that ships with the support package and you should be fine with licensing issues.

I hope it helps,

Antonin.

Hello,
first of all it is a great tutorial.
I have one question to the license file which is part of the zip folder:
I read the license agreement and I do not know whether I understood or do not.

"3. LICENSE RESTRICTIONS. The License is subject to the express
restrictions set forth below. Licensee shall not, and shall not permit any
Third Party to:

3.1. modify, or create any derivative work of, any part of the licensed
Materials

3.2. adapt, translate, copy, or convert all or any part of the Materials
in order to create software or other materials, a principal purpose of
which is (a) to perform the same or similar functions as the Materials or
any other technology or materials licensed by MathWorks, or (b) to replace
any component of the Materials or any other technology or materials
licensed by MathWorks;"

Whats the purpose of this tutorial / file ?

I own a Matlab license but I will not be allowed to use this example for developing own products (including adaptions/ or to derive from it) ?

Best regards,

Stefan

Hi Antonin,

I'm sorry if i'm bothering you by many messages lately. I solved the problem of the serial connection so you can neglect the last comment. Now, I'm facing a different problem as the motor still doesn't rotate, it only rotates a discrete rotations for a second or two when I first connect the USB cable to my laptop, the desired speed scope in the host correctly point to 0.5. but the actual speed scope gives small random pulses, and the torque demand scope is pointing to 1.

If that help, I followed these random pulses in the actual speed backward to figure out where did they start. I found out they started from the loop of the park transformation and the (SMO) so I get these pulses from the unstable Theta, Vd and Vq.

The motor used: Teknic M-2310P-LN-04K 6000rpm 4.6V/rpm

The power supply used: 24 volt DC , 2.5A max

another note: when I build the model, the 4 LEDs in GPIO 0123 are not solid blue as before building the model. they blink slightly.

I really don't know what's wrong with it.

Best Regards,

Tarek Doghish

Hi Antonin,

all the switches are up, no matter I keep the jumpers on or not, I still get the same warning message. The thing is when I try to build the c28027pmsmfoc_ert file without even having the MCU connected to the laptop, I still get the same results as the building is done successfully and get the warning message with nothing connected to my laptop.
I'm using Matlab2016a and here's my checkenvsetup:

>> checkEnvSetup('ccsv5','f28027','check')

1. CCSv5 (Code Composer Studio)
Your version : 6.1.0
Required version: 5.0 or later
Required for : Code Generation
TI_DIR="C:\ti\ccsv6"

2. CGT (Texas Instruments C2000 Code Generation Tools)
Your version : 6.4.6
Required version: 5.2.1 to 6.0.2
Required for : Code generation
C2000_CGT_INSTALLDIR="C:\ti\ccsv6\tools\compiler\c2000_15.12.3.LTS - Copy"

3. DSP/BIOS (Real Time Operating System)
Your version : 5.42.02.10
Required version: 5.33.05 to 5.41.11.38
Required for : Code generation
CCSV5_DSPBIOS_INSTALLDIR="C:\ti\bios_5_42_02_10"

4. XDC Tools (eXpress DSP Components)
Your version : 3.32.01.22.
Required version: 3.16.02.32 or later
Required for : Code generation

5. 2802x C/C++ Header Files
Your version : 2.20
Required version: 2.20
Required for : Code generation
DSP2802x_INSTALLDIR="C:\ti\controlSUITE\device_support\f2802x\v220"

6. Flash Tools (TMS320F2802x Piccolo(TM) Flash API)
Your version : 2.01
Required version: 2.01
Required for : Flash Programming
FLASH_2802X_API_INSTALLDIR="C:\ti\controlSUITE\libs\utilities\flash_api\2802x\v201"
>>

what do you think could be wrong?

Thank you so much

Tarek Doghish

Antonin

Hi Kamal, hi Tarek,

Even if you don't connect a motor, the serial host model should receive data and you shouldn't see the following warning message on the host (Unsuccessful read: The specified amount of data was
not returned within the Timeout period...)

That's a good way to first verify that code is running on the board.
Please make sure that your boot switches on the LaunchPad are all in the "On" position. The serial switch should also be in the "On" position.

Here is a good page that helps making sure the COM port is properly configured:

http://processors.wiki.ti.com/index.php/Using_the_serial_adapter_of_XDS100

I successfully tested the example with the DRV8305 Booster Pack. It works the same as the DRV8301 and I can spin my motor without modifications. I also tested the 2 versions of the Launchpad (F28027 and F28027F), they both work.

To be on the safe side, you can actively drive GPIO7 high to make sure that you take the DRV8305 out of sleep mode, but this step is not necessary on my side.

Go to "c28027pmsmfoc_ert/FOC Algorithm/DRV8301 Enable" and set GPIO7 in addition to GPIO6 at this step.

Another important point, MOSFET power needs to be "On" while the code starts. The control algorithm has integrators that will be saturating if there is no reaction from the system.

I hope this helps,
Thanks,

Antonin.

Kamal Joshi

Can this also be implemented for a low inductance motor on LAUNCHXL - F28027F ?

Kamal Joshi

How can I run the similar model for DRV8305 ?

Hey Antonin

I got the same problem as "Sreenath m" about the host_rxl giving an error (Warning: Unsuccessful read: The specified amount of data was
not returned within the Timeout period..)

I did everything you told him and "Cheyang" except Putty I couldn't do it and it's still not working.

can you tell me how to use putty or what else could be the problem?

Thanks

Tarek Doghish

Hi Antonin,

I have had everything done like the video with no errors, the model is built correctly but the motor is not rotating and on the host model all the scopes are pointing to Zero.

do you have any idea what could be the problem?

Thanks in advance

Tarek Doghish

haibo tan

Hi,

Antonin,think you so much for replying,I will have a check again.

Cheers,

Antonin

Hi team,
One common question I'm going to explain here:
"Why is there a -1 gain in the input scaling subsystem applied to the Ia and Ib currents".
The BOOSTXL-DRV8301 uses an inverted amplifier circuit to sense currents on Ia, Ib and Ic.
This is shown at page 7 of the following document (for Ic):
http://www.ti.com/lit/ug/slvu974/slvu974.pdf
The -1 gain reverts back the current to the real value.
Other motor control examples may not use this gain depending on how the sensing is done on the hardware.
I hope it helps,
Antonin.

S V

Hi Antonin,

I am using the DRV8312-69M-KIT with the c28069pmsmfoc_ert.slx model. The serial monitor block was added to this simulink model, but host_rx simulink model is not reading any data back. The COM port number/baud rate are set to match the PC port and VCP is enabled for emulator B. In SCI transmit, both options for SCI Module (A and B) was tried, but no joy.

Any idea what could be wrong.

Thanks

vinod kumar

Hello,

After connecting TMSDOCKf28335, I am getting this error...

*** Connecting to target...
*** Loading the program to the target...
*** Program is running.

*** Disconnecting from target...
SEVERE: Timed out after 90000ms
SEVERE: Error disconnecting from the target: Timed out after 90000ms

*** Terminating debug session...

Once I unplu and plug the dsp, it is not retaining the file

I have a Problem running this version:

IC:/MATLAB/SupportPackages/R2015b/texasinstrumentsc2000/toolbox/target/supportpackages/tic2000/inc -I/f2802x_common/include -I/f2802x_headers/include -I --output_file="MW_c28xx_board.obj" "MW_c28xx_board.c"
"MW_c28xx_board.c", line 1: fatal error: cannot open source file "F2802x_Device.h"
1 catastrophic error detected in the compilation of "MW_c28xx_board.c".
Compilation terminated.

Can you help me?

Best,
Andreas

We run were able to run motor with sensorless control. Now I am also interested in running it with optical encoder as speed sensor. What changes are required to make in MATLAB model

peter lee

Hi,Antonin. Thanks for your model. I am wondering why you scale the current and speed to per unit. Thanks.

peter lee

Antonin

>> lays25

stdbool.h comes with your compiler. Make sure that you run targetupdater and point to a valid compiler and CCS version.
I hope it helps,
Thanks,
Antonin.

Antonin

>> Abdulhakim

In this particular demo we use the following motor:
Anaheim Automation BLY172S-24V-4000

http://www.anaheimautomation.com/products/brushless/brushless-motor-item.php?sID=143&pt=i&tID=96&cID=22

We also use the following motor for other demos:

Teknic M-2310P-LN-04K

https://www.teknic.com/products/hudson-motors/pricing-specs-hudson-motors/

We have used conservative PI gains, which makes this example compatible with many 3-phase motors, you can probably adjust it to any motor with minor tweaks.

I hope it helps,

Antonin.

lays25

Hi Sumith,

I really wanted to follow your advice and see if it works but in the meantime I needed to reinstall Matlab and now it seems I cannot even return to the point I was stuck at earlier. I re-ran all the configuration steps as before but when I try to build any Simulink model with CCS v3.3, all I get in CCS during compilation is an error which is displayed by each file that CCS attempts to compile: ""D:/programy/controlSUITE/device_support/f2802x/v220/F2802x_Device.h", line 104: fatal error: could not open source file "stdbool.h""

My checkEnvSetup says that everything is in order ("Your version" equals "required version" in all 5 fields).
1. CCS (Code Composer Studio)
Your version : 3.3.82.13
Required version: 3.3.82.13
2. CGT (Texas Instruments C2000 Code Generation Tools)
Your version : 5.2.1
Required version: 5.2.1
3. DSP/BIOS (Real Time Operating System)
Your version : 5.33.05
Required version: 5.33.05
4. 2802x C/C++ Header Files
Your version : 2.20
Required version: 2.20
5. Flash Tools (TMS320F2802x Piccolo(TM) Flash API)
Your version : 2.01
Required version: 2.01

What exactly am I missing? Was there any compiler that was somehow removed during the reinstallation process?

abdulhakim

hey i have question could you please tell me what is the specification of the motor that you used and from where can i get one of these, thanks

Hi lays25,

Your checkEnvSetup results looks good. Please use the path
(CONTROLSUITE_PATH)\libs\utilities\flash_api\2802x\v201a\lib\Flash2802x_API_V201.lib in the "Specify API location" parameter.

(CONTROLSUITE_PATH)\libs\utilities\flash_api\2802x\v201 will not work as the include files in the folder (CONTROLSUITE_PATH)\libs\utilities\flash_api\2802x\v201\include are for F2803x processors.

Also you can use the ert.tlc based example c28027pmsmfoc_ert which supports auto download feature with CCSv4/v5.

Hope this helps.
Sumith

lays25

I've been having a lot of problems trying to run this example. I am using the F28027 Launchpad, running Matlab 2013b and CCS v3.3. I evetually got to the point where I get no errors during compilation in CCS but then Simulink opens up a link (http://www.ti.com/tool/sprc848) in a new window and gives me the following error message:

The call to idelink_ert_make_rtw_hook, during the exit hook generated the following error:
Error while loading and running the program.

The build process will terminate as a result.

Caused by:
Error while loading and running the program.
The TI flash API library does not exist on your machine. Specify the right path or download the appropriate flash APIs from TI's website or TI's controlSUITE installer.

Of course I have run checkEnvSetup and I get the following, which I reckon is correct and means the Flash API is installed and its path configured

5. Flash Tools (TMS320F2802x Piccolo(TM) Flash API)
Your version : 2.01
Required version: 2.01
Required for : Flash Programming
FLASH_2802X_API_INSTALLDIR="D:\programy\controlSUITE\libs\utilities\flash_api\2802x\v201"

Also, when I go to Model Configuration Parameters -> Coder Target -> Target Hardware Resources -> Flash_API, the "Specify API location" is set to "C:\tidcs\c28\Flash28_API\Flash2802x_API_V100\lib\Flash2802x_API_V100a.lib". Even if I change it to the aforementioned path, it always resets to this one after a failed "build & run". So I downloaded the Flash API v2.00 from the suggested link (http://www.ti.com/tool/sprc848) and installed it into the default path (C:\tidcs\...), then set it using checkEnvSetup (this time I got: your version: 2.00, required version: 2.01 which I guess is not OK). Same story.

And by the way, entering any path into the "Specify API location" field and clicking Execute pops up a window saying: "The first input to exist must be a string".

I have absolutely no idea how to get it to work. Anybody, please help me.

Hi Antonin,
Great video and thanks for the detailed instructions. Could you comment on whether these instructions will work in Matlab (R2014a) running on Linux (Ubuntu 14.04) as well? Do I need to plan to do some tweaking for this to get going? I have ordered the hardware and hope this will be doable. Let me know your thoughts.

Hello Antonin,
I do not wanna spam, but I have already made it work. You were right that it was the compiler problem, the path of compiler contained non-ASCII characters, so the new account which did not contain them helped. Thank you very much for your help and for your entire work. Martin

Hello Antonin,
thank you very much for your answer but I still could not make it work. I have tried a lot of compilers, the newest ones, e.g. 15.6.0, 6.4.6, 6.2.5 and many others. I have CCSV5. Still having the same problem. Sometimes appeared this:
C:/ti/INSTAL~1/c28069pmsmfocdual_ert_rtw/MW_c28xx_board.c"
gmake: *** [MW_c28xx_board.obj] Error -2147483645
I don´t wanna bother you anymore but do you have any idea what could possibly go wrong?
Thank you very much.
Martin

sreenath m

what changes are to be done in block diagram for varying speed of motor using pot? where can i connect the port?

sreenath m

Thanks antonin, i got the result...

Antonin

>>Martin,
The message you are getting is coming from your compiler. You may be using an old compiler that doesn't support the F28027.
I would suggest that you download a newer version of the compiler. If using CCSv3.3, the latest compatible compiler is 6.2.5, use the following page to find compilers:
http://software-dl.ti.com/codegen/non-esd/downloads/download.htm
Use the following page for upgrade instructions:
http://processors.wiki.ti.com/index.php/Compiler_Installation_and_Selection
I hope it helps,
Good luck,
Antonin.

Antonin

>>Ana,
It sounds that you have installation issues. I would strongly recommend that you go through the installation steps again, especially targetupdater and checkEnvSetup. You can select the installation for CCSv5 and point to CCSv6. This will work, just point to the CCSv6 folder. In checkEnvSetup, you still have to call the function with the 'ccsv5' argument.
I hope it helps,
Good luck,
Antonin.

Antonin

>>Sreenath
If you face problems with the serial communications, here are a few things you can try:
Open a hyperterminal like putty (http://www.putty.org/) and verify that you are seeing incoming characters when opening a session on your COM port.
Also make sure that you have the VCP enabled on the xds100 channel B of the hardware manager. There are explanations on how to do this on the following page:
http://processors.wiki.ti.com/index.php/Using_the_serial_adapter_of_XDS100
I hope it helps,
Antonin.

Antonin

>> Stan:
Thanks for the feedback. The models open and work in 14b. They are compatible with all MATLAB releases above 13b (inclusive). Make sure you go through the installation steps. You may have to rerun targetinstaller and checkEnvSetup when you switch to a new version of MATLAB.
For the SMO, I suggest you start with TI's documentation. You can look in the following controlSuite folder, on my machine:
"C:\ti\controlSUITE\libs\app_libs\motor_control\math_blocks\v4.3"
Search "\~Docs\DMC MATH_v13.1.pdf" for SMO.
You can also look in smopos.h
I hope it helps,
Good luck,
Antonin.

Hello Antonin,
I would to ask you for a help with my problems regarding the compilation of the simulink scheme. It always ends up with saying this: Debug Assertion Failed!
Program: C:\ti\ccsv5\tools\compiler\c2000_1\bin\cI2000.exe
File:isctype.c
Line:56

Expression: (unsigned)(c+1)<=256

And then there is the diagnostic viewer, which is always telling me the same:
INTERNAL ERROR: C:/ti/ccsv5/tools/compiler/c2000_1/bin/cl2000 aborted while
processing file C:/ti/c28069pmsmfocdual/c28069pmsmfocdual_ert_rtw/MW_c28xx_board.c

This is a serious problem. Please contact Customer
Support with this message and a copy of the input file
and help us to continue to make the tools more robust.

gmake: *** [MW_c28xx_board.obj] Error 2

I am pretty sure, that I have gone through all the installation and validation steps correctly, but I simply can´t solve this great obstacle. Could you please help me? Thank you very much for the answer.
Martin
PS: I´m using MATLAB R2015a

ana hariss

Hi Antonin,
I need a new toolchain for 2014b and 2802x, it builds well with ti_ccsv5 when using 28069M but for 28027 : no way !
the directories generated by the makefile are not good, I need to fix that in the toolchain
so I can I have one and how to register it
thanks

PS I also tried the example http://www.mathworks.com/matlabcentral/fileexchange/45124-motor-control-with-ti-launchpadit

but no way, it does not compile

http://www.mathworks.com/matlabcentral/answers/229500-matlab-2014b-c2000-ccs6-1-ccsv6-toolchain-needed

ana hariss

Hi Antonin,
I need a new toolchain for 2014b and 2802x, it builds well with ti_ccsv5 when using 28069M but for 28027 : no way !
the directories generated by the makefile are not good, I need to fix that in the toolchain
so I can I have one and how to register it
thanks
http://www.mathworks.com/matlabcentral/answers/229500-matlab-2014b-c2000-ccs6-1-ccsv6-toolchain-needed

sreenath m

Hello Antonin,
I have some problem with host file(serial interfacing motor control).It is not properly working.can u plz help me getting rid of this problem.It shows that "Unsuccesful read: Specified amount of data was not returned with in the specific timeout period".I have tried all the methods u suggested. I correcrd port number.I hv refreshed rate of the signals in the Simulink host model host_rx is 50ms. In the host_rx model

Hello Antonin,

Excellent job! Just two short questions:

Q1: Is won't open in V2014a (8.3 Simulink) /Could not open source code/. Surely it could be ported manualy (shares a lot in common with your other excellent example for F28096 - opens in V2014a), but isn't there a shorter way?

Q2: If possible, could you share with us a source (article) you used to synthetize your SMC velocity observer? I am trying to make a sense out of it and straight from Simulink schemes it is never quite easy.

GREAT JOB !!!
With Best Regards
Stano

Antonin

Hi Sreenath,

This is benign. It just tells you that int8 will be emulated on your processor as the smallest container in 16 bits.
As a guideline, I recommend not to use 8 bit data types on the TI C2000 processors.
I hope it helps,
Good luck,
Antonin.

sreenath m

sir,
while building c28027pmsmfoc_ert i'm also encountering a
Warning: The data type "int8" uses a word size that is not available on the intended target. Fixed-point signals using this data type will be put inside a larger word or multi words. When used,extra software will be generated to force this larger word or multi words to emulate a smaller word. This emulation is helpful when your prototype target and your final production target are not the same. If the smaller word size does NOT exist on the final production target, then consider increasing the word size to
one that is supported.
what shouldi do..

Antonin

Dear Indulal Sreedharan,

From the error message that you are passing, it looks like the code can't be loaded on the target.
The code generation went through successfully but the load failed.
You need to run targetupdater. The first question asked is the location of the codegen tools (the TI C2000 compiler). If you pick the one located in the CCS folder (i.e. C:\ti\ccsv5\tools\compiler\c2000_6.2.0), the installer will be smart enough to locate the download scripting tool. If you point to another installation of the codegen tools, you should get a message that asks you to locate the download scripting tool located in the CCS folder (i.e. C:\ti\ccsv5\ccs_base\scripting). You can run targetupdater at any time without downloading the support package again. Make sure that you complete that step successfully, it should fix the error and allow you to download the code to the target automatically.
I hope it helps,
Cheers,
Antonin.

Antonin

Dear Cheng-Ying Chung,
Note that I am monitoring the speed control loop signals which are updated every 10ms. To do so I'm using a serial Transmit block via a 50ms rate transition block located inside Speed Controller/Serial Monitor, so the refresh rate of the signals in the Simulink host model host_rx is 50ms. In the host_rx model, make sure that your COM port is set correctly, by default I'm using COM2, this has to match your LaunchPad virtual COM port. Read my comment to Rusu Sadu below for more info.
I hope it helps,
Antonin.

Dear Antonin,
The period of PWM is 20KHz and the Baud rate of SCI is 115200. The transmission rate of SCI is slower than the interrupt period. I am confused that why the waveform in the host PC can run in real time. Actually, it showed the message "warning: unsuccessful read: the specified amount of data was not returned within the Timeout period" in the command window when I run the host_rx program.

Dear Antonin,
I have successfully uploaded the code to the target board but the debugging side was showing the following error messages

SEVERE: Cannot read System Setup data from XML file C:\MATLAB\SUPPOR~1\R2013b\tic2000/CCS_CO~1/F28027~1.CCX
Error parsing file:
Fatal Error at (0, 0): An exception occurred! Type:RuntimeException, Message:The primary document entity could not be opened. Id=C:\MATLAB\SUPPOR~1\R2013b\tic2000\CCS_CO~1\connections\TIXDS100usb_Connection.xml while parsing file: C:\MATLAB\SUPPOR~1\R2013b\tic2000\CCS_CO~1\connections\TIXDS100usb_Connection.xml
SEVERE: Could not start server: DebugServer.1: Cannot read System Setup data from XML file C:\MATLAB\SUPPOR~1\R2013b\tic2000/CCS_CO~1/F28027~1.CCX
Error parsing file:
Fatal Error at (0, 0): An exception occurred! Type:RuntimeException, Message:The primary document entity could not be opened. Id=C:\MATLAB\SUPPOR~1\R2013b\tic2000\CCS_CO~1\connections\TIXDS100usb_Connection.xml while parsing file: C:\MATLAB\SUPPOR~1\R2013b\tic2000\CCS_CO~1\connections\TIXDS100usb_Connection.xml
*** Cannot create a valid debug session for Board/CPU=*/*.
Make sure this matches only one board and one CPU.
Exiting...

"### Done invoking postbuild tool."
### Successful completion of build procedure for model: c28027pmsmfoc_ert
### Creating HTML report file c28027pmsmfoc_ert_codegen_rpt.html

Motor did'nt run

The version of Matlab was 2013b

Antonin

>> Michal
It looks like the toolchain selected in the model has defaulted to the lcc compiler that ships with MATLAB instead of using the TI toolchain.
This could happen if the TI C2000 support package is not properly installed. Make sure you go through the targetinstaller and targetupdater steps described in the video.
The TI toolchain should be selected in the configuration parameters after you open the model. I hope it helps.

Antonin

>> rusu sadu
Your COM port is not set correctly for the host block to receive messages from the LaunchPad. Go to the Windows Device Manager and check which COM port is used by the "USB Serial Port" under "Ports (COM & LPT)".
In the host_rx model, open the "SCI Receive" block to select the matching serial port you want to use. COM2 is selected by default. From the error message you get, it sounds like COM4 could be the right value to select.
The host serial blocks only support COM port value up to COM4. In the Windows Device Manager you can change the value of the COM port if you get a COM port value bigger than 4. If you don't want to change the COM port value, the Instrument Control Toolbox provides a more powerful host serial block that allows a wider range of COM port selections. I hope it helps.

rusu radu

I tried to run this model in matlab 2013b but in run host_rx ghiv this error:
Error evaluating registered method 'Start' of MATLAB S-Function 'c2000hostsci_setup' in 'host_rx/SCI Setup'. The following is the MATLAB call stack (file names and line numbers) that produced this error:
['C:\Program Files\MATLAB\R2013b\toolbox\matlab\iofun\@serial\fopen.m'] [72]
['C:\MATLAB\SupportPackages\R2013b\tic2000\blocks\masks\c2000hostsci_setup.m'] [156]

Caused by:
Open failed: Port: COM2 is not available. Available ports: COM4.
Use INSTRFIND to determine if other instrument objects are connected to the requested device.

Michal

I tried to run this model in the Matlab 2014a and unfortunatelly got following error while code generation:
Making simulation target "c28027pmsmfoc_ert_sfun", ...


D:\motor\matlab\Launchpad_Motor_Control\slprj\_sfprj\c28027pmsmfoc_ert\_self\sfun\src>"C:\Program Files\MATLAB\R2014a\sys\lcc64\lcc64\bin\lccmake.exe" -f c28027pmsmfoc_ert_sfun.lmk
"C:\Program Files\MATLAB\R2014a\sys\lcc64\lcc64\bin\lcc64.exe" -dll -noregistrylookup -c -Zp8 -DLCC_WIN64 -DMATLAB_MEX_FILE -DMX_COMPAT_32 -nodeclspec -I"C:\Program Files\MATLAB\R2014a\sys\lcc64\lcc64\include64" -I"C:\Program Files\MATLAB\R2014a\extern\include" -I"C:\Program Files\MATLAB\R2014a\simulink\include" -I"C:\Program Files\MATLAB\R2014a\stateflow\c\mex\include" -I"C:\Program Files\MATLAB\R2014a\rtw\c\src" -I"D:\motor\matlab\Launchpad_Motor_Control\slprj\_sfprj\c28027pmsmfoc_ert\_self\sfun\src" "c28027pmsmfoc_ert_sfun.c"
"C:\Program Files\MATLAB\R2014a\sys\lcc64\lcc64\bin\lcc64.exe" -dll -noregistrylookup -c -Zp8 -DLCC_WIN64 -DMATLAB_MEX_FILE -DMX_COMPAT_32 -nodeclspec -I"C:\Program Files\MATLAB\R2014a\sys\lcc64\lcc64\include64" -I"C:\Program Files\MATLAB\R2014a\extern\include" -I"C:\Program Files\MATLAB\R2014a\simulink\include" -I"C:\Program Files\MATLAB\R2014a\stateflow\c\mex\include" -I"C:\Program Files\MATLAB\R2014a\rtw\c\src" -I"D:\motor\matlab\Launchpad_Motor_Control\slprj\_sfprj\c28027pmsmfoc_ert\_self\sfun\src" "c28027pmsmfoc_ert_sfun_registry.c"
"C:\Program Files\MATLAB\R2014a\sys\lcc64\lcc64\bin\lcc64.exe" -dll -noregistrylookup -c -Zp8 -DLCC_WIN64 -DMATLAB_MEX_FILE -DMX_COMPAT_32 -nodeclspec -I"C:\Program Files\MATLAB\R2014a\sys\lcc64\lcc64\include64" -I"C:\Program Files\MATLAB\R2014a\extern\include" -I"C:\Program Files\MATLAB\R2014a\simulink\include" -I"C:\Program Files\MATLAB\R2014a\stateflow\c\mex\include" -I"C:\Program Files\MATLAB\R2014a\rtw\c\src" -I"D:\motor\matlab\Launchpad_Motor_Control\slprj\_sfprj\c28027pmsmfoc_ert\_self\sfun\src" "C:\Program Files\MATLAB\R2014a\sys\lcc64\lcc64\mex\lccstub.c"
"C:\Program Files\MATLAB\R2014a\sys\lcc64\lcc64\bin\lcclnk64.exe" -s -dll -L"C:\Program Files\MATLAB\R2014a\sys\lcc64\lcc64\lib64" -entry LibMain -map sfun.map -o c28027pmsmfoc_ert_sfun.mexw64 @c28027pmsmfoc_ert_sfun.lmko
Time: 29.531 seconds

Michal

Will this example also work for the Matlab R2014a? Next release after the one you develop with. In the past I had the problem with using c2000 target different Matlab releases.

Antonin

>>Rusu
There are 2 models, the c28027_pmsmfoc works with CCSv3.3 which is probably not installed on your system, that is why you are getting the error.
Use c28027_pmsmfoc_ert for CCSv4/5/6, that is the recommended version.
I you really want CCSv3.3 support, watch the following video for installation instructions:
https://www.youtube.com/watch?v=Pcx-VGU1MIM
I hope it helps,
Antonin.

rusu radu

I tried to run this good example but it gives me this error:
The call to idelink_ert_make_rtw_hook, during the entry hook generated the following error:
Could not connect to the board specified in the Target Hardware Resources tab on the Coder Target pane in the Configuration Parameters dialog.

The build process will terminate as a result.

Caused by:
Could not connect to the board specified in the Target Hardware Resources tab on the Coder Target pane in the Configuration Parameters dialog.
Cannot establish a connection to the MathWorks plug-in component in CCS application. Verify that the plug-in is installed and enabled properly.
For more information on troubleshooting the problem, please refer to IDE Link FAQ.

Antonin

>> Kevin Huang.
In this example, we use the default configuration of the DRV8301, so we don't need to initialize it via SPI.
In the default configuration, the upper and lower sides of the "H" bridge have to be independently controlled. We force ePWMB to be the complementary of ePWMA adding dead-bands to ensure that there is no "shoot-through".
Our SPI Simulink block can also be used to initialize the DRV8301 to a different configuration.
I hope it helps.

Antonin

>> Nandor Bodo.
Most eval kits come with an on-board xds100 emulator that provides a serial connection as well as a JTAG connection to the processor. You need the serial lines to be connected to the xds100 for the serial connection to work. I'm not sure if an "off the shelf" xds100 emulator will allow you to connect the serial lines, it may only provide the JTAG connection. If you use the ISO versions of the TI control cards, you will get an on-board xds100 that will have the serial connection (as well as JTAG). I hope it helps.

Kevin Huang

Does this model include setting DRV8301 configuration, operating parameters, and read out diagnostic information by SPI interface?

Nandor Bodo

Hi Antonin,

Really useful stuff.

I used your application to start learning about Simulink programming of C2000, I have an Experimenters kit platform, though.

I noticed you use only one cable for programming the controller and getting feedback through the serial port. Can I do the same? I program my Experimenter Kit with a usb cable. So I have the XDS100V Jtag emulator already on the Kit.

Antonin

More information on how the models have been created and how to use them in the following video:
http://youtu.be/wxYTLbYfBP0

Updates

1.4.0.0

Fixed a factor of 2 in the speed calculation

1.3.0.0

Added a picture to this post

1.3.0.0

Added video link

1.2.0.0

Updated models

MATLAB Release Compatibility
Created with R2013b
Compatible with R2013b to any release
Platform Compatibility
Windows macOS Linux
Communities

Launchpad_Motor_Control