Microchip MATLAB forum

Thread Starter

Kittu20

Joined Oct 12, 2022
511
Hi,

I've gone through various threads, replies on the microchip MATLAB forum here https://forum.microchip.com/s/sub-f...B&forumName=Development Tools&page=1&offset=0, but I'm still unclear about why MATLAB is being utilized.

I usually work with PIC microcontrollers, where I write code using MPLAB and xc8, and then transfer it to the microcontroller using PK3.

However, I'm struggling to understand why MATLAB is preferred in some cases.

Could someone summarize the key points discussed in the MATLAB forum regarding its relevance to microcontroller development?
 

Thread Starter

Kittu20

Joined Oct 12, 2022
511
What? What do you use it for? Sorry but the questions you're asking seem disjointed.
Have you visited the link I provided?

You will see several threads in that subforum discussing MATLAB and microcontroller peripherals.

I'm particularly interested in understanding key points about the MATLAB forum regarding its relevance to microcontroller development? Why MATLAB is utilized for embedded product development compared to conventional methods like MPLAB and xc8.

Thank you very much for your quick response on the topic
 

nsaspook

Joined Aug 27, 2009
16,249
I could not make sense of this reply @nsaspook
As far as I understand his only question seems coherent. O always asked that myself BTW.
It's like asking what do you use soap for when the actual question is what soap brand and type is best for X job.

MATLAB is only a tool (primarily for numerical analysis) and his post tells me he's likely not at a level to use it effectively. Master basic engineering principles first for things like image processing, finding some mathematical transforms of particular signal, implementing filters etc in C or some other programming language, then MATLAB uses will become obvious.
 
Last edited:

Thread Starter

Kittu20

Joined Oct 12, 2022
511
It's like asking what do you use soap for when the actual question is what soap brand and type is best for X job.
After reading several discussions on the Microchip MATLAB forum, it appears to me that MATLAB is primarily used for testing the behavior of embedded systems before physical implementation.

From what I gather, MATLAB is used to create models, from which C code is generated and subsequently uploaded into the microcontroller's memory. While I believe this aligns with common practices, I'd appreciate insights from more experienced individuals to confirm my understanding.

What do you @nsaspook understand by reading threads on Microchip MATLAB forum?
 

nsaspook

Joined Aug 27, 2009
16,249
After reading several discussions on the Microchip MATLAB forum, it appears to me that MATLAB is primarily used for testing the behavior of embedded systems before physical implementation.

From what I gather, MATLAB is used to create models, from which C code is generated and subsequently uploaded into the microcontroller's memory. While I believe this aligns with common practices, I'd appreciate insights from more experienced individuals to confirm my understanding.

What do you @nsaspook understand by reading threads on Microchip MATLAB forum?
All that is true but it's not a process normally used with small 8-bit controllers you are learning on. I don't think there is a xc8 compatible generator as the resulting code won't fit in small 8-bit systems.
https://www.mathworks.com/matlabcen...e-blocks-for-simulink-dspic-pic32-and-sam-mcu
https://github.com/rdelpoux/ctrl-elec/tree/main/MCU/fieldWeakening
The example can be used with different motors, including
I've used the system before with the MATLAB/Simulink Model kit and motor. It's quick way to work on models but IMO not very practical for production code.
1713711484263.png

I designed my own hardware and software in XC32 instead of using MATLAB.
 
Last edited:

Irving

Joined Jan 30, 2016
4,995
MATLAB/Simulink provide a feature called 'hardware-in-the-loop' where a MATLAB simulation can be gradually ported to the microcontroller while MATLAB simulates some or all of the peripherals and/or external inputs.

An example is one of my students was creating a 2-wheeled self-balancing robot. She first simulated it in Simulink multibody, using simulation of the motors and mechanical configuration to get a basic stable PID controller with a force outer loop and velocity inner loop, that was then ported to her microcontroller so it ran the PID controller with simulate peripherals and motors. Finally when the hardware was ready the completed system was running autonomously with MATLAB monitoring it and providing controlled perturbations to test stability, etc.

Its not for everyone or every project, but its a great teaching aid...
 

nsaspook

Joined Aug 27, 2009
16,249
MATLAB/Simulink provide a feature called 'hardware-in-the-loop' where a MATLAB simulation can be gradually ported to the microcontroller while MATLAB simulates some or all of the peripherals and/or external inputs.

An example is one of my students was creating a 2-wheeled self-balancing robot. She first simulated it in Simulink multibody, using simulation of the motors and mechanical configuration to get a basic stable PID controller with a force outer loop and velocity inner loop, that was then ported to her microcontroller so it ran the PID controller with simulate peripherals and motors. Finally when the hardware was ready the completed system was running autonomously with MATLAB monitoring it and providing controlled perturbations to test stability, etc.

Its not for everyone or every project, but its a great teaching aid...
I agree but for a person just starting with 8-bit controllers, I strongly advise them to wait a bit and learn a lot more before using it.
 

Ya’akov

Joined Jan 27, 2019
10,226
The answers that were given in the thread (I did read his question there, and the responses) were perfectly sensible.

These are MatLab users who know how to create models in MatLab and want to offload the work to microcontrollers for the actual experiments they are performing. They are not developing embedded devices—they are using MCUs and FPGAs to make better versions of their experimental apparatus, and this is possible only because MatLab cab produce the code.

They don’t have the time or inclination to learn embedded development because that’s not their job. They don’t have technicians who can do it because a lot of places are poorly staffed. But they can write MatLab and Simulink models and magically have working hardware—a big win.

If there is anyone developing products this way—that’s an issue. But in a lab… seems pretty great.
 
Top