Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Problems counting encoder pulses (http://www.chiefdelphi.com/forums/showthread.php?t=24681)

bludstayne 02-02-2004 17:34

Problems counting encoder pulses
 
We are having problems counting pulses with our encoders, even at very low speeds. We aren't sure whether this is a problem in the code or with the hardware, but our counting problem is so bad that we can watch the controller missing pulses on hyperterminal. Is anyone else having this problem?

kc8nod 02-02-2004 17:43

Re: Problems counting encoder pulses
 
Do you know how fast you are sampling the inputs?
How about how fast the encoder shaft is turning?

Without seeing your code it is hard to diagnose.

If you are reading the inputs only once every 26ms, you are very likely to miss pulses.

deltacoder1020 02-02-2004 17:47

Re: Problems counting encoder pulses
 
best to put sensor-checking code (if you are using a polling method) in user_routines_fast.c

the best way (if possible) to poll such sensors would probably be interrupts.

bludstayne 02-02-2004 18:23

Re: Problems counting encoder pulses
 
Our code is in user_routines_fast. We tried adding another variable to the code to count the loops when the code did not detect a high signal, and usually we looped several thousand times (at least) between "hits." As I said, we were going VERY slowly. Thanks for your ideas, though. We appreciate any help you can give us.

velocipenguin 02-02-2004 21:50

Re: Problems counting encoder pulses
 
You might want to consider using an external counting circuit to count pulses and store them in some sort of register that can be read by the RC at any time. Before doing that, however, I would recommend modifying your code so that it uses interrupts to count pulses - this would eliminate any problems caused by the fairly low sample rate imposed by the rate at which the main loop executes.

Guest 02-02-2004 21:56

Re: Problems counting encoder pulses
 
We have a custom circuit that converts the frequency of pulses to an analog signal from 0 to 5v. With the counting circuitry independent from the control loop in software, it is easier to isolate problems and work on the "real" programming ;)

kc8nod 02-02-2004 22:35

Re: Problems counting encoder pulses
 
Even if your code is running in user_routines_fast.c you can still miss pulses. Remember that everything comes to a screeching halt when it is time to run the Process_Data_From_Master_uP(). The most reliable way to count pulses is with an interrupt-driven routine. Perhaps you could look at Kevin Watson's example code at http://www.kevin.org/frc/
But if you really are turning the shaft very slowly (much greater than 26ms between pulses) it sound like you've got some other bug.
Why not post the code here?

Kevin Watson 02-02-2004 23:07

Re: Problems counting encoder pulses
 
Quote:

Originally Posted by kc8nod
Even if your code is running in user_routines_fast.c you can still miss pulses. Remember that everything comes to a screeching halt when it is time to run the Process_Data_From_Master_uP(). The most reliable way to count pulses is with an interrupt-driven routine. Perhaps you could look at Kevin Watson's example code at http://www.kevin.org/frc/
But if you really are turning the shaft very slowly (much greater than 26ms between pulses) it sound like you've got some other bug.
Why not post the code here?

Yes, there is an example written for the EDU-RC that should be easilly ported to the FRC-RC. Just drop encoder.c/.h into your project and modify user_routines_fast.c to call the interrupt handlers. The interrupt handlers are very efficient and should have no problem with many hundreds of counts per second (I've successfully done five thousand/sec).

-Kevin


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

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