Passing a Vector to the C-Function Call block

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

Passing a Vector to the C-Function Call block

Post by malife » Fri May 16, 2008 10:18 pm

Hello Lubin,
I am trying to pass a vector to the C-Function Call block but apparently it is only getting the first element in that vector: You can see in the image shown below I assemble a vector using a Mux, and then pass it to the C function call, but the call to the function call is this:

Code: Select all

* S-Function "dsPIC_Digital_OutputWrite" Block: <Root>/Digital Output Write3 */
  LATBbits.LATB2 = FALSE;

  /* S-Function "dsPIC_C_function_Call" Block: <Root>/C Function Call */
  myPutSPI(8U);

  /* S-Function "dsPIC_Digital_OutputWrite" Block: <Root>/Digital Output Write2 */
  LATBbits.LATB2 = TRUE;
which is of course wrong since the function myPutSPI is expecting a vector and not a constant. Any ideas what I am doing wrong? Is this a bug? I have attached the code so you can verify it for yourself.

Thanks!
Attachments
spi.zip
(11.67 KiB) Downloaded 201 times
spi.JPG

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

Re: Passing a Vector to the C-Function Call block

Post by LubinKerhuel » Fri May 16, 2008 11:24 pm

Hi Mariano,


I confirm the bug.
Will fix that shortly !

I propose the following solution (while I am working on that bug !)

- add an output to the C function call block (like char or whatever)
- uncheck the "inline parameters" in Simulation ==> Configuration Parameters ==> Optimization

This solution is working on my blockset version. Note that I already made some change on the C function call block that are not yet published (blockset still in developments).
If you encounter a problem with the "dirty" solution proposed here, let me know.

Anyway, I will correct that bug soon. Thanks for reporting it !

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

Re: Passing a Vector to the C-Function Call block

Post by malife » Sat May 17, 2008 12:14 am

Thanks for a very quick response. I will try what you suggest and report back.

If it does not work I will wait for the next version.

DMA SPI si comming along, hope to give positive reports soon :-)

Thanks!

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

Re: Passing a Vector to the C-Function Call block

Post by malife » Sat May 17, 2008 12:20 am

Yes, that took care of it. I confirm the work around solves the problem.

Thanks for excellent support!

Mariano

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

Re: Passing a Vector to the C-Function Call block

Post by LubinKerhuel » Sun May 18, 2008 11:50 pm

Hi, I corrected the bug : if you have only one input vector, you do not need to add an (unused) output to the function.
This will be available in the next version (i.e. 0.97b)

Remark about the inline parameters :
When the C call function use input vectors with more than 2 elements (an array in C language), the adress of the first element (pointer) is passed to the C function .
In your exemple, when inline parameters is checked in simulink options, the first element of the array is a constant. This constant may not be stored next to the remaining vector variables values.

When inline parameters, the vectors intern variable usually follows each other in memory. (from experiment, I did not read anything about it)
Thus, I suggest to use an intermediate variable :
C_funCall_WithInterVariable.png
C function Call with vector input and intermediate variable (Simulink "inline parameters" option checked)
C_funCall_WithInterVariable.png (14.58 KiB) Viewed 3794 times
I wish you good luck with SPI using DMA !

Right now, I have done a new SPI block that use interrupt (but no DMA) However, It works only in master mode. It is usefull if you read data from external component (ADC, gyro or others) and have stringent real-time constraints. I will try to extend to slave mode.
Attachments
SPI_CFunctionCall.zip
modified version of the model posted by Mariano
(11.08 KiB) Downloaded 232 times

bmairs
Posts: 69
Joined: Mon Jul 27, 2009 7:51 pm

Re: Passing a Vector to the C-Function Call block

Post by bmairs » Thu Sep 16, 2010 5:08 pm

This bug still exists. I'd like to keep inline parameters checked as an optimization, is there anyway to fix this on your end, Lubin, or is this something that we're just going to have to deal with?

Mariano did find that replicating a Mux block with an embedded Matlab block fixed the bug. I'm not certain if that helps to fix this.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest