View Single Post
  #8   Spotlight this post!  
Unread 15-01-2006, 13:43
Joe Hershberger Joe Hershberger is offline
National Instruments
AKA: jhersh
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: Nov 2005
Rookie Year: 1997
Location: Austin, TX
Posts: 148
Joe Hershberger is a name known to allJoe Hershberger is a name known to allJoe Hershberger is a name known to allJoe Hershberger is a name known to allJoe Hershberger is a name known to allJoe Hershberger is a name known to all
Lightbulb Re: Gear tooth sensor vs. Optical Encoders

Quote:
Originally Posted by Avarik
Alright, thanks! That was very helpful.

I set these sensors up with interrupts, right? Or is that not possible with the analog inputs..?

And can someone point me to the documentation please?
The interrupts on the analog inputs only tells you when the analog conversion is complete. That will not help you for measuring the GTS.

You want to use an External Interrupt. Several of the digital lines are wired to external interrupts on the user processor. When you configure these interrupts, you specify which edge you want to be active. If you leave this configuration alone, then you will receive one interrupt for each pulse and you can measure the speed from the GTS with a timer.

If you are interested in measuring the direction as well, you can add an instruction in your Interrupt Service Routine (ISR) to switch the active edge. This way when the signal changes again, you will get another interrupt. In this case, you will get 2 interrupts per pulse from the sensor.

You can use the timer and some integer math to measure the time between the rising and falling edge to allow you to determine the direction of the gear, then you can also measure the time between one rising edge and the next to determine the speed of the gear.

To time the events, you can simply setup a counter to a speed that will not overflow for the measurements you'd like to make, but that also will give you good resolution. Each time you get an interrupt, save the value in the counter. Also, before saving it, subtract the last timer value that was saved from the current timer value. This will give you the change in time. Save that as well. You can then use the numbers elsewhere in your code to compute the speed. If you want to compute direction as well, the you'll need to store two old values.

Best of luck!
-Joe