FORUM TOPIC · READ ONLY

C function call block

C function call block

Forum : General Remark and Questions

5 message(s) · archive en lecture seule

Simon_says
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

Re: C function call block

Citation : Simon_says
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

Re: C function call block

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

Pièce jointe : call6.mdl

Pièce jointe : callf6.c

LubinKerhuel

Re: C function call block

Dear Joze Luis,


Citation : Simon_says
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 !
<i>
</i>#include <p30f4012.h>
unsigned char call6(unsigned char Input)
{	
	unsigned char Temp;
	Temp = (Input);

	return Temp;       
} 

should be :
<i>
</i>#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

Re: C function call block

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