Go to Post Some people need the 2x4. - Ether [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #11   Spotlight this post!  
Unread 26-10-2007, 20:02
JamesBrown JamesBrown is offline
Back after 4 years off
FRC #5279
Team Role: Engineer
 
Join Date: Nov 2004
Rookie Year: 2005
Location: Lynchburg VA
Posts: 1,276
JamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond repute
Re: Problem using VEX shaft encoder

Quote:
Originally Posted by RyanN View Post
Could you help me with this. I'm new to programming, and am not very good at all. I was thinking that the cpu must be pretty fast to catch every loop perfectly. So where should I write this code and what should I write?
Alright, In User_routines.c you want to declare (globally, at the top where it says initialize user variables) a variable that will count pulses. For this example call it count.

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
__________________
I'm Back


5279 (2015-Present)
3594 (2011)
3280 (2010)
1665 (2009)
1350 (2008-2009)
1493 (2007-2008)
1568 (2005-2007)

Last edited by JamesBrown : 26-10-2007 at 20:31. Reason: Found what I was looking for
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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