Matlab model to embedded code

General discussion on mikroBasic for dsPIC30/33 and PIC24.
Post Reply
Author
Message
mcnaull
Posts: 4
Joined: 14 Jun 2010 19:30

Matlab model to embedded code

#1 Post by mcnaull » 16 Aug 2010 14:26

Hello,

I recently started using MikroeC Pro and the dsPIC30F5013 for controls development. I have successfully used many of the peripherals and heavily use the dual CAN ports on the chip. One of our new development tools is using Matlab to generate C code from a Simulink model and import it to the project. Has anyone done this previously with this compiler and is there any specific settings we should be using when using the toolbox that generates the C code from the simulink model. I have emailed support and they are working on some help, they also mentioned to check the forums, which I did and did not see anything for my application so I thought I would ask if anyone has experience in this area.

Any comments or suggestions would be greatly appreciated.

Thanks,

RPM

mcnaull
Posts: 4
Joined: 14 Jun 2010 19:30

Re: Matlab model to embedded code

#2 Post by mcnaull » 17 Aug 2010 22:27

I made some progress today and found that if I used the included header files from Matlab's include library that I could almost compile except for two errors which are underlined and are in red below.

void bobs_test_model2_initialize(void)
{
/* Registration code */

/* initialize error status */
rtmSetErrorStatus(bobs_test_model2_M, (NULL));

/* block I/O */
(void) memset(((void *) &bobs_test_model2_B), 0,
sizeof(BlockIO_bobs_test_model2));

/* states (dwork) */
(void) memset((void *)&bobs_test_model2_DWork, 0,
sizeof(D_Work_bobs_test_model2));

/* InitializeConditions for Stateflow: '<S1>/Chart' */
bobs_test_model2_DWork.is_active_c1_bobs_test_model2 = 0U;
bobs_test_model2_DWork.is_c1_bobs_test_model2 = 0U;
bobs_test_model2_B.TestState = 0;
}

Can someone tell me what these two lines are exactly doing and how to modify them to work? I uploaded the entire project in a zipped file below if anyone wants to take a crack at it.

Any help is greatly appreciated.


RPM
Attachments
Project with Matlab Includes.zip
(39.6 KiB) Downloaded 323 times

mcnaull
Posts: 4
Joined: 14 Jun 2010 19:30

Re: Matlab model to embedded code

#3 Post by mcnaull » 15 Sep 2010 14:09

After getting some expert help from some industry friends we have successfully imported and used code generated by matlab's real time workshop on the dsPIC30 microcontroller we are currently using.

I found that most of our issues came from the simulink model settings as well as the real time workshop embedded coder generation settings. Once we worked these issues out, the code was almost plug and play. The model we are currently using is only a state-flow model, but we will be trying to incorporate some closed loop control utilizing the imported simulink code as well in the near future.

No one seemed to interested in my posts but thought I would share in case anyone would like some help getting code generated in matlab into a dsPIC chip.


RPM

User avatar
slavisa.zlatanovic
mikroElektronika team
Posts: 1321
Joined: 07 Apr 2009 09:39

Re: Matlab model to embedded code

#4 Post by slavisa.zlatanovic » 19 Sep 2010 11:59

Hi mcnaull!

I'm glad to hear that you succeeded to port MATLAB generated code into mikroC PRO for dsPIC.
Thanks for sharing your code and offering to help others.
I'm sure that there are many people interested in this topic.
However, your posts are at the wrong section of mikroE forum.

You should post issues regarding mikroC PRO for dsPIC here!
Best regards
Slavisa

billjones
Posts: 8
Joined: 07 Sep 2012 06:34

Re: Matlab model to embedded code

#5 Post by billjones » 20 Sep 2012 09:37

Hello Sir mcnaull!

Thank you for sharing your files. I have read all your posts and it interests me because I am going to build a project, an Engine Control Module/Engine Control Unit for trucks. I am a beginner and I plan to build my own circuit diagram for controlling the engine parameters, and I want to use a PIC microcontroller in my ECU. I have with me some MikroElektronika products namely mikroC Pro for PICs, mikroProg suite(programming software) for PICs, mikroprog USB programmer hardware, mikroICD(in-circuit debugger),and LV32MX v6 development board. I also plan to use Matlab to generate C code from a Simulink model and import it to the microcontroller,(in this case your posts would really help), and simulate the whole project using matlab and simulink by connecting it to a target hardware(which will represent the real engine) so that I could test how my ECU will behave for optimum performance. I want to know if LV32MX v6 can be used as my target device or as a real engine providing the I/O parameters to the my ECU. And maybe if you know some, you could also suggest some ECU circuits using a PIC microcontroller.

I hope for your kind reply. Thank you. :)

sincerely yours,
billjones

Post Reply

Return to “mikroBasic for dsPIC30/33 and PIC24 General”