![]() |
Encoder Help with VEX and MPLAB
Greetings,
I am trying to set up some reference encoder for my team. We are using MPLAB with Vex Controller. Is there a way that I can get the interrupt to be triggered on the raising or falling edge of the resulting encoder square wave? Right now my code (below) just looks to see if the signal is high (0) or low (1), but if the encoder happens to stop when the signal is high , the encoder count just runs. Code:
if(rc_dig_int1) |
Re: Encoder Help with VEX and MPLAB
Kevin Waston provides some modular code for setting up encoders on the IFI hardware. The EDU hardware is closest to Vex, so I'd download that workspace. Any of the code can be easily ported to work with Vex, so I guess it doesnt matter.
That code will work as long as rc_dig_int1 is defined as the interrupt flag you want to look at and it is placed in the interrupt handler found in user_routines_fast.c. I'm guessing you are looking directly at the input pin, which is causing the code inside the If to execute every time. |
Re: Encoder Help with VEX and MPLAB
The VEX encoders send a binary string. You should only increment distance when the latest value is different from the previous value.
Code:
unsigned int distance = 0; |
Re: Encoder Help with VEX and MPLAB
Thank you that worked great
|
Re: Encoder Help with VEX and MPLAB
Quote:
To get the encoder values, just look at the two globals. It would be better to wrap that lookup in code that disable interrupts, so you don't risk having the value change in the middle of reading it. I can post that bit of code later, but I need to run right now. user_routines.c --------------- in the function "User_Initialization" add this line: Code:
EnableInterrupts();--------------- in the Function Prototypes section, add these lines: Code:
extern volatile int g_distMotorLeft;-------------------- below this line: /*** DEFINE USER VARIABLES AND INITIALIZE THEM HERE ***/ add these lines: Code:
volatile int g_distMotorLeft = 0;Code:
void InterruptHandlerLow () |
Re: Encoder Help with VEX and MPLAB
How would do you make encoders work with interrupt pins 3-6?
I plan on allowing the code to utilize 4 encoders and 2 ultra-sonics. Thanks in advance |
| All times are GMT -5. The time now is 04:11. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi