C function call block

Create new topics, add your comment, remark, bugs...
Post Reply
Simon_says
Posts: 17
Joined: Mon Dec 01, 2008 9:01 pm

C function call block

Post by Simon_says » Thu Dec 11, 2008 6:32 pm

Hi you all!
Hello Lubin:

I am trying to understand how the C call function block works but I am stuck. I have just tried to read a variable "data" and put it out . I compare it with a constant and set a port bit if it is greater or iqual. I have attached the C function also. After I compile it I get this error:

.
.
.
.
callf4.o(.text+0x0):C:\Documents and Settings\123\Mis documentos\MATLAB\call4_dspic\sources\..\..\callf4.c: Link Error: Cannot access symbol (_data) at an odd address.
C:\Program Files\Microchip\MPLAB C30\bin\bin/pic30-coff-ld.exe: link errors found, deleting executable `..\../call4.coff'
gmake: *** [..\../call4.coff] Error 0xff
### Real-Time Workshop build procedure for model: 'call4' aborted due to an error.
C30 Compiler found
C30 Compiler found
>>

I was trying to attach the .mdl file and the .c function but I do not know how to attach the files.
Can you explain me how to attach files?
Can you tell me what am I doing wrong?

Jose Luis

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

Re: C function call block

Post by LubinKerhuel » Thu Dec 11, 2008 6:44 pm

Simon_says wrote:Can you explain me how to attach files?
Hi Jose Luis,

To attach files on this forum, just look below the Save - Preview - Submit buttons, there is a tab : "upload attachement".
It will help to see the model.

Lubin

Simon_says
Posts: 17
Joined: Mon Dec 01, 2008 9:01 pm

Re: C function call block

Post by Simon_says » Fri Dec 12, 2008 9:08 pm

Hi Lubin..
Here are the .mdl and .c files. I am just trying to turn a pair of leds when the ADC reads more than 2.5V or less than 1.5V. I wanted to use the C function call in order to lear how to use it. I decided to use the example format you posted and it compiles succesfully. However, I program the dsPIC30f4012 and it just turns led RD1 on. That´s all it does. No response to ADC input...nothing. Just RD1 on.
Can you suggest me please?

Thanks a lot!

I was trying to see the C call function output with the matlab scope, but there is no output... Is it posible to simulate and check the performance before program the dsPIC?

Jose Luis
Attachments
callf6.c
(144 Bytes) Downloaded 433 times
call6.mdl
(29.64 KiB) Downloaded 449 times

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

Re: C function call block

Post by LubinKerhuel » Sat Dec 13, 2008 2:45 am

Dear Joze Luis,
Simon_says wrote:Is it posible to simulate [C function block] before program the dsPIC?
No, C function block will have no behaviour in a simulation. (Like all others blocks from the dsPIC library)

I had a quick glande on your model.
Sample time are Ok for every blocks ; thanks ! (It's a common source of error)

I noticed a datatype error in the C file that make the condition (<= 256) always true and the condition ( >= 512) false !

Code: Select all

#include <p30f4012.h>
unsigned char call6(unsigned char Input)
{	
	unsigned char Temp;
	Temp = (Input);

	return Temp;       
} 
should be :

Code: Select all

#include <p30f4012.h>
unsigned int call6(unsigned int Inputtt)
{	
	unsigned int Temp;
	Temp = (Inputtt);

	return Temp;       
} 
Be aware that a global variable called Input is declared by the simulink model. You also use a variable named Input inside your function (That may cause trouble). You may considere to rename this variable either in your C function file or in the simulink model file or just directly connect ADC to C function Call.

It should works ! However, I did not tested on the dsPIC. Let us know !
Lubin

Simon_says
Posts: 17
Joined: Mon Dec 01, 2008 9:01 pm

Re: C function call block

Post by Simon_says » Thu Jan 08, 2009 5:14 pm

Hi Lubin.. Sorry for the delay of my response...
Happy new year to all of you! This season I did not work at all, but now I have tested the model and I can see what my mistakes were. It works as you suggested!!! I have implemented it in a dsPIC and it is working. Thanks a lot. I am continuing experimenting and learning. I´ll get back to you again soon.

Jose Luis

Post Reply

Who is online

Users browsing this forum: No registered users and 48 guests