This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Matlab link to CCS v4 for Concerto/F28M35 (control side only)

Other Parts Discussed in Thread: CONTROLSUITE

Hello, Its been a wile since I started using Concerto and there might be changes, but i managed to make/generate code on the matlab for the Concerto. Sorry for my "not so fluent" english.

This ‘how to’  is not a step-by-step tutorial and requires that the reader has already installed Matlab/Simulink®, Code Composer Studio® (CCS) and ControlSuite (CS) (at least version 2.6 must be installed). The reader must be familiar with CCS, IQMath® and how to program a microcontroller, in this case the F28M35 Concerto series, a dual core Stellaris/Delfino (LINK). I will no explain how to configure GPIOs or use PWMs, etc...


Before we start you need to prepare your simulink model accordingly and know that:
-    The Concerto “Control” side is a Delfino, but if you try and program its ADCs as you would do in a normal Delfino you will notice that its different, the ADC in the Concerto is of type 3 and not of type 2 as in regular Delfino. (see section 3.5 of LINK and chapter 6 of LINK)
-    Just a small warning for the readers who are starting to use this link between matlab and CCS: Be aware of IQMath constants, depending on its type/number, their  value might saturate.
-    After you have your model working/compiling without errors, execute the command xmakefilesetup on matlab console and change the options according to this LINK. Afterwards, press Ctrl+E in your model to access the model configuration window, and in the IDE/Tool Chain selection choose: makefile generation only, see Fig. 1


Fig. 1 Select makefile generation only


    Compile the code using Ctrl+B in your Simulink model. During the process, matlab will generate, in the same folder as the model, a folder with the same name as the model. See Fig 2 for an example were the simulink model name is “dsp_rect_new_test1”.
 


Fig. 2 Files in the matlab generated folder


    The files in yellow in Fig. 2 are the ones to be copied to a new project in CCS v4. These files contain the model and some configuration code that would be enough to program the Delfino. Please read the information in chapter 2 of the file in  (CS folder) \ device_support \ f28m35x \ v??? \ doc \ F28M35x-FRM-EX-UG.pdf to help you create a new project in CCS v4. Please skip the part for creating a main.c  source code. The main() function is already defined in your name_of_model_main.c  file.
    After the project is created according to the previous pdf file, you need to add the files created by Matlab to the project (adding them, not linking). To add files right click your project with in CCS and select “Add Files…”. Do this for rtwtypes.h present in the generated folder and every file in yellow according to Fig. 2. (leave the folder derived). For CCS to compile properly you will have to link (Link Files… in right button menu) the file c2000_main.h present in you matlab installation folder: ... \ MATLAB \ R20XXx \ toolbox \ idelink \ extensions \ ticcs \ inc \ .


    So far so good, now you need to change the Included files in the several source files generated by Matlab (that are for the Delfino in the format DSP280x…h!) Luckily, as they are “the same” microcontrollers the names are almost equal and you just have to change from DSP280x format to F28M35x format in most of the cases. For that check these folders:
          C:\TI\controlSUITE\device_support\f28m35x\v100\F28M35x_common\source
          C:\TI\controlSUITE\device_support\f28m35x\v100\F28M35x_common\include
          C:\TI\controlSUITE\device_support\f28m35x\v100\F28M35x_headers\include
          C:\TI\controlSUITE\device_support\f28m35x\v100\F28M35x_headers\source

    To help identifying the F28M35x.XXX.h/c files needed to add/link to the project you can make a list of the .obj files generated by matlab compiler, present in the “derived” folder identified in yellow in Fig. 2. In Fig 3 you can see an example of all the files added and linked for my project where I use the ADC, PWM and SPI peripherals.

    Considering that the Delfino/control part of the Concerto doesn’t need the same initial setup as the normal Delfino, and that we changed the include files it is necessary to configure the appropriate ports and system configuration in the ARM/Master part of the Concerto. This is outside the scope of this small “tutorial”, please read the appropriate documentation. If you don’t know what to do and just want to use the Delfino part of the Concerto with matlab generated code, please compile and run “setup_m3” project on your ARM (can be found in …controlSUITE \ device_support \ f28m35x \ version \ F28M35x_examples_Control). This will give the Delfino access to all the peripherals and pins/legs of the Concerto chip (PWM, GPIO, etc)


    After this is up to the user to decide which functions to change as they will be different from user to user. I leave a list for common changes:
•    init_board() function, in MW_c28xx_board.c should be edited to be compatible with the Concerto, the initial setup where the System and peripherals clocks are defined should be skipped as this is done on the ARM part.
•    The function name_of_model_initialize() in the file name_of_model.c can be changed according to the needs of your GPIO. (Remember, the clock associated with GPIO, the pull-up resistances, direction, etc. are configured on the ARM side).
•    c2000_main.h is a strange file :) I’ve been trying to figure out what it does but with no luck. This file makes validations on variables that might generate errors as being undeclared. To avoid these errors please comment (Ctrl+Shift+7) the lines that check for RT, MODEL, NUMST e NCSTATES. Or you can define them in your code if you know what they mean. (RT prob. means real time, but it is not used anywhere on the code, at least in my code, so far).
•    In my application I had to add to the ADC configuration the following lines to be able to use the ePWM module to start the ADC acquisition:
          AnalogSysctrlRegs.TRIG1SEL.all     = 5;
          Adc1Regs.ADCCTL2.bit.ADCNONOVERLAP = 1;
These commands tell the ADC module to monitor ePWM1 to start an acquisition (read the Concerto Techincal Manual for more configuration possibilities)
•    With these changes your code probably compiles without errors and if lucky with no warnings (If you find errors stating that you have undeclared functions, please look for them in the .c files and make a .h files with the same function names and declare them as they are in the .c files  - make a header file for the source file generated by matlab). I had this problem with the initialization of the ADC, the function was declared in the c. file of MW_c28xx_adc.c but it wasn’t recognized by the compiler until I added a  MWc28xx_adc.h and included it on name_of_model.c.


Contents of MWc28xx_adc.h:


                #ifndef MW_C28XX_ADC_H_
                #define MW_C28XX_ADC_H_

                void InitAdc(void);
                void config_ADC_SOC0(void);
                void config_ADC_SOC1(void);
                void config_ADC_SOC2(void);
                void config_ADC_SOC3(void);
                void config_ADC_SOC4(void);
                void config_ADC_SOC5(void);

                #endif /*MW_C28XX_ADC_H_*/
        


        To be able to use the PWM I had to do the same with the GPIO configuration functions, made a file called MW_c28xx_pwm.h with the following contents:


            #ifndef MW_C28XX_PWM_H_
            #define MW_C28XX_PWM_H_

            void config_ePWM_GPIO (void);

            #endif /*MW_C28XX_PWM_H_*/

    In Fig 3 there is a list of all the files I needed to compile (without errors and warnings) a small 3 phase rectifier, which means, 5 ADC channels, 3 PWMs (A and B = 6 signals total).

Fig. 3 List/example of the files needed for CCS

Hoping this will be helpful,

Rui Ventura

  • Great information!  Thank you for sharing.

  • You Welcome Lori, thank you for all your work!
    Reading these forums and learning from this community made/makes my work a lot funnier, I just feel obliged to share and help wherever and whenever I can.
    So, thank you!


  • Hi, I have a problem with my DSC and hope you might be able to help me:

    I am using ezDSP F28335 with Code Composer Studio 3.3 and want to use it with Matlab R2009a and the Target Support Package TC2.

    I can connect to the microcontroller via CCS 3.3 and I can also build a project in Simulink with Target Support Package TC2. But somehow, the PWM (and the ADC i guess, too) doesn't work properly. I just tried to use the demo-models that are included in the Target Support Package. If I use the first demo (ADC-PWM Synchronization via ADC Interrupt ; It generates a PWM out of the signal on the ADC) I sometimes get a PWM signal on the oscilloscope. But the most times I just see a PWM Signal for about 1 second at the beginning of the running cycle of the DSC. As "Signal" at the ADC I use a DC Power-Supply with about 1V. If I (as it is in some cases) see a PWM on the screen, a change of the supplied voltage on the ADC doesn't change anything about the duty cycle of PWM. As second example I tried "CAN-Based Control of PWM Duty Cycle". Here I get the same problem. Additionally after building the project, when (I guess) there should open a dialog where the PWM Duty Cycle can be changed, there is an error message saying "There is a problem loading the COFF file for the selected processor. You may need to reset your hardware and rebuild project.". A change couldn't be achieved by following these instructions. My question would be, if I maybe forgot to install anything, or if any installation of drivers or programs I use might be corrupt. Do you possibly have any other idea what I could be doing wrong? Thanks for your time...

  • Thank you sir, for sharing the details.

    Me too working/exploring the embedded coder - code generation for different TI C2000 applications. I have explored ADC, PWM and GPIO using this technique.

    Never worked on the interrupts and communication protocols. If you have any examples, it would be very helpful if u share it.

    Kind Regards

    Karuna