|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#11
|
||||
|
||||
|
Re: Problem using VEX shaft encoder
Quote:
in the User_Initialization function add this line INTCON3bits.INT2IE=1; This line enables Interrupt 2 if INTCON3bits.INT2IE is equal to 1 then every time the signal pin on digital input 1 goes high then it will enter the interrupt routine. The final step is to add a line into the interrupt routine Open user_routines_fast.c go down to the InterruptHandlerLow function The first if statement is the one you want to change just so you know what the if statement actually says. it says "if (INTCON3bits.INT2IF && INTCON3bits.INT2IE)" INTCON3bits.INT2IF is the interrupt flag, it is tripped whenever the pin goes high, INTCON3bits.INT2IE is the interrupt enable flag you set that to 1 in the last step. Inside the if statement you want to add "count++;" (or whatever you named the variable) Make sure you leave INTCON3bits.INT2IF = 0; other wise the code will keep stepping into the interrupt. Now you can use the count any where in the code you want, you can reset it to 0 if you want to, basically use it just like you were before. The reason you need the interrupt is that at decent speeds the encoder can pulse more than once per loop, if you were using it in a lower speed application, say on a high torque gearbox it may not be necessary. One last note, this will only count half as many pulses per revolution as yours did, the interrupt only counts high signals at the pin, your code counted every change, both low and high. THe interrupt however should give you plenty of resolution. If you have any more questions my s/n on AIM is JamesBrownsSN otherwise just post or PM me. Good luck. James Last edited by JamesBrown : 26-10-2007 at 20:31. Reason: Found what I was looking for |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Encoder Problem | DustinB_3 | Programming | 22 | 03-01-2007 20:42 |
| VEX Shaft Encoder Kit | jeffmorris | FIRST Tech Challenge | 1 | 19-05-2006 12:23 |
| Which shaft encoder to use? | Jeff Waegelin | Electrical | 22 | 18-06-2005 03:57 |
| Using Shaft Encoders | D.Viddy | Programming | 7 | 14-12-2004 18:27 |
| shaft encoder help | stephenthe1 | Programming | 2 | 03-12-2004 16:09 |