Go to Post "Defense wins qualifying rounds, offense wins championships." - Paul Copioli [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 03-02-2008, 00:01
Kilroy0846 Kilroy0846 is offline
Registered User
FRC #2139
 
Join Date: Jan 2007
Location: Las Vegas
Posts: 28
Kilroy0846 is an unknown quantity at this point
Calling functions from other documents

In MPLAB, how do I call functions from other files in a project?

Here is my code:
Code:
static int counter;

counter = Get_Encoder_3_Count();
And the Get_Encoder_3_Count() function is located in the file encoder.c

Here is the function code:
Code:
long Get_Encoder_3_Count(void)
{
	long count;

	INTCONbits.RBIE = 0;

	count = Encoder_3_Count;
	
	INTCONbits.RBIE = 1;

	return(count);
}
The error that I get is:

Error - could not find definition of symbol 'Get_Encoder_3_Count' in file 'V:\frc-code-2007-8722\FrcCode_2007_8722\user_routines.o'.

Last edited by Kilroy0846 : 03-02-2008 at 00:03. Reason: Added The Error Text
  #2   Spotlight this post!  
Unread 03-02-2008, 00:09
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: Calling functions from other documents

declare the function reference as external to your source file.

Code:
extern long Get_Encoder_3_Count(void);
  #3   Spotlight this post!  
Unread 03-02-2008, 00:15
tdlrali tdlrali is offline
Registered User
FRC #0469 (Las Guerrillas)
Team Role: Programmer
 
Join Date: Sep 2006
Rookie Year: 2006
Location: MI
Posts: 377
tdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud oftdlrali has much to be proud of
Re: Calling functions from other documents

are you #include'ing?
  #4   Spotlight this post!  
Unread 03-02-2008, 00:19
Kilroy0846 Kilroy0846 is offline
Registered User
FRC #2139
 
Join Date: Jan 2007
Location: Las Vegas
Posts: 28
Kilroy0846 is an unknown quantity at this point
Re: Calling functions from other documents

I have the both the files encoder.c and encoder.h included. I added the external identifier, but I still get the same error.

Here is my new code:
Code:
static int counter;
extern long Get_Encoder_3_Count(void);

counter = Get_Encoder_3_Count();
  #5   Spotlight this post!  
Unread 03-02-2008, 00:30
JohnC's Avatar
JohnC JohnC is offline
my other name is nigel
FRC #0360 (360 Revolution)
Team Role: Programmer
 
Join Date: Mar 2005
Rookie Year: 2005
Location: user_routines.c
Posts: 100
JohnC is a jewel in the roughJohnC is a jewel in the roughJohnC is a jewel in the roughJohnC is a jewel in the rough
Send a message via AIM to JohnC
Re: Calling functions from other documents

If you're using more than one function from a file, you could just include that file's header file. Use quotes if it's not a library that comes with the compiler.

#include "myfile.h"
__________________
What place are we at? ... TODAI!
  #6   Spotlight this post!  
Unread 03-02-2008, 00:32
Kilroy0846 Kilroy0846 is offline
Registered User
FRC #2139
 
Join Date: Jan 2007
Location: Las Vegas
Posts: 28
Kilroy0846 is an unknown quantity at this point
Re: Calling functions from other documents

I Have the code:

#include "encoder.h"
#include "encoder.c"

located at the top of the document
  #7   Spotlight this post!  
Unread 03-02-2008, 00:37
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: Calling functions from other documents

It sounds like you haven't set up the encoder stuff correctly. Not all the encoder code is enabled by default. If that's the case then that routine isn't being compiled - its being excluded because ENABLE_ENCODER_3 isn't defined.

There is an encoder_readme.txt file in the documentation directory and there is info in the encoder.h file. Is the ENABLE_ENCODER_3 line in .h un-commented?
  #8   Spotlight this post!  
Unread 03-02-2008, 01:14
Chaos in a Can Chaos in a Can is offline
Joel Spadin
FRC #1736 (Robot Casserole)
Team Role: Programmer
 
Join Date: Mar 2007
Rookie Year: 2007
Location: Peoria, IL
Posts: 58
Chaos in a Can is an unknown quantity at this point
Send a message via MSN to Chaos in a Can
Re: Calling functions from other documents

You don't need to include "encoder.c", and in fact, you probably shouldn't.

I don't think that's the problem, but if you include a .c file, you're probably going to get an error about something like multiple declarations of something.

The headers tells the file that a function exists somewhere in one of the .c files. The actual code for that function doesn't need to be in the same .c file the function is used in.
__________________
2006 Xerox Creativity Award
2007 General Motors Industrial Design Award
2008 Judges' Award
2009 Chrysler Team Spirit Award

  #9   Spotlight this post!  
Unread 03-02-2008, 11:56
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Calling functions from other documents

Take a few steps back. Undo everything you've tried to do in order to make it work. Read the documentation (I think it's called encoder_readme.txt) that comes with the encoder software. Follow the steps (nine of them, if I recall correctly) to add the code to your project and configure it.

If it still doesn't work, let us know.
  #10   Spotlight this post!  
Unread 03-02-2008, 19:39
ShotgunNinja's Avatar
ShotgunNinja ShotgunNinja is offline
Programming Mentor, FRC 4247
AKA: Nicholas Iannone
FRC #4247 (CougarBOTS)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Milwaukee, WI
Posts: 160
ShotgunNinja is a jewel in the roughShotgunNinja is a jewel in the roughShotgunNinja is a jewel in the roughShotgunNinja is a jewel in the rough
Re: Calling functions from other documents

Quote:
Originally Posted by Kilroy0846 View Post
In MPLAB, how do I call functions from other files in a project?

Here is my code:
Code:
static int counter;

counter = Get_Encoder_3_Count();
And the Get_Encoder_3_Count() function is located in the file encoder.c

Here is the function code:
Code:
long Get_Encoder_3_Count(void)
{
	long count;

	INTCONbits.RBIE = 0;

	count = Encoder_3_Count;
	
	INTCONbits.RBIE = 1;

	return(count);
}
The error that I get is:

Error - could not find definition of symbol 'Get_Encoder_3_Count' in file 'V:\frc-code-2007-8722\FrcCode_2007_8722\user_routines.o'.
The problem could be that you tried to return a 'long' (4 bytes) variable into an 'int' (2 bytes) holder. Let me know if that helps any.
__________________
Team #2970 Alum
Team #1652 Alum
2006: School Mascot for Team 1652
2007-2008: Programmer for Team 1652 (Robot Mafia)
2009: Programmer on Team 1652 (Robot Mafia), Programmer on Team 2970 (eSchool eBots)
2010-2016: Volunteer, Wisconsin Regional
2017: Programming Mentor, FRC 4247 (CougarBOTS, Obama SCTE, Milwaukee, WI)

Last edited by ShotgunNinja : 03-02-2008 at 19:43.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling C functions from EasyC koenig3456 Programming 4 27-01-2006 16:03
How Do I Program My RC To Spot One wheel From Going faster than the other Kyle1010 Programming 5 12-01-2003 15:30
Stack height Poll (spawn from other thread) Andrew Rudolph Chit-Chat 5 07-01-2003 17:15
Legality Issues Regarding Gears From other vendors kilpatrick Rules/Strategy 1 17-02-2002 09:04
And once more from the top... GLORIA! GEFORCE 3! AND OTHER CARDS... Robby O 3D Animation and Competition 1 24-01-2002 20:12


All times are GMT -5. The time now is 19:15.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi