CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Encoder problem (one more) - solved
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mdemuth



Joined: 16 Apr 2007
Posts: 71
Location: Stuttgart, Germany

View user's profile Send private message Visit poster's website

PostPosted: Thu Jun 13, 2013 9:31 am     Reply with quote

As I wrote before, the raw data "position" is perfectly OK.

COPAL Type is: RECW20D50-201-1

Encoder_value_irq which is more ore less position/4.
It is needed to change encoder_value_irq at the time just when the knob falls into the detent position. When you turn it back the encoder_value_irq is not changed in the same position but in the next detent position.
It works like a drag indicator.

The copal datasheet says that the "click spot" is not clearly defined.
The detents and the optical code disc are not congruent.
I found one decoder where there is a state change just around the detent position:This one has the A=0 and B=0 in one detent position and when turning the knob 90° the signals in this next detent position are A=1 and B=0.
So we have sometimes 3 state changes and sometimes 5 state changes (only 4 in average) goinbg from one detent to the next.
Ttelmah



Joined: 11 Mar 2010
Posts: 20161

View user's profile Send private message

PostPosted: Thu Jun 13, 2013 9:56 am     Reply with quote

From the mechanical detents, 'of course you will'. These are not accurate devices. It normally doesn't matter at all. You use them like the mouse track button, doing several steps to give the movement you want. Treat them like the batons used by a marshal at an airport. If you want your value to move in one direction, move in that direction, so like the marshal, keep 'waving' right till you get to the position you want.
Accuracy costs money. If you want a precision detent, that occurs on an exact number of pulses, you need to spend a lot more money than these encoders cost.
I think you are just expecting too much.

Best Wishes
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Jun 13, 2013 10:57 am     Reply with quote

IF you are turning this with something other than a rotating shaft at continuous speed -
there are many low cost Absolute encoder designs that utilize a repeating 2 bit pattern that still resolves direction change cleanly, for you to consider. and low cost too
I should stress - switching your design to
Absolute Gray code
NOT the incremental type -
( as you have now ) -
devices with a slight logic rework to your program -
can handily avoid the kind of issue you see with the encoder you are using now. the result is simpler code - as you are pretty much guaranteed glitch free state change.

the Honeywell 510E is an example of a part i used at one time, and has 8 repetitions per revolution of the 4 bit absolute code . the data sheet should make it abundantly clear- why this can be better for you than sticking with incremental state detection.


Last edited by asmboy on Thu Jun 13, 2013 3:49 pm; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9658
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jun 13, 2013 2:35 pm     Reply with quote

You might also look at USDIGITAL for encoders like the SP-16. Not 'cheap' at $50 a unit but super reliable, good for decades of 24/7 operation.
With encoders you get what you pay for.
Since the detents are not 'cast in stone' by the mfr, you'll have to compromise..money or performance.

hth
jay
mdemuth



Joined: 16 Apr 2007
Posts: 71
Location: Stuttgart, Germany

View user's profile Send private message Visit poster's website

PostPosted: Fri Jun 14, 2013 4:19 am     Reply with quote

The product suggested never have this issue, it is only present when using encoders mechanical detents.

Meanwhile I changed my code:
Instead of using the drag counter:
Code:

if (position < 7)  // 4 state changes between two clicks
{
encoder_value_irq++;
position=10;
}
if (position > 13) // 4 state changes between two clicks
{
encoder_value_irq--;
position=10;
}

I simply make
Code:

encoder_value_irq = position/4;

and initialize position with 2 in the startup sequence of the device.

This algorithm is more simple than the other one with the drag –counter I used first.
Advantage: It works OK with encoders not having the discussed behavior (3 or 4 or 5 state changes).
Disadvantage: The mechanical hysteresis is less than using the drag –counter algorithm: 1 state change compared to 4 state changes needed to change the value shown.

If you move slowly from one clickspot to the next and back you feel the difference.
Maybe some of you are interested in comparing both options (drag-counter versus simple modulo4).

I also check the speed advantages of the code proposed by Ttelmah.
My code needs about 7µs. Ttelmah's code needs between 5µs and 6µs which is at least 1µs (15%) less then my code.
Thanks for that!
I finally implementented the faster code (just to have more time to do other things in the future).
Except the disadvantage listed above, no problem so far.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group