Hardware in the loop quadrature encoder simulator

OHH MAN! Well I guess that solves all my problems! I thought it was the frequency of the whole wave NOT just changing states. WOW! So that finally solves my issue with the code.
Just to clarify to close this once and for all. Your frequency is state change and not full cycle AND the fact that you have 2 times the state change for the encoder counts is because you count 2 encoder counts per pin. So for 2 pins (2 waves) you count every change from high to low or from low to high (falling and rising edges). Is that correct?

Now to understand why my encoder is doing this to me.

I’m basically rotating the output part of the shaft (wheel) 360. There’s a screw to hold the wheel hub to shaft, and I’m using that as my reference.

I’ll tell you my issue in full. I’ve been assigned this project from someone before me. I have the encoder which I’m 100% sure of because I have the receipt email from robot shop. I have this rover that I also inherited, however, I don’t really trust the info on the website. I’m essentially trying to write a code on both arduino and raspberry pi to work with that encoder and motor combination.

The issue is that I’m not sure of the readings from the encoder. So I thought I’d make a simulation (with your code) so I can test MY code on both arduino and raspberry pi. Once they’re good and are giving me the same results, I can integrate them into the project.

Right now I’m getting stable results on arduino from the simulator (yours) and the encoder (230 transitions). I’m not sure why I’m getting 230 but that’s what I’m getting. I’m using the same code that I’ve included before.

What I’ll be doing next is writing code for the raspberry pi!

Hope that explains what I’m doing exactly.

Right now I’m getting stable results on arduino from the simulator (yours) and the encoder (230 transitions).
Now to understand why my encoder is doing this to me.

The issue does not appear to be the code.

Do you have external pull ups on the A and B pins? If not, change the pin mode to INPUT_PULLUP.

There is definitely some confusion between robotshop and pololu as to whether the encoder is 20 counts or 12 counts per revolution when reading all the available transitions. You should either see 6 or 10 counts/rev with the code you are using.

The rover spec says 30:1for the motor, so for one rev of the output shaft you should see either 180 or 300 encoder counts per revolution.

My thinking is that the gear ratio specification is not correct.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.