Go to Post Sometimes, you just have to beat something (someone?) into submission. Yes, you can use your head, but its a lot easier with a hammer. - Andy A. [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
  #46   Spotlight this post!  
Unread 04-01-2005, 10:17
seanwitte seanwitte is offline
Registered User
None #0116
Team Role: Engineer
 
Join Date: Nov 2002
Location: Herndon, VA
Posts: 378
seanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant future
Send a message via AIM to seanwitte
Re: encoder vs. motor

Quote:
Originally Posted by stephenthe1
I've been using Kevin Watson's interrupt template code. I want to have a variable increment every time the interrupt fires. that's not a problem. however, is there a static variable type available that I can use between files? I'm not aware of such a thing. also, does the code in interrupts.c execute first, or the code in user_routines_fast.c go first? this affects whether I use the interrupts.c file to handle the motor speed or the user_routines_fast.c file to handle the speed of the motor. if the user routines file comes second, that would be the case where I need the variable. I'm willing to bet there's an easier way, but this is what I've come up with so far. I would use Kevin's template for encoders but it supports two encoders for the wheels, when I want to use the one we already have set up on digitals 1 and 2 with one motor. we'll probably have to use his eventually on the wheels in addition to this encoder.
thanks,
Stephen.
Declare the variable you want to share between files in a header file with the "extern" storage specifier. For example:

extern unsigned char MyVar;

In a source file that includes the header, define the actual variable:

unsigned char MyVar;

Any source files that use the header now have access to MyVar. I would declare all of your shared variables in one header file and define them all in one source file. To use them you just include the header in the source files where needed. Something like "sharedvars.h" and "sharedvars.c".
  #47   Spotlight this post!  
Unread 04-01-2005, 16:52
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: encoder vs. motor

Quote:
Originally Posted by seanwitte
Declare the variable you want to share between files in a header file with the "extern" storage specifier. For example:

extern unsigned char MyVar;

In a source file that includes the header, define the actual variable:

unsigned char MyVar;
If the interupt fire enough, you will want to declare it volatile. ie,
Code:
/*** Variables.h ***/
volatile unsigned char MyVar = 0;

/*** MyCode.c ***/

extern volatile unsigned char MyVar;
This will cause it to not copy the value to a temporary storage location.
  #48   Spotlight this post!  
Unread 04-01-2005, 17:00
seanwitte seanwitte is offline
Registered User
None #0116
Team Role: Engineer
 
Join Date: Nov 2002
Location: Herndon, VA
Posts: 378
seanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant future
Send a message via AIM to seanwitte
Re: encoder vs. motor

Quote:
Originally Posted by Astronouth7303
If the interupt fire enough, you will want to declare it volatile. ie,
Code:
/*** Variables.h ***/
volatile unsigned char MyVar = 0;

/*** MyCode.c ***/

extern volatile unsigned char MyVar;
This will cause it to not copy the value to a temporary storage location.
Correct, I forgot about about the volatile keyword. You need to swap the declarations in the two files though. The extern statement goes in .h and the declaration goes in .c.

Code:
/*** Variables.h ***/
extern volatile unsigned char MyVar;

/*** MyCode.c ***/
volatile unsigned char MyVar = 0;
  #49   Spotlight this post!  
Unread 04-01-2005, 22:21
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Re: encoder vs. motor

thanks guys!!! that clears that up.
do you know about the order the files are executed though? I need to know, because if I use interrupts in one file to control the speed of a motor, it needs to be read before the user_routines_fast.c file so that the variable's values (the extern one I was asking for help earlier) can be sent to that file.
do you see what I mean?
also, can I use the
volatile unsigned int my_int;
then assign its value to a static variable inside a method in another file?

(back to the question obout the file execution order) it would be really cool to be able to tell the controller to rescan the file (or whatever part of the .hex file it is) of course, it's better just to know which ones are done first and which are done last.
by the way, I feel dumb for asking this, but what's the difference between frc_rc and edu_rc.

Last edited by stephenthe1 : 04-01-2005 at 22:28.
  #50   Spotlight this post!  
Unread 04-01-2005, 22:59
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: encoder vs. motor

Quote:
Originally Posted by stephenthe1
thanks guys!!! that clears that up.
do you know about the order the files are executed though? I need to know, because if I use interrupts in one file to control the speed of a motor, it needs to be read before the user_routines_fast.c file so that the variable's values (the extern one I was asking for help earlier) can be sent to that file.
do you see what I mean?
also, can I use the
volatile unsigned int my_int;
then assign its value to a static variable inside a method in another file?

(back to the question obout the file execution order) it would be really cool to be able to tell the controller to rescan the file (or whatever part of the .hex file it is) of course, it's better just to know which ones are done first and which are done last.
by the way, I feel dumb for asking this, but what's the difference between frc_rc and edu_rc.
1. Interrupts happen whenever interrupts happen. The only condition is that they must be enabled, This is typically performed in User_Initialization().

2. Your non-interrupt code executes from main () in main.c and follows whatever tortuous path you lead it on.

3. frc_rc is the full size controller that goes on our robots. edu_rc is the smaller controller for the Edubot.
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
  #51   Spotlight this post!  
Unread 05-01-2005, 15:23
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Re: encoder vs. motor

as I was looking at Kevin's encoder template, I was wandering how these particular variables are available to all files, as they aren't declared with the "extern" keyword.
examples:

long Get_Left_Encoder_Count(void); // call this to get the current left
// wheel's encoder count

long Get_Right_Encoder_Count(void); // call this to get the current right
// wheel's encoder count

void Set_Left_Encoder_Count(long); // call this to set the left wheel's
// encoder count

void Set_Right_Encoder_Count(long); // call this to set the right wheel's
// encoder count

void Left_Encoder_Int_Handler(void); // left wheel encoder interrupt handler

void Right_Encoder_Int_Handler(void); // right wheel encoder interrupt handler

do you see what I mean? this is pretty much the only thing keeping me from coding our encoder is understanding why this is. thanks. also, does anyone know an easy way to set up a third encoder easily with his code (attatched to dig_in_01 and dig_in_02 (plus setting them up as interrupts))? I'm semi-new, so I'm proned to mistakes. thanks again,
Stephen
  #52   Spotlight this post!  
Unread 05-01-2005, 15:36
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: encoder vs. motor

Quote:
Originally Posted by stephenthe1
as I was looking at Kevin's encoder template, I was wandering how these particular variables are available to all files, as they aren't declared with the "extern" keyword.
examples:

long Get_Left_Encoder_Count(void); // call this to get the current left
// wheel's encoder count

long Get_Right_Encoder_Count(void); // call this to get the current right
// wheel's encoder count

void Set_Left_Encoder_Count(long); // call this to set the left wheel's
// encoder count

void Set_Right_Encoder_Count(long); // call this to set the right wheel's
// encoder count

void Left_Encoder_Int_Handler(void); // left wheel encoder interrupt handler

void Right_Encoder_Int_Handler(void); // right wheel encoder interrupt handler

do you see what I mean? this is pretty much the only thing keeping me from coding our encoder is understanding why this is. thanks. also, does anyone know an easy way to set up a third encoder easily with his code (attatched to dig_in_01 and dig_in_02 (plus setting them up as interrupts))? I'm semi-new, so I'm proned to mistakes. thanks again,
Stephen
Stephen,

All of your examples are of functions not variables...
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
  #53   Spotlight this post!  
Unread 05-01-2005, 19:56
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Re: encoder vs. motor

yeah, I soon realized that after posting. thanks for the tip though.
  #54   Spotlight this post!  
Unread 06-01-2005, 18:39
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Re: encoder vs. motor

beware, long question...

ok, I have a couple questions.
1: in Kevin's encoder template, he first uses the Get_Left_Encoder_Count function, and assigns its value to the "count" variable. then he uses the Get_Right_Encoder_Count function and assigns its return value to the "count" variable also. Then he runs the Set_Left_Encoder_Count function, and uses the "count" variable to assign the value of "count" to Left_Encoder_Count. then he uses the "count" variable to assign the value of "count" to Right_Encoder_Count. I don't understand how he can do this without confusing the value of "count" between the left and right encoders. any help would be appreciated.

2:when setting up digitals as low priority interrupts, what do I use to reference the different pins (1-6, or interrupts 2-7). I know the first one is INTCON3bits.INT2IP = 0. but I need confirmation that that one is correct, and what the other five are. I know that interrupts 3-6 (4-7) are ganged together. I would prefer to know how to address each one individually
if that can be done easily, if not, I can set them all as low priority interrupts. I think it'd be better to do the other way though, because I need to learn how to address each one individually.

3: similarly to question two, I need to know the names of the pins to set the "edge select" option. also, the names to clear the interrupt flag and to enable the interrupts. I found some of the info in the "interrupts for dummies tutorial," but I don't know how to address each one specifically. I can't be in the dark or guessing on any of this, because interrupts are very finicky.

thank you,
Stephen

Last edited by stephenthe1 : 06-01-2005 at 19:06.
  #55   Spotlight this post!  
Unread 06-01-2005, 20:26
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: encoder vs. motor

Stephen,

Find a good primer on C and read it. I highly recommend http://www.lysator.liu.se/c/bwk-tutor.html

Understand that I am not trying to be cruel... I just feel that you have not attempted to work things out for yourself. If Mr. Watson gave you all of the answers, what would you learn?

As it is, I feel he has given you too much.

I think back to my freshman days at college. A fellow student (I'll call him John) was hopelessly lost and in over his head. Another student gave him the program (it was a stack of punchcards for an IBM 360 mainframe). All John had to do was change the job card (the top card on the stack) and run his program...

John screwed it up and, after several hours, declared that he had changed all of the variable names and the program still didn't work!

John's problem was that he never read the material required by the professor and was too busy talking in class to pay attention.

Now to your situation. Your earlier post indicates that you have no real understanding of C. The variable count is a local variable inside of Get_Right_Encoder_Count and has nothing at all to do with the local variable count inside of Get_Left_Encoder_Count. Both functions return a number to the statement which called them.

Suppose I asked you to find out how many pennies Marsha has and then how many Bill has? You would go to Marsha and find out she has 3 pennies and report this to me. Then you would go to Bill hand find out he has 2 pennies and report it to me. The face that Marsha had 3 pennies does not influence the fact that Bill has two. I did not ask you to add then together... Just report.

The function Get_Right_Encoder_Count has no idea what other functions are available. It just reports the number of clicks that the right encoder has seen.

The last line of the function could have been written:

return(Right_Encoder_Count);

without any local variable... Does this make sense?

Bottom line: Mr. Watson's code works.
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...

Last edited by Mike Betts : 07-01-2005 at 00:59.
  #56   Spotlight this post!  
Unread 06-01-2005, 22:07
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Re: encoder vs. motor

your right there. it's just frustrating right now, because I understand the code so well, save that little thing and methods. however, my main problem was not that little variable, but the interrupt names ( the whole TRISBbits. etc. thing ), mainly for accessing the 3-6 interrupts. yeah, I'm the type of guy, who, when I understand it 100%, I can work magic, untill then, I'm in a ditch.
2 days till kickoff excitement is bubbling.

Last edited by stephenthe1 : 06-01-2005 at 22:16.
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
[OCCRA]: motor brush springs greencactus3 OCCRA Q&A 1 28-09-2004 20:56
Multiple Motors phrontist Motors 12 21-06-2004 23:05
Mounting the drill motor Veselin Kolev Motors 11 26-04-2004 14:27
WHich motor to lift and for arm thoughtful Motors 8 25-02-2004 10:34
Thermal Protection archiver 2000 1 23-06-2002 23:27


All times are GMT -5. The time now is 17:34.

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