Go to Post Patents are an issue of law which, alas, has little to do with engineering or common sense. - Mike Betts [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
  #31   Spotlight this post!  
Unread 15-12-2004, 20:06
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: encoder vs. motor

Quote:
Originally Posted by Kautz
Where do you wire the 5v and ground to pin 1 and 2 of the encoder. Pin 3&4 to the digital input /output?

Thanks I searched but do not fine anything.
+5V goes to the middle PWM pin
Gnd goes to the outside PWM pin, where it's marked "Blk"
The A and B outputs go to the inside pins.

I don't remember which I/Os are used for the signals, but it will be documented in the readme.txt file and at the top of the encoder.c source file.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #32   Spotlight this post!  
Unread 16-12-2004, 15:36
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

Quote:
Originally Posted by Kevin Watson
+5V goes to the middle PWM pin
Gnd goes to the outside PWM pin, where it's marked "Blk"
The A and B outputs go to the inside pins.

I don't remember which I/Os are used for the signals, but it will be documented in the readme.txt file and at the top of the encoder.c source file.

-Kevin
did you mean that the +5V goes to the middle digital pin? the pwm's have an output of 7.5 volts right. and does the digital pin have an output of +5 volts?
  #33   Spotlight this post!  
Unread 16-12-2004, 16:59
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: encoder vs. motor

Quote:
Originally Posted by stephenthe1
did you mean that the +5V goes to the middle digital pin? the pwm's have an output of 7.5 volts right. and does the digital pin have an output of +5 volts?
Yes, use the middle digital I/O pin, which is at +5V.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #34   Spotlight this post!  
Unread 16-12-2004, 18:32
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

in ifi_aliases.h, there is a reference to adc.h (#include <adc.h>). I looked in the directory with all the c and h, etc. files, and didn't find a file called adc.h. this is a problem, because the code won't compile with mplab untill I find out why it can't find that particular file. can I remove it from the ifi-aliases.h file?
this is the exact error message:
"E:\Robotics\defaultcode\FrcCode\ifi_aliases.h :18: unable to locate 'adc.h'"

Last edited by stephenthe1 : 16-12-2004 at 18:41.
  #35   Spotlight this post!  
Unread 16-12-2004, 18:56
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

This seems to occur frequently. Unless you didn't install MCC18 (which is a requirement), it should be there.

I believe adc.h is the first 'standard' include; so a misconfig is the most likely cause. Check to make sure MPLAB has the right include dir (by default it is C:\mcc18\h ).
  #36   Spotlight this post!  
Unread 16-12-2004, 23:04
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,810
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: encoder vs. motor

Quote:
Originally Posted by stephenthe1
this is the exact error message:
"E:\Robotics\defaultcode\FrcCode\ifi_aliases.h :18: unable to locate 'adc.h'"
More details are in this thread http://www.chiefdelphi.com/forums/sh...ighlight=adc.h
or you can search for "adc.h" to get more hits.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
  #37   Spotlight this post!  
Unread 31-12-2004, 16:11
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

hi,
I've been going through a tutorial for using interrupts ("interrupts for dummies") and another one titled ("quadrature encoders"). this may be a vague question, I'm not sure. but what is "Port_B"? and what is "0xFF".
also, what are state machines (based on the current encoder position). are they used to determine what part of the "cycle" the encoder is going through.
lastly, just a thought, is does Port_B tell which of the 4 interrupts (4-7 was fired?), because these particular four are all identified under the "same name."
it seems that Port_B is used to reference interrupts 4-7, and then the 0xFF, where "FF" identifies which of those four ports was interrupted?
anything you can tell me to simplify this would be appreciated,
thanks,
Stephen P.

Last edited by stephenthe1 : 31-12-2004 at 16:14.
  #38   Spotlight this post!  
Unread 31-12-2004, 16:26
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

also, if you could explain this segment of code.
Code:
#pragma code InterruptVectorLow = LOW_INT_VECTOR // put this code at address 0x18
void InterruptVectorLow (void)
{
_asm
goto InterruptHandlerLow // jump to InterruptHandlerLow(), below
_endasm
}
#pragma code
1: what is "#pragma"
2: what is the purpose of putting the "#" symbol in front of it
3: what are _asm and _endasm
thank you so much for the help,
Stephen.
  #39   Spotlight this post!  
Unread 31-12-2004, 18:15
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: encoder vs. motor

Stephen,

Quote:
Originally Posted by stephenthe1
I've been going through a tutorial for using interrupts ("interrupts for dummies") and another one titled ("quadrature encoders"). this may be a vague question,
No, they're great questions. I'll update the source code with additional documentation.


Quote:
Originally Posted by stephenthe1
I'm not sure. but what is "Port_B"? and what is "0xFF".
Assuming you're referring to my code, here's a description of the three variables:

"Port_B" is a working copy of the input port where the state of the interrupt bits can be read. You need to take a snapshot because their value may change at any time. If, for example, interrupt 6 changes from a zero to a one and then quickly changes back to a zero before you get around to checking it's state, you're stuck servicing an interrupt without knowing which of the four inputs caused it. This is why I grab a copy of PORTB first off.

"Old_Port_B" is the state of the port the last time an interrupt was generated. Because four inputs are mapped to one interrupt, you need this information to determine which of the four inputs changed and caused the interrupt.

"Port_B_Delta" is the exclusive-or of the above two variables. The exclusive-or of two bits returns a one if the two bits are different, zero if they're the same. Later on, I check all four bits to see if they're a one, meaning that they've changed since the last interrupt was generated. You need to check each bit because one may have changed between the time another bit caused the current interrupt and the time you sampled PORTB. If you didn't do this, you might miss a valid interrupt-causing event, which is a really bad thing to happen.


Quote:
Originally Posted by stephenthe1
...what are state machines (based on the current encoder position). are they used to determine what part of the "cycle" the encoder is going through.
Yes, exactly. A state machine is a construct that allows software (and hardware) to keep track of what's happened in the past. To use an analogy, it's kinda like Drew Barrymore's character in Fifty First Dates, who doesn't remember what happened the day before when she wakes-up the following morning. If she just left a note to herself each evening with her current marital state <unattached/dating/engaged/married>, she wouldn't have a problem the following morning <grin>. It's the same thing for software. By just changing the state variable (think Drew's note) before leaving a function, you'll be able to pick up where you left off the next time the function is called.


Quote:
Originally Posted by stephenthe1
...lastly, just a thought, is does Port_B tell which of the 4 interrupts (4-7 was fired?), because these particular four are all identified under the "same name."
Yes, as I described above.


Quote:
Originally Posted by stephenthe1
...and then the 0xFF, where "FF" identifies which of those four ports was interrupted?
If nothing is attached to the PORTB pins, their state will be read as all ones, the 0xFF is just my best guess of the state of PORTB when software starts execution. If you take a look at the Initialize_Interrupts( ) function, you'll see that I initialize Old_Port_B with the real state of PORTB just before I initialize the interrupt.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #40   Spotlight this post!  
Unread 31-12-2004, 18:31
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: encoder vs. motor

Stephen,


Quote:
Originally Posted by stephenthe1
1: what is "#pragma"
A pragma tells the C pre-processor that what follows is a special note telling it to do something non-C language related. In this case, it tells the pre-processor (and later the linker) that you want this specific piece of code placed in a special place in memory reserved for interrupt service routines.


Quote:
Originally Posted by stephenthe1
2: what is the purpose of putting the "#" symbol in front of it
This just indicates that this is a message for the C compiler pre-processor. Other examples are #include and #ifdef.


Quote:
Originally Posted by stephenthe1
3: what are _asm and _endasm
This tells the C compiler that you want to insert raw assembly language within a C source file. In this case, we're just putting a jump instruction to the interrupt handler at the special location in memory where the CPU starts execution in response to an interrupt condition.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #41   Spotlight this post!  
Unread 01-01-2005, 11:24
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

I was reading about extern and static variables. I realize that it's considered bad coding technique to declare extern variables, because they are declared outside functions. however, I need this variable available to interrupts.c and user_routines_fast.c. however, I only want this variable to have its value assigned once. where should I place a variable that can be used in both these files, and have the variables value (unsigned int phase = 1000) assigned only once. I did search on google, but it doesn't exactly tell me about how the structure of the default code is set up to work with and where to put such a variable so it will be available to these particular files.
by the way, the purpose of the variable, is so when interrupt #1 fires, 1 is added to its value, and when interrupt #2 fires, 1 is subtracted from its value. the reason it needs to be available to user_routines_fast.c, is because that is where I want to place my functions, as it would be confusing to have the interrupts.c file running a function controlling the robot and a function in user_routines_fast.c controlling the robot as well.
thanks a lot,
Stephen.
  #42   Spotlight this post!  
Unread 01-01-2005, 11:50
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 stephenthe1
I was reading about extern and static variables. I realize that it's considered bad coding technique to declare extern variables, because they are declared outside functions. however, I need this variable available to interrupts.c and user_routines_fast.c. however, I only want this variable to have its value assigned once. where should I place a variable that can be used in both these files, and have the variables value (unsigned int phase = 1000) assigned only once. I did search on google, but it doesn't exactly tell me about how the structure of the default code is set up to work with and where to put such a variable so it will be available to these particular files.
I don't know how it would be bad coding practice; any variable that needs to be accessable from 2 or more different functions must be declared globally.

The variable should be declared in one file and extern'd in all the others you need it in.
  #43   Spotlight this post!  
Unread 01-01-2005, 20:17
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

where does mplab ide 7.00 send the mcc18.exe compiler file? I did the default settings for the entire installation. where is this at? keep in mind that I don't have a mcc18 folder in the root of the drive. the mplab files were installed into the program files folder. thanks, Stephen.
  #44   Spotlight this post!  
Unread 01-01-2005, 20:30
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: encoder vs. motor

Quote:
Originally Posted by Astronouth7303
I don't know how it would be bad coding practice...
Well, minimizing the number of global variables is desirable because you don't have any control over the scope of a global variable. I've been involved with a few flight projects where there weren't any globally defined variables in the flight source code.


Quote:
Originally Posted by Astronouth7303
...any variable that needs to be accessable from 2 or more different functions must be declared globally.
No, this isn't true. You can pass a pointer to the variable in the function call.
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #45   Spotlight this post!  
Unread 04-01-2005, 10:00
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

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.
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 10:07.

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