Counter doesn't work?

Hi,

We are experimenting with single channel encoders and no matter what we do, we can’t get wpilib.Counter to work.

2022pendik.zip (326.3 KB)

Here’s the code, We tried everything in wpi.edu docs; but it was no help, neither in simulation nor on a real rio.

Thanks for taking the time to help,
-Berke

So, we solved the problem by ditching our test bed -a limit switch- for just some simple jumper wires; turns out the 10k resistor we have on our limit switch was causing some problems.

Looking at a Counter on a limit switch is very instructive to show that debouncing is useful. It’s amazing how many counts you get opening and closing one of those mechanical micro switches.

I don’t know why you had a resistor on the switch but my team has used resistors without trouble. Wire length can be problem; the limit isn’t particularly long especially with resistors.

You didn’t say why you thought the Counter wasn’t working. I didn’t look at your code much since there is a ton of code to hunt through for your Counter.

I’m glad you found your problem - good job. I hope you didn’t fool yourself into thinking that a limit switch on the robot was ever going to be as clean of a contact as a jumper at the input. That’s why WPILib docs for years has shown how to debounce with a Counter and later provided debouncing methods.

2 Likes