Jump to content

Rotary Encoders


Recommended Posts

Hi All,

Sorry for being cheeky but this is not a midibox question.

I am having an absolute nightmare trying to get reliable up/down code running for a mechanical 2 bit 36 detent grey code encoder. If I allow time for the worst case bounce (about 15mS !!) I miss good samples and subsequently my lookup table which processes based on last good read (bits 2 and 3) and current read (bits 0 and 1) goes off to la la land and then recovers.

Does anyone have some sample code that is known to work with noisy encoders ??

Thanks

Dave

Link to comment
Share on other sites

Hi Dave,

in the encoder driver of MIOS I'm doing plausibility checks in order to overcome this problem. The idea is, to measure the delay between two "encoder ticks". If it is shorter than 16 mS, an increment event won't be forwarded to the encoder handler if the last one was a decrement, and vice versa.

The code is located in mios_enc.inc; it works quite well with noisy encoders. I don't know if there are better methods, since this was developed by myself - it was the result of many experiments with different encoders :)

Best Regards, Thorsten.

Link to comment
Share on other sites

Thanks TK, Happy New Year....

Couldn't find your 16mS timer but in my code I have a 1mS ISR timer so I can use a similar method. Funny how quick you forget things, the last couple of projects have been 16F based to allow other members of our radio club to make updates, looking at 16 bit intructions and your macros took a bit of 'tuning in'

Plan is:

Read port (bits 0 and 1 where my encoder is)

copy to bits 0 and 1 of my encoder state register

Check if different to last read, if same return

debounce

call lookup table (based on last and present, 4 bits 0x00 to 0x0F)

check if direction flag(s) is set, if set check returned value is valid, if not. Tidy up and return

If valid, copy present reading to last reading (bits 2 and 3 of my encoder state register)

start direction timer / flag(s) (cleared in ISR)

process up / down / same

I did think about using the upper 4 bits for further checking as well

Will write the code tonight and see how it goes.

Thanks Again.

Dave

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...