File Exchange

image thumbnail

MPLAB Device Blocks for Simulink :dsPIC, PIC32 and SAM mcu

version 3.48 (9.6 MB) by Lubin Kerhuel
Microchip support package for Embedded Coder

84 Downloads

Updated 19 Nov 2020

View Version History

GitHub view license on GitHub

MPLAB Device Blocks for Simulink enables Embedded Coder for automated build and execution of real-time executable for any board equipped with a dsPIC (r), PIC32 (r) or SAMx7 from a Simulink model.

INSTALLATION:

1. [download](https://github.com/LubinKerhuel/MPLAB-Device-Blocks-for-Simulink/archive/master.zip) and unzip the package
2. execute the .p installer script . Within Matlab, right click on file install.p and select run.

FEATURES:

Built-in scheduler including single-tasking and multi-tasking option for multi-rate models.

Advanced configuration of ADC / PWM peripheral enable PMSM motor algorithm where ADC sample time is triggered precisely within a PWM duty-cycle. The time step might also be triggered by end of ADC conversion minimizing delays.

A custom protocol allows visualizing and recording data through the UART. The custom picgui interface allows plotting using your own matlab script incoming data in real-time. Data log enable further analysis or offline identification and allow to feed a simulation with real data.

The custom "C function" block allows including your own code if required.

The blockset also support MathWorks features like:
- Hardware in the loop (HIL)
- External mode features.
- Code replacement to benefit from DSP architecture of dsPIC

This version embed a third part tool adding blocks for UAVs projects (GPS, MAVLink, Receiver S.BUS, S.Port and F.Port blocks for dsPIC). Type picInfo to find out how to install the UxV blocks.

Cite As

(Microchip Technology) MPLAB-Device-Blocks-for-Simulink

Comments and Ratings (24)

Lubin Kerhuel

Hi Shivaprasad,

We had a compatibility issue between the blockset and the latest MPLAB X (5.45) where changes were introduced (it is now 64 bit app).
This has been solved with the blockset v3.48 available and next versions to come. Please isntall the current blockset version released. It works with all MPLAB X version (keep using the latest anyway).

Shivaprasad Narayan

Hi Luben,

I am using Matlab R2020b, MPLAB X IDE v5.45, x16 compiler and MHCP blockset v3.46 on dsPIC33EP256MC506 on MCLV development board.
MPLAB and compiler are installed in their default paths (C:\Program Files\Microchip\MPLABX and C:\Program Files\Microchip\xc16\v1.61)

When I build the example 'MCLV_V2_33EP256MC506_SlidingModeObserver_Single_DualShunt.slx', model compile fails. Below is the error log.

### Build procedure for model: 'MCLV_V2_33EP256MC506_SlidingModeObserver_Single_DualShunt' aborted due to an error.
Tool MDB not found using the registry.
Tool IPE not found using the registry.
Cannot propose to program chip from Matlab: Either file MCLV_V2_33EP256MC506_SlidingModeObserver_Single_DualShunt.elf does not exist or MPLAB X API is not available on this system.

Below is the MATLAB commandline log from MHCP toolbox installation process.

Start Script to clean old MPLAB X java API wrapper to program chip directly from Matlab : >>MCHP_API_Flash('remove')
Tool MDB not found using the registry.
Tool IPE not found using the registry.

----

Refreshing cache
Examples copied in D:\Work\Files\09_Microchip\MPLabtoolbox\MCHP_examples\

----
Check compilers
1 compilers found for 16 bits mcu
- C:/Program Files/Microchip/xc16/v1.61

Did not find a compiler for 32 bit chip.

-----------------------------------------------------
Embedded Target for Microchip Installation done
Version 3.46 (08-Nov-2019)
- Link to MPLAB X API is Ok
- 1 Compiler(s) found for 16 bits chip
- No Compiler found for 32 bits chip
-> download xc32 on xc32 webpage

Could you please suggest how to fix the MDB tool error?

Lubin Kerhuel

Hi Farhaan,
We do not implemented blocks for CAN or ECAN peripheral so far.
You will find user code allowing to use ECAN with simulink through the User C Call block from the MPLAB blockset.
Check a simple ECAN here: https://www.microchip.com/forums/m1158655.aspx, another more complex based on the CAN open code here: https://www.microchip.com/forums/FindPost/878818

Farhaan Shaikh

Does anyone have an example of sending and receiving on CAN? Are there any specific CAN blocks in the library?

Lubin Kerhuel

Hi Swastik,

The overall method seems ok.

When compiling the model for the secondary core, a folder named {untitled}.X is created. A subfolder named secondary_image is also created and contains files Secondary_FuseConfig.h, secondary_iamge.h and secondary_image.s.

Do you get an error during compilation of the secondary core model ?
If you encounter difficulties, please post the build report and model on the Microchip forum dedicated to matlab. (link provided on top of this page)

SWASTIK PANI

Hello Lubin,
thank you for your response.
I am using v3.47 with dual-core dsPIC33CH128MP508 where the block name secondary core inside dual-core asking for .s file of the slave. but when I generate code of slave using master block dsPIC33CH128MP508S1 then I did,t find any .s file. also, I put separate MSI block one for master and one for slave and my master and slave model are different. also in model settings, I added master reference and slave reference but didn't see any results.

Lubin Kerhuel

Mahendra, we are willing to support MAC OS and Linux. Microchip environement setup should allows to do it easily. It is however not a priority unless we get high demand for it. Thus I prefere not commit for any short term support.

Mahendra Gupta

Hello Lubin,

waiting for the support for MAC OS.

Hello Lubin !
Thank you very much for the update and your reactivity!
I did a simple test with the dsPIC33CK Curiosity development kit and it looks like everything is set up and compiles correctly.

I would like to take this opportunity to ask you also if the support package can perform a PIL with the dsPIC33CK?
I tried to do a test, but I got an error...

I noticed that in the example provided in the folder “MCHP_exemple \ ProcessorIntheLoop_PIL” the field "Enter Librariers" and Header Inlcude Path "in the simulink configuration parameters are loaded. In my settings these fields are not loaded.
My error msg :
### BUILD_MODE model_reference ### Creating library ... "C:/PROGRA~1/MICROC~1/xc16/v1.60/bin/xc16-ar" -r -omf=elf rtwshared_lib.a mul_s32_hiSR.o mul_wide_s32.o C:\PROGRA~1\MICROC~1\xc16\v1.60\bin\bin/elf-ar.exe: mul_s32_hiSR.o: No such file or directory gmake: *** [rtwshared_lib.a] Error 255 Error(s) encountered while building "rtwshared"

Thank you again and have a nice day!

Lubin Kerhuel

Hi Guilherme, Please give a try with the v3.47 release. It extend SPI support to dsPIC CK, CH and GS.

Lubin Kerhuel

Hi Guilherme,

Current version does not support the most recent "SPI with Audio Codec Support" peripheral available on dsPIC CH / CK and GS family.
We will try adding it shortly.

Hello Lubin
I am having a problem using the BUS SPI block for the 33CK family.
When I configure the MCHP block for the dsPIC33CK256MP508, for example, and then add the BUS SPI block, an error message appears.
“Error evaluating ‘OpenFcn’ callback of SPI Driver block (mask)… Callback string is ‘MCHP_BUS_SPI_callback(gcbh,’OPEN’)’
Index esceeds the number or array elements (0)”

there is a particular manipulation to use the BUS SPI block with the microcontrollers of the 33CK family, or the block does not support this family?
Please, could you suggest a solution for this problem?

I am using version 3.46.064 with matlab 2020a. I found the same problem with version 3.46.063

Thank you for your time!

Lubin Kerhuel

dual-core (dsPIC 33CH family): Create two models. One target the Main core (select 33CH512MP508 in master block), the other target the secondary (33CH512MP508S1).
Add within the master model the block "SLAVE core”; open and pick the slave Simulink model name.
When the Master is compiled, the slave will also get compiled and the. s generated added to the Master binary.
Use the MSI block to send/receive data between the two cores.

SWASTIK PANI

how to generate code for dual-core processors like dsPIC33CH128MP508?

David White

Great tools, however I'd also be very keen to see the reinstatement of the CAN bus blocks, even if they only supported a subset of the ECAN interface. Many thanks. David

Phan Liem

Sylvain Thomazo

Bonjour,
Sur votre ancien site "https://www.kerhuel.eu/wiki/Simulink_-_Embedded_Target_for_PIC" on peut voir apparaître dans votre librairie "Simulink Blockset Embedded Target microchip" des blocks pour le BUS CAN.
Or sur la dernière version 3.46.03 ces blocks ne sont plus disponibles. Est-il prévu dans une prochaine realease que ces blocks soient de nouveau disponibles?
Merci d'avance,
Cordialement.

Lubin Kerhuel

HI Dikko,

You might copy examples in the current working folder typing picInfo at matlab prompt then click on links provided.
Some examples deal with I2C.

Another source of information might be the Microchip forum ; this thread is related to I2C: https://www.microchip.com/forums/FindPost/837165

DIKKO ABUBAKAR

Could someone be kind enough to post an example of using the I2C block; please, why is there no help file for these block as provided for others?

Julio Walter

Ryan Roy

Thanks for this information. It useful

Phillip Maser

How does this MPlab Block Set Work? How does one obtain this embedded coder or is it needed. The fact that we need all these tools. Can we use other toolboxes with this MPlab. I would like to use fmincon and other toolboxs with this design.

Phil

Lubin Kerhuel

Hi Deepak,

The blockset is compatible with Windows platform. It has never been tested with MAC OS and all functions related to programming, also compiling might not work properly on MAC.

Lubin

Deepak Deepak

Hello! Thank you for sharing MPLAB blockset.

I was trying to install it in Matlab 2018a (Mac OS 10.14.4). I am getting the following error:
--------------------------------------------------------------------------------------
Microchip Blockset 3.45 installed. See info and examples.
Save path
Update start-up matlabrc.m script
...done
no setup for programming API required with this blockset version.
Error: MCHP Java API: cannot locate the SystemRoot folder
Tool MPLAB X not found using the registry.
Tool MPLAB X not found searching in program file folder.
Refresh cache
Register Compilers
Microchip Blockset 3.45 installed. See info and examples.

Blockset Installation done.

----

Start Script to clean old MPLAB X java API wrapper to program chip directly from Matlab : >>MCHP_API_Flash('remove')
Tool MDB not found using the registry.
Tool MDB not found searching in program file folder.
Tool IPE not found using the registry.
Tool IPE not found searching in program file folder.

------------------------------------------------------------------------------------

Could you please suggest how to troubleshoot this ?

Thank you for your time :)

Cheers!

MATLAB Release Compatibility
Created with R2010a
Compatible with R2010a to R2020b
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!