Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   encoders (http://www.chiefdelphi.com/forums/showthread.php?t=32611)

dmurdz 04-02-2005 23:07

Re: encoders
 
Im working on my programming, when it comes to my code I do not know how to set up my interrupt handlers, is there demo code some where for this???

Alan Anderson 05-02-2005 00:11

Re: encoders
 
Quote:

Originally Posted by dmurdz
Im working on my programming, when it comes to my code I do not know how to set up my interrupt handlers, is there demo code some where for this???

See http://www.kevin.org/frc/ for lots of example programs, many of which are complete drop-in modules. Scroll down to frc_encoder.zip for interrupt-based encoder code.

dmurdz 05-02-2005 10:20

Re: encoders
 
Sample code from Kevin on www.kevin.org/frc, the interrupts program, in file interrupts.c, there is a spot that says:

/************************************************** *****************************
*
* FUNCTION: Int_3_Handler()
*
* PURPOSE: If enabled, the interrupt 3 handler is called when the
* interrupt 3/digital input 3 pin changes logic level.
*
* CALLED FROM: user_routines_fast.c/InterruptHandlerLow()
*
* PARAMETERS: RB4_State is the current logic level of the
* interrupt 3 pin.
*
* RETURNS: Nothing
*
* COMMENTS: The PIC18F8520's RB4/KBI0 pin on port b is mapped to
* interrupt 3 on the EDU-RC and digital input 3 on the
* FRC-RC [108].
*
************************************************** *****************************/
void Int_3_Handler(unsigned char RB4_State)
{
// this function will be called when an interrupt 3 occurs
}

Is this the final code??? What do I need to add???

HELP!!!!!!!!!!!!!!!!

Kevin Watson 05-02-2005 12:52

Re: encoders
 
Quote:

Originally Posted by dmurdz
Is this the final code??? What do I need to add???

It's just template code that shows you how to setup the interrupts. Check out some of the other examples that show you what you can do with interrupts.

-Kevin

dmurdz 05-02-2005 13:43

Re: encoders
 
where can I find the other examples for interrupts?

roboticsjenkins 05-02-2005 13:44

Re: encoders
 
How do I hook up th encoders to the RC. I know that they go on Digital I/O, but do I use two PWM CABLES to hook each encoder up or what do I do? Someone please help me.

stephenthe1 05-02-2005 15:48

Re: encoders
 
ok, I'm assuming you have a quadrature encoder (this means there are 4 places to hook up wires on the encoder). 1 is the + power pin. 1 is the - (ground) pin. one is the phase -a pin, and one is the phase b pin. this requires two digital ports on the rc. I'm assuming you are using Kevin watson's encoder template (the only way to do this if your a beginner). hook up the +, -, and phase a wires on the digital io 1. then put the phase b wire on digital io (I think, but check the template read me provided b Mr. Watson) on digital io 6. this is how the "left" motor encoder, or w/e our using it for is hooked up.

don't feel too bad, I had this same problem about a month ago, I started a couple threads before I was able to understand it.

hope this helps,
Stephen

roboticsjenkins 05-02-2005 16:16

Re: encoders
 
Let me see if I have this right I have to hook one encoder to two different Digital I/O ports?...I'm so confused

stephenthe1 05-02-2005 16:25

Re: encoders
 
ok here it is, and yes, one encoder to two digital IO's. did you read what I said carefully? um, check to see if there are four pins on the encoder, if there are, then you need two digital ios. here-

dig. io 1 ------- phase a pin ------- positive power --------negative power

dig. io 6 ------- phase b pin (only, no power or anything here)

if this doesn't make sense, then you really need to go to the white papers section and read up on interrupts a little and on encoders, and read through the comments on mr. Watson's code. questions are fine, but really, after reading this, you shouldn't be having any problems.

stephenthe1 07-02-2005 07:24

Re: encoders
 
(didn't mean to sound mad ;) ) came out that way I guess

dmurdz 07-02-2005 15:47

Re: encoders
 
Is it possible to change these pins if you adjust the code???

Kevin Watson 07-02-2005 16:21

Re: encoders
 
Quote:

Originally Posted by dmurdz
Is it possible to change these pins if you adjust the code???

The phase-A signals must be tied to an interrupt. The phase-B signals can be tied to any digital input. See encoder.h for directions.

-Kevin

dmurdz 07-02-2005 21:21

Re: encoders
 
Quote:

Originally Posted by Kevin Watson
The phase-A signals must be tied to an interrupt. The phase-B signals can be tied to any digital input. See encoder.h for directions.

-Kevin


What do you mean " phase-A signals must be tied to an interrupt", can i hook them up to digital i/o pins 3-6???

Alan Anderson 07-02-2005 23:40

Re: encoders
 
Quote:

Originally Posted by dmurdz
What do you mean " phase-A signals must be tied to an interrupt", can i hook them up to digital i/o pins 3-6???

One of the two phases of the encoder needs to be able to interrupt the processor. Putting it on pin 1 or pin 2 makes that easy, with each pin causing its own interrupt upon the desired edge of the connected signal. Using pins 3-6 complicates the software quite a bit, because those pins all cause the same physical interrupt no matter which pin changed, and no matter which direction the signal transition went. You can still do it (in fact, you have to do it if you're using more than two encoders), but you need to know which bits of PortB mean what, and you need to do your own software filtering of signal transition direction. It takes a lot more work to do it that way rather than letting the RC hardware do it for you.

stephenthe1 08-02-2005 07:23

Re: encoders
 
I would suggest, especially Mr. Watson has it set up this way, putting the phase a's on 1-6, and b's on any other pins. Unless you can't already figure the direction your going, it won't be important to inerrupt the phase b's.


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

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi