Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   encoder vs. motor (http://www.chiefdelphi.com/forums/showthread.php?t=31681)

Kevin Watson 15-12-2004 20:06

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

stephenthe1 16-12-2004 15:36

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?

Kevin Watson 16-12-2004 16:59

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

stephenthe1 16-12-2004 18:32

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'"

Astronouth7303 16-12-2004 18:56

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 ).

Mark McLeod 16-12-2004 23:04

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.

stephenthe1 31-12-2004 16:11

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.

stephenthe1 31-12-2004 16:26

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.

Kevin Watson 31-12-2004 18:15

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 31-12-2004 18:31

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

stephenthe1 01-01-2005 11:24

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.

Astronouth7303 01-01-2005 11:50

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.

stephenthe1 01-01-2005 20:17

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.

Kevin Watson 01-01-2005 20:30

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.

stephenthe1 04-01-2005 10:00

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.


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