![]() |
Re: encoder vs. motor
Quote:
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". |
Re: encoder vs. motor
Quote:
Code:
/*** Variables.h ***/ |
Re: encoder vs. motor
Quote:
Code:
/*** Variables.h ***/ |
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. |
Re: encoder vs. motor
Quote:
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. |
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 |
Re: encoder vs. motor
Quote:
All of your examples are of functions not variables... |
Re: encoder vs. motor
yeah, I soon realized that after posting. thanks for the tip though.
|
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 |
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. |
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 :yikes: excitement is bubbling. |
| All times are GMT -5. The time now is 22:26. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi