Hi everyone
iv'e been trying to make an RPM meter for a rotary encoder (YUMO A6B2-CWZ3E-1024), basically by looping for the length of a given time and dividing the number of interrupts within that time frame by the P/R of the encoder
It doesn't seem to work, however.
I deliberately left in unused parts that are used when not doing direct port manipulation. It's based on a sketch i found in the forums, and seems to work for other people.
I have tried the suggested solutions in said thread, and searched for other ones as well, but did not manage to get it to work
Any help or ideas will be much appreciated, thanks
sherzaad:
I moded your code based using a code from here:
try it out and let us know. hope it helps!
Thank you for your help, that is some work there
Unfortunately, it does not seem to work. I'm trying to debug it myself, stays on zeros the entire time.
One thing that might be a hint is the warning when i try to upload it-
jimmer-
i should've figured it might cause confusion, i used a ternary operator, it's a good way to operate a "yes or no" situation in a single line without an if
In this case- "pulse=pulse plus [if pin a= pin b, +1. Otherwise, -1]"
I need just a single direction, and it's ok to even count only the rising edges to get 1024 pings/revolution, i really don't need 2048, it's overaccurate
strange indeed, I would have expected at LEAST the pulse count to return you some value at the encoder is rotated. I have used the actual encoder code from that link before
That seems to fix the problem, Thanks!
but something new popped up-
for some reason, i'm getting more 3000 pings for one revolution, probably 4000, something is being counted twice. Trying to find what right now, will report when (if) i find it.
After that i'll change the code to use direct port manipulation and share it, this encoder is supposed to be spinning up to 3000rpm, so reading FAST is important....
I guessed it was some kind of compressed if then else statement
I think the problem with your original is that that method (comparing A== B ) needs a reversed answer depending on which channel has changed. You could do that by two separate interrupts or adding an if then else.
I've been using a different method that's not as neat as yours, gonna have a play with it now.
iv'e been trying to make an RPM meter for a rotary encoder (YUMO A6B2-CWZ3E-1024)
For an rpm meter the resolution of this encoder is not required. According to the part number, there should be a Z signal output once per revolution. Why not use it?
With interrupt set to CHANGE you're getting over 100000 pulses per second at 3000 RPM, try it with FALLING instead (51200 PPS), still way too many IMHO. And, if you only want RPM, only read 1 channel, (A or B).
Excuse me for my late reply, real life was knocking at my door for a couple of days. merry christmas everyone.
the 1ppm point is very valid- i'll need to also get a real live angular position i can plot, so the crazy 2048p/r is definitely too high, but i'd like to at least be able to pinpoint at a 1 degree resolution (so around 360p/r, which isn't too high)
I'm still working on the code to get the speed as high as possible, will report back with results and what i ended up using
jimmer- i don't see which pin i need to connect my interrupting signal wire to, could you enlighten me? since i'm using an encoder that outputs up to 9v, connecting it to 0 seems to be a bad idea