help : write a microcontroller program from matlab

Discussion in 'Embedded Systems and Microcontrollers' started by walid el masry, Dec 17, 2009.

  1. walid el masry

    walid el masry Thread Starter Active Member

    Joined:
    Mar 31, 2009
    Messages:
    132
    Location:
    Mansoura , EGYPT
    is that true that i can write a program to a microcontroller from matlab tool box cause some program will be easy to be written with matlab tool box instead assembly and c either and if that possible is there any examples for this operation assuming we program for pic microcontroller take PIC16F877A as an example
  2. russ_hensel

    russ_hensel Well-Known Member

    Joined:
    Jan 11, 2009
    Messages:
    814
    Location:
    South Dartmouth Ma
    I doubt it unless you mean use it as a text editor.
  3. walid el masry

    walid el masry Thread Starter Active Member

    Joined:
    Mar 31, 2009
    Messages:
    132
    Location:
    Mansoura , EGYPT
    no no not like a text editor what i mean is similar to what matlab 2009 do with FPGA when it convert what i wrote in matlab to VHDL code so that i can download it on FPGA so what i want here is to write a program in matlab specially using the simulink or tool box of matlab and then download it on a microcontroller
  4. Papabravo

    Papabravo AAC Fanatic!

    Joined:
    Feb 24, 2006
    Messages:
    6,049
    Location:
    Michigan, USA (GMT-5)
    I know of no such product. In part this is due to the extreme mismatch between matlab operations and the capabilities of a typical microcontroller which may have to do a multiply or divide without the benefit of a hardware instruction. In addition the limited amounts of RAM would make matrix operations quite limited.

    There may be interpreted languages that are suitable for download and execution on a microcontroller, but matlab and simulink would not be my first choice.

    What are you trying to accomplish exactly?
  5. walid el masry

    walid el masry Thread Starter Active Member

    Joined:
    Mar 31, 2009
    Messages:
    132
    Location:
    Mansoura , EGYPT
    about what i want to do i intent to measure the frequency , capacitance & inductance and i have been told that matlab simulink have a stong ability to do that so i thought if i wrote the program on matlab and download it on a microcontroller it will be a great way with a high efficiency to accomplish that
  6. Chaabane

    Chaabane Member

    Joined:
    Nov 30, 2009
    Messages:
    37
    Hello,
    read this,its the same question i guess
    http://www.mathworks.com/matlabcentral/newsreader/view_thread/265159

    what i know is that you can use simulink to interfere with your real system (AC motor,...) .
    Using a system called Dspace , so you can simulate filters,modulators,... in simulink and control a real system.
    but you can use a pic with simulink,for example:you need to send a feedback to your pic, using an expensive non-linear filter,and you're not sure if this will work or not,why wasting money !! use simulink to simulate this filter...
  7. walid el masry

    walid el masry Thread Starter Active Member

    Joined:
    Mar 31, 2009
    Messages:
    132
    Location:
    Mansoura , EGYPT
    what i want to do is to interface the real system usin a microcontroller with a program written with simulink and burnt on the microcontoller

    you mean that the feedback is done by a program written b simulink and executed on the pc but what i want is to reduce the need of the pc and depend only on the microcontroller to reduce the size and cost

    what i really want is the feature of the matlab using the microcontroller
  8. Papabravo

    Papabravo AAC Fanatic!

    Joined:
    Feb 24, 2006
    Messages:
    6,049
    Location:
    Michigan, USA (GMT-5)
    I'm sorry but I think this is a quest which is not grounded in reality. If you can figure out a way for a microcontroller to run matlab or simulink code you'll be well on your way to a promising career.
  9. walid el masry

    walid el masry Thread Starter Active Member

    Joined:
    Mar 31, 2009
    Messages:
    132
    Location:
    Mansoura , EGYPT
    i don't mean it that way :D i mean run matlab or simulink code with the limitation of the hardware of the microcontroller will better 100 times from writing a program from the scratch in assembly even in c it is like using the predefined library in c instead of writing your own in assembly even in c
  10. Papabravo

    Papabravo AAC Fanatic!

    Joined:
    Feb 24, 2006
    Messages:
    6,049
    Location:
    Michigan, USA (GMT-5)
    Let us start with some basic information.

    Matlab and Simulink are interpreted languages. What does this mean? It means there is a program, the matlab interpreter, that takes as input a string representing a statement. An example would be the definition of a 3x3 matrix
    Code:
    A = [1, 2, 3 ; 4, 5, 6 ; 7, 8, 9]
    
    From this string the matlab interpreter would define and initialize a data structure to contain the 3x3 array named "A". Next consider a statement to take the inverse of A. The matlab interpreter would look at the string:
    Code:
    AINV = inv(A)
           or
    AINV = A^-1
    
    and invoke the intrinsic procedure for inverting the matrix A

    In order for matlab to be executable on a microcontroller there must either be a matlab interpreter that runs on the microcontroller that can interpret matlab statements, or there must be a compiler on the PC which can compile matlab statemnts into executable code for the microcontroller of interest. There are no other ways of doing this.

    What I am saying is that there are unlikely to be matlab interpreters for microcontrollers, and there are unlikely to be compilers that will compile matlab statements into executable code for microcontrollers. If there is a counter example to my assertions then let the lucky party please step forward and help the OP.
  11. Nanophotonics

    Nanophotonics Active Member

    Joined:
    Apr 2, 2009
    Messages:
    363
    Location:
    United Kingdom
    I'm not aware of any compiler that translates matlab codes into executable codes for microcontrollers. I know one can use matlab codes to interact with microcontrollers and that with the help of a PC. Matlab isn't a programming language like others in a sense but is rather a numerical computing environment. The OP is probably new to the field.
  12. Papabravo

    Papabravo AAC Fanatic!

    Joined:
    Feb 24, 2006
    Messages:
    6,049
    Location:
    Michigan, USA (GMT-5)
    Matlab is a language which is highly optimized for matrix operations. It is really really poor at doing the loops that are common in microcontroller code. The reason for this is that each statement in a loop has to be recompiled each time the statement is executed. In a loop that runs a few million times that can amount to considerable overhead. I became aware of this matlab shortcoming while trying to program the Crank-Nicolson algorithm to solve financial derivative PDEs. Using loops required the program to run for several hours. Using matrix operations shortened that time considerably.

    http://en.wikipedia.org/wiki/Crank%E2%80%93Nicolson_method
  13. aznblood

    aznblood New Member

    Joined:
    Jan 13, 2010
    Messages:
    1
    Hi, I used to use simulink to design a PID controller. But that was all theory when i was in college getting my degree in mechanical engineering. I am very comfortable in programming Atmel microcontrollers in C or assembly, after having gained real work experience in the software industry. However, nobody ever taught me on integrating a PID controller on a uC. For example, how the software is designed using matrix/array to compute results from transfer functions. Would anyone please explain how it is done, or at least give me a how-to link. Thank you.
  14. Dragonblight

    Dragonblight Active Member

    Joined:
    Aug 19, 2009
    Messages:
    35
    If you're simply looking into easy coding of microcontrollers, I suggest the picaxe. I haven't read up a whole lot into it, but it supports flow-charts and basic statements in a native manner.
  15. nescartel

    nescartel New Member

    Joined:
    Mar 10, 2010
    Messages:
    1
    i've actually used Matlab Simulink to create & simulate applications and later convert into C code and later into hex file. this hex file is then flashed into a 32-bit fujitsu microcontroller. but this 'bridge' between Matlab and microcontroller hardware is developed exclusively for Siemens. what i am trying to say is it is not impossible, but i'd say it is really hard to do. :)
  16. t06afre

    t06afre AAC Fanatic!

    Joined:
    May 11, 2009
    Messages:
    5,939
Similar Threads
Forum Title Date
Embedded Systems and Microcontrollers Difficult to write a complete code for microcontroller Sep 13, 2014
Embedded Systems and Microcontrollers HOW can a custom IP READ/WRITE data to DDR2 SDRAM PLB BUS Mar 18, 2014
Embedded Systems and Microcontrollers Read or write data on 16F877A's EEPROM memory Aug 4, 2013
Embedded Systems and Microcontrollers two PIC32 want to read and write with a 128x16 SRAM. May 4, 2013
Embedded Systems and Microcontrollers write cycles in STM32 internal flash memory Apr 10, 2013

Share This Page