Jump to content

Software swapping encoder pins?


Sauraen
 Share

Recommended Posts

Hi TK,

 

In the manual configuration for encoders, I see you have only four options for connecting encoders to a DIN shift register: 0:1, 2:3, 4:5, and 6:7. It says "If you notice that the encoder increments in the wrong direction, the pins have to be swapped at the hardware side!"

 

Is there any chance you could also include 1:0, 3:2, 5:4, and 7:6 as allowable modes? I'm laying out a board for a front panel that encoders will be permanently mounted in, and I don't want to power it up and find out half the encoders turn in the wrong direction, because I can't swap the wires on the hardware at that point! (Plus it makes it easier to lay out if I can swap the order arbitrarily.)

 

I'm sure you could figure this out quite easily, but this is a quick way to swap bits 1 and 0, 3 and 2, 5 and 4, 7 and 6. It would seem to me to be as easy as making a copy of the input data byte from the shift register, modifying the copy as follows, and then reading from either the original or the copy according to the configuration line.

data = ((data & 0x55) << 1) | ((data & 0xAA) >> 1);
//or in assembler, assuming data is in r1
mov r2,r1
andi r2, 0x55
rol r2
andi r1, 0xAA
ror r1
or r1,r2

Thanks,

Sauraen

Link to comment
Share on other sites

Thank you for the fast fix!

 

In the User Manual, this item is called ".pins", not ".pos". However, I see in $MIOS32_PATH/include/mios32_enc.h that the appropriate variable is in fact mios32_enc_config_t.cfg.pos. Is this what you changed the handling for? If so, does the NGC parser simply read the first of the two pins specified and set that value into mios32_enc_config_t.cfg.pos, so we should simply be able to write our configuration files with ".pins=1:0", etc., with no further changes?

Edited by Sauraen
Link to comment
Share on other sites

Ok, understood the problem: the .NGC file parser was too restrictive - I released a mbng_file_c.c change in the repository which allows swapped pins, and which should raise an error message on unsupported pin combinations.

Please help to test this (critical) change - we've to avoid that valid pin combinations are refused by the parser due to a potential programming error!

 

Best Regards, Thorsten.

Link to comment
Share on other sites

It's going to be a couple weeks before I will be able to test this (my front panel is still raw aluminum and copper clad board), but once I build it I should be using each valid combination. But can't you just take a controller you already have, swap each pin statement in the configuration file (e.g. change 0:1 to 1:0) and see if all the encoders turn backwards?

 

Edit: Working fine, thanks very much! Encoder rotates backwards with pins in wrong configuration, then switching them and saving causes it to rotate correctly again.

Edited by Sauraen
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...