Forums

MATLAB/Simulink + RTW and generating code for a microcontroller

Started by argee March 18, 2009
Hi all,

I seem to be stuck with what seemed a very simple task. I want to 
convert a Simulink model with one input and one output to a C program 
that I could run on a microcontroller (any microcontroller, not only 
those TI chips on those development boards). It should be able to read 
some data from a ADC, do some processing (as defined by the model -- 
amplify/multiply by 2 is a fine starting point) and send the result to a 
DAC. I have no problem generating the "middle part", i.e. processing, 
but I have no idea how to interface to ADC and DAC. What I need are some 
"read_inputs()" and "write_outputs()" functions into which I could add 
my own code and those functions would be called automatically by the 
generated code when needed.
I was checking the C-API for Interfacing with Signals and Parameters and 
  External mode communication channels, but these don't seem to be able 
to do the job. I was also reading on the execution models and browsing 
the Embedded Coder documentation, but to no avail. So, is there a simple 
way to that? And is there some sort of a cookbook available?

Many thanks!

RG
"argee" <rg@arg.com> wrote in message news:gpr7cf$eob$1@news2.carnet.hr...
> Hi all, > > I seem to be stuck with what seemed a very simple task. I want to convert > a Simulink model with one input and one output to a C program that I could > run on a microcontroller (any microcontroller, not only those TI chips on > those development boards). It should be able to read some data from a ADC, > do some processing (as defined by the model -- > amplify/multiply by 2 is a fine starting point) and send the result to a > DAC. I have no problem generating the "middle part", i.e. processing, but > I have no idea how to interface to ADC and DAC. What I need are some > "read_inputs()" and "write_outputs()" functions into which I could add my > own code and those functions would be called automatically by the > generated code when needed. > I was checking the C-API for Interfacing with Signals and Parameters and > External mode communication channels, but these don't seem to be able to > do the job. I was also reading on the execution models and browsing the > Embedded Coder documentation, but to no avail. So, is there a simple way > to that? And is there some sort of a cookbook available? > > Many thanks! > > RG
I'm sure you have a license for the $20k worth of software you are using here. Mathworks offer pretty good support including some free training for these products. Is there some special reason that they can't help you ? Michael Kellett
MK wrote:

> I'm sure you have a license for the $20k worth of software you are using > here. Mathworks offer pretty good support including some free training for > these products. Is there some special reason that they can't help you ?
Well, the entire university is on academic licences, so I really don't think we'll be getting any free training (except from our own in-university support center which doesn't do RTW). Especially since we're in what MathWorks probably considers a third-world country. :/ And, besides, if I'm not able to figure something like this for myself (with a few pointers, hopefully), then either something's amiss with my engineering skills or MATLAB's help. So, any pointers, links, ...? RG
"argee" <rg@arg.com> wrote in message news:gpt26t$eoh$1@news2.carnet.hr...
> MK wrote: > >> I'm sure you have a license for the $20k worth of software you are using >> here. Mathworks offer pretty good support including some free training >> for these products. Is there some special reason that they can't help you >> ? > > Well, the entire university is on academic licences, so I really don't > think we'll be getting any free training (except from our own > in-university support center which doesn't do RTW). Especially since we're > in what MathWorks probably considers a third-world country. :/ > > And, besides, if I'm not able to figure something like this for myself > (with a few pointers, hopefully), then either something's amiss with my > engineering skills or MATLAB's help. > > So, any pointers, links, ...? > > RG
Look on Mathworks website -follow link to User Comminity which gets you to what they call Matlab Central. Do some searching. I had a very quick look and there is some stuff there which may help - you need to use the Generic Targtet C coder (the real name may be different - its years since I went on their training course and the people I was working for never bought the license !!! I work on my own now and find it cheaper to write my own code. You could try the matlab newsgroup. Michael Kellett
MK wrote:

> Look on Mathworks website -follow link to User Comminity which gets you to > what they call Matlab Central. Do some searching. I had a very quick look > and there is some stuff there which may help - you need to use the Generic > Targtet C coder (the real name may be different - its years since I went on > their training course and the people I was working for never bought the > license !!!
Well, I do know about Matlab central and have gone through quite a few tutorials and videos, but my real problem is that there is just too much of MATLAB. Too many tools and too many options... I was hoping someone could direct me through them and try to point out which to use for my specific purpose. The latest idea is to use the Legacy code tool to insert input and output code into custom blocks/S-functions and then use RTW or the Embedded Coder to generate the actual code.
> You could try the matlab newsgroup.
If the latest idea (also) fails, I will try, thanks. I have no idea why I didn't at least crosspost to the matlab newsgroup. Just gotten used to my regular newsgroups a bit too much, I guess. :) Thanks, RG