|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||||
|
|||||
|
Big Question concerning Interrupt Pins 3-6
Happy Monday to all!
I had a revelation while sitting in the shower.... We have two mechanical encoders on our bot. They have four output pins each. One is a ground, one is for the voltage or whatever, and the other two are signals. The two signals are offset by either 1/2 or 1/4 of a sine wave. At andy rate, they don't change at the exact same time. So I was thinking.... Is there a way that I could combine the two signal wires into one and stick each encoder on one of the digital interrrupts (3-6) because they can detect a change in state? If I could it would make coding much much easier and it'd be sweeeeeeeeeet. I just don't know enough about the electric signal coming out of the encoder to be able to judge. Thanks alot. By the way.... Did anyone else wake up this morning and hope that Monday wasn't here ALREADY!!!! |
|
#2
|
||||
|
||||
|
Re: Big Question concerning Interrupt Pins 3-6
The reason it has 2, is because it has 2 sensors on it. they are set half a notch apart from one another. The theary behind it is that you get directional ability by seeing the order the things hit. If you dont need direction you could just use one of the signal wires. If you want high res and all the features of the encoder (do you want to know if its going forword or backword) you could just put the second signal wire on its own interupt (excluding the power/ground).
|
|
#3
|
|||
|
|||
|
Re: Big Question concerning Interrupt Pins 3-6
Kevin Watson posted an encoder example on his web site kevin.org/frc. The output of the encoder is called Gray Code and is set up so that only one channel changes at a time. Channel A leads channel B by 90 degrees. Thats just a fancy way of saying that channel B won't see a state change until halfway through a state change on channel A. Here is the order the signals will change as the shaft rotates:
Code:
A B -- -- 0 0 1 0 1 1 0 1 0 0 |
|
#4
|
||||
|
||||
|
Re: Big Question concerning Interrupt Pins 3-6
Kevin Watsons example only shows how to set up the interupts. It is alot more involved than that. You must be very acurate with your messurements of wheel diameter or your distance/speed readings will be way off. You also need to know how many times the state will change per turn.
|
|
#5
|
||||
|
||||
|
Re: Big Question concerning Interrupt Pins 3-6
Forgive me for possibly asking a dumb question but aren't you making this way harder than it needs to be? We've just got an aluminum disk with 30 holes punched in it and the encoder that first gives you. Our interrupt handler is a whopping shaft_encoder++;
|
|
#6
|
||||
|
||||
|
Re: Big Question concerning Interrupt Pins 3-6
30? We got a laser cut piece of polystierene with 16 holes and it works fine. I guess what direction the bot is going by assuming that power over 127 is forward and below 127 is reverse. Good for speed, bad for distance
![]() |
|
#7
|
|||
|
|||
|
Re: Big Question concerning Interrupt Pins 3-6
Quote:
|
|
#8
|
|||||
|
|||||
|
Re: Big Question concerning Interrupt Pins 3-6
I'm still struggling with how to figure direction.... Any help?
|
|
#9
|
|||
|
|||
|
Re: Big Question concerning Interrupt Pins 3-6
Quote:
Code:
volatile signed int distance = 0;
void Int_1_Handler()
{
//check the other encoder channel. you may have
//to switch the comparison value to 1 depending on
//the configuration.
if (rc_dig_in08 == 0)
{
distance++;
}
else
{
distance--;
}
}
|
|
#10
|
|||||
|
|||||
|
Re: Big Question concerning Interrupt Pins 3-6
QUOTE:
Connect the signal pin not connected to the interrupt and ground to the signal and ground pins on digital input number 8 I think I know what you are getting at but could you clarify this? |
|
#11
|
||||
|
||||
|
Re: Big Question concerning Interrupt Pins 3-6
Quote:
|
|
#12
|
|||||
|
|||||
|
Re: Big Question concerning Interrupt Pins 3-6
Quote:
In a quadrature encoder you have two signals out of phase by 90 degrees from each other. That's why you have two signal lines. (The word quadrature means 90 degrees.) When the primary signal line goes high it causes the interrupt (in this case in digital input 1). If you check the second signal line (in this case on digital input 8) at the same time you will see it will always be low when the wheels are rotating in one direction and always high when the wheels are rotating in the opposite direction. So you can add counts going forward and subtract from your count when going backwards. Think of two square waves offset from each other like this: ____----____---- signal A __----____----____ signal B If you think of a vertical line moving from left to right you'll see whenever signal A goes high (---) signal B is always high too (---). But moving your imaginary vertical line from right to left, whenever signal A goes high (---) signal B is always low (___). [edit] I had to come back and finish up this explanation later, because my car pool was leaving. ![]() Last edited by Mark McLeod : 24-02-2004 at 19:12. |
|
#13
|
|||||
|
|||||
|
Re: Big Question concerning Interrupt Pins 3-6
You're a genious....
I totally understand the concept. I'm just struggling as to how I hook it up. What I tried today (and miserably failed at) is this: I found a 4-cable pwm-like Y(splitter)-cable. On an interrupt pin (pin1) I stuck the ground to the ground, one of the two signals (The "A" signal) to the signal pin and the +5 to the +5. Then I stuck the split ground to the ground on digital6 and the split +5 to the split +5 and the other signal (the "B" signal) to the signal pin all on digital 6. Is this correct? I'm very/pretty sure of my code, as I have played around with interrupts a good deal and have a general knowledge of how they work and how to implement them... |
|
#14
|
|||||
|
|||||
|
Re: Big Question concerning Interrupt Pins 3-6
While you don't actually need the split +5v or ground on the digital input, only the signal pin is required, it shouldn't matter.
Is digital input 6 also setup as an interrupt? The code seanwitte posted assumes you are only polling. That's why he specified input 8 rather than one of the potential interrupts. |
|
#15
|
|||||
|
|||||
|
Re: Big Question concerning Interrupt Pins 3-6
sweet.
thanks for the quick reply. While I know I don't have pin6 configured as an interrupt, I will try to move it anyways. Thanks for the info. Wiring will be much simpler now. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Question about input pins. | Tom Bottiglieri | Programming | 3 | 15-02-2004 15:12 |
| Interrupts Questions | mightywombat | Programming | 0 | 03-01-2004 14:50 |
| BIG!!! Championship Location in Question | Nate Smith | Championship Event | 194 | 05-11-2002 12:31 |
| Curie Division Robots information... (not complete) | archiver | 2001 | 3 | 24-06-2002 03:13 |
| A Big Question?????? | archiver | 2001 | 7 | 23-06-2002 22:49 |