I did get it to work now, but it's strange the way it 'forces' a count of 2 increments instead of just 1. I've never seen anything so illogical before. Anything i do to make it count only 1 does not work, it becomes erratic.
... I cant explain yet why it insists on counting by 2..
You explained it yourself before. You said that the signals are always either 'both high' or 'both low'. In order this to happen the signals need to go through two transitions. You are counting both of those transitions when you move the encoder 'one click'.
Try detecting transitions on one line only:
In code:
if(sum ==0b1101 || sum ==0b0010) dir=1;
if(sum ==0b0111 || sum ==0b1000) dir=-1;
.. Or just disable interrupts from one of the data lines.
You explained it yourself before. You said that the signals are always either 'both high' or 'both low'. In order this to happen the signals need to go through two transitions. You are counting both of those transitions when you move the encoder 'one click'.
Try counting transitions on one line only:
dir = 0;
if(sum == 0b1101 || sum == 0b0010) dir = 1;
if(sum == 0b0111 || sum == 0b1000) dir = -1;
count = count+dir;
So are you using this encoder to tune your DDS chip?
When I used optical encoders in the late 70's I was tracking a linear probe on a spool aircraft cable spool drive with 1mm resolution up to 10m/s which is 10kHz. No problems and that left lots of margin.
Stopless encoder rotary controls used in DSO's etc may not be as fast but pulse rate depends on number of pulses per rev and rotation speed.
My guess is you would like to have 10 clicks in about 90 deg. or about 40 clicks per rev. for decimal selection , or simply use a BCD encoded rotary switch.
The options now are; 32, 64, 100, 128, & 256 pulses per rev.
These have a 200ns rise/fall time, from an optical quadrature encoder.
You can design it directly in hardware with a decimal up/down counter and read the result in parallel then use 3 switches. Left digit, select and right digit or use firmware to shift the digit from MSB to LSB after each select with only one switch using absolute or scientific notation and as many digits as you need.
Then another switch to load the resulting value or a longer duration on the select switch selected by firmware.
These are expensive but feel good. https://www.digikey.com/product-detail/en/EM14A0D-C24-L032N/EM14A0D-C24-L032N-ND/954402
I would be inclined to modify an optical mouse with a really good plastic wheel and use that for the interface. and use the twin optical detectors included and breakout the pulse forward and reverse into an Up;Down counter for parallel reading.... or use the Mouse/joystick port or the USB port.....
THe logic can reset the counter after read port is done and internally shift the digit towards Least significant digit. Then you can use a button mouse for left/right/ select and combinations for more features like increment frequency and step size.
That sounds like a good way to go. I like it.In one of the later iterations of the VFO project using a DDS module ( See:VK5TM's stuff on the DDS modules), they used the speed of encoder rotation to determine the size of the encoder steps, much like some modern mice do. That adds a new dimension (time). A fast turn may increment by 10's of kHz, while a slow turn may only increment 10 Hz per revolution or so. Your proposed method does much the same thing, but I think users may be more accustomed to the mouse way.
John
Something like this circular LED add on would make your project look coolIf your into that sorta thing?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?