C-Function Call and Muxes - to solve

Post Reply
malife
Expert
Posts: 56
Joined: Tue Apr 17, 2007 7:24 am
Location: Santa Cruz, CA
Contact:

C-Function Call and Muxes - to solve

Post by malife » Mon Sep 01, 2008 3:37 am

Hello Lubin,
This another bug that has been killing me all day and have not found a work-around. I have three separate signals that come from different sources and have different widths. They are joined by a mux and then passed on to a C-Function call. The problem is that the signal is overall 46 bytes wide, but it only allocates space in the code generation for the first one that goes into the mux (26) so when I try to read all the input, after 26 bytes I get junk. I wonder what the global input parameter does in the C-Function call, because I explicitly say 46 (otherwise it would no let me compile) but the code that is generated, reuses the output from my first block, the GPS parser.

Code: Select all

uint8_T GPSSentenceParser_o1[27];    /* '<S2>/GPS Sentence Parser' */
This is REALLY a show stopper. Please take a look at it. I can not post the model/code, but if you want me to email you the model, let me know.

Thanks

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

Re: C-Function Call and Muxes

Post by LubinKerhuel » Mon Sep 01, 2008 8:37 am

Hi Mariano,

I am just back and "setting up" my flat again!
malife wrote:I wonder what the global input parameter does in the C-Function call

The Global Input Size parameters set all input with the defined size.
If that size is 1, each input is considered as a scalar. (Simulink call the function with the value as parameter)
If that size is greater than 1, each input is considered as a vector. (Simulink call the function using pointers)

From the function call block point of view, there is no difference if the input size is 2 or 100. The pointer provided by Simulink is taken as is.

I can propose few independent solutions that you perhaps already tested:

- change the optimization option of the real time workshop (like "reuse signal").
- use the input of the C call function with 3 independent vector input (i.e. size of the global input Size parameter greater than 2) and mux the three input in the C function.
- Set the output of the GPS parser block with a size of 46 (so the 20 last bytes are not used) and use the Simulink standard block that can fill in a vector starting at a defined index (here 21 for the 2nd input and so on...)

It is not clear to me how Simulink mux vectors and if the RTW optimization parameters change the way it do it. I will look at that as soon as I unpack my computer (I am using the old vacation laptop that does not like matlab at all ;-)

To have a close look on theses bugs, it is always helpful to get model with the bug. I would be glad if you could send it (or a simplified version with the same bug!)

Lubin

malife
Expert
Posts: 56
Joined: Tue Apr 17, 2007 7:24 am
Location: Santa Cruz, CA
Contact:

Re: C-Function Call and Muxes - to solve

Post by malife » Mon Nov 03, 2008 2:58 am

Hello Lubin,
Just wanted to follow up on the Muxes issue. I can positively confirm that Muxes do not work with the code translation. I don't know if it is the matlab version, the blockset version or some of the code simplification settings. But to work around this what I do is for every mux I use instead an embedded matlab function that does exactly what a Mux would do. This solves the problem. Demuxes work just fine which is strange. Anyways, no show stopper but just wanted to let everyone know that if they see a funny behavior and muxes are involved, try substituting them with an embedded matlab block like:

Code: Select all

function y = myMux (u1, u2);
y = zeros(9,1) % size of output vector

y = [u1(:); u2(:)];


and see if this fixes the issue. Would be happy to discuss this further.

Thanks!

ismaeelbit
Posts: 19
Joined: Mon Feb 28, 2011 5:00 am

Re: C-Function Call and Muxes - to solve

Post by ismaeelbit » Sat Jun 25, 2011 11:48 am

Hi Malife,
Can you share with me how you implment gps parser with this blockset. I have trying to do similar things since using C-call function for a gps which does not work still.
thanks

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests