File Exchange

image thumbnail

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

version 3.50 (10.5 MB) by Lubin Kerhuel
Microchip support package for Embedded Coder

123 Downloads

Updated 03 May 2021

From GitHub

View Version History

View license on GitHub

MPLAB Device Blocks for Simulink support Package target up to 507 Microchip MCU. Provide peripheral blocks for dsPIC 16 bit devices and PIC32, SAMx7, SAMx5, SAMx2 32 bits devices (MIPS, ARM Cortex M7/M4F/M0p). With Embedded Coder, builds and execution model in real-time on any board with a supported MCU.

INSTALLATION:

1. 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 or ARM optimization (with MathWorks ARM support package add-on)

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

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

Comments and Ratings (35)

Mike Baker

Lubin,
Thank you for the proactive support, this is a fantastic service you are providing to everyone.
I will move future comments to the Microchip forum.

Mike

Lubin Kerhuel

Hi Mike, I noticed some issues you mentioned.
Please give a try to the beta fix fixes at: https://github.com/LubinKerhuel/MPLAB-Device-Blocks-for-Simulink/archive/Beta.zip
Thanks.

Mike Baker

A few bugs here and there, and perhaps could do with a little more documentation, but overall a very good addition to embedded coder with a lot of useful features!
-------
(Sorry, posting here because I can't post on the Microchip forum) One problem I am having is with the PWM_HS_FEP block, it only wants to compile for 2 or 3 input ports, more than 3 gives the error:
"Error: File: [path]\MCHP_PWM_HS_FEP.tlc Line: 532 Column: 12
The specified index (3) was out of the range 0 - 2"
And only 1 gives the error:
"Error: File: [path]\MCHP_PWM_HS_FEP.tlc Line: 518 Column: 15
The == and != operators can only be used to compare values of the same type"
(Also, cannot use PWM channel 4 without also using channels 1~3, but I don't know if this is a bug or just a limitation)

LOUNIS KHIAT

Hi Lubin,
Thank you for these informations so I will try to use the Microchip DSP library directly with the Mplab IDE first.

best regards

Lubin Kerhuel

Hi Lounis,

We do not provide FFT block. The tool is mostly focusing on control.
When activating the Code Replacement for dsPIC, the DSP is used to speed-up some replaced functions.

There exist Microchip DSP library for dsPIC that might be called using the C function call block.
You might probably have to split such function with a block to feed the FFT memory one by one (avoiding to have to copy a vector from one place to the FFT input memory bank), the FFT execution itself with its output vector.
Special care should be taken depending if the DSP lib used is compatible with pre-emption or not.

LOUNIS KHIAT

Hi Lubin Kerhuel,
Thank you for this great toolbox.
Is there way to do DSP like FFT with simulink blocks and then build it into a dspic.

Lounis.

Lubin Kerhuel

Issue with model reference not beeing compiled with v3.49 below: Problem was file path too long. The previous version v3.48 shorten path to 8.3 compability version, solving thus possible issue with too long path, but with the inconvenient for compilation command to be difficult to read for end user. (details on mchp forum)

Lubin Kerhuel

Hi Guilherme,
A beta is available which fixed an issue reported with R2018.
I checked that this beta compile reference model with R2020b. Could you give it a try ?
https://github.com/LubinKerhuel/MPLAB-Device-Blocks-for-Simulink/archive/Beta.zip
Discussion thread about it is available on mchp forum: https://www.microchip.com/forums/FindPost/1163898
We could share models on mchp forum if required.

Hello Lubin,
Thanks for the updates. With version 3.49 I was able to use external mode, however PIL did not work. I believe it is not a problem with the PIL tool, because the external model worked.

I did some testing and I believe there is a problem when a referenced model is used.
I cannot compile any topmodel with models referenced with version 3.49 .

For example, when I do a simple logic in an "Atomic Subsytem" to blink leds on the topmodel I can correctly compile the model.
However, when I use a referenced model for the logic to blink the LEDs I get an error.

"### Build procedure for model: 'BLINKmain' aborted due to an error. Cannot propose to program chip from Matlab: Either file BLINKmain.elf does not exist or MPLAB X API is not available on this system."

The versions of the tools used are:
MPLAB X v5.45
xc16 v1.61
Matlab 2020b
Support package Microchip v3.49

Thank you very much !

Lubin Kerhuel

Hi Gem,
PIC32MX chip is not on the dvpt radar right now. FYI, we have SAME5x done but not listed in the description above.

Gem Gem

Hi Lubin
is there any plan to include 32MX family ?

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 R2021a
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!