Mux encoders?

Status
Not open for further replies.
The easiest "mux" is using a Teensy LC to read several encoders and send the data as serial or I2C communication.

hi,

hmmm.. I don't know if this could be a problem in the future.. I already need to power a Teensy3.2 and a RaspberryPi from the same source .. if I now add a Teensy LC.. could this lead to problems?
 

BRO!!!!! .. THIS MIGHT SAVE MY LIFE !!! :))) thank you!!!

I will try this out as soon as I am at home. But I wonder about this code here:
Code:
void readInputs(uint8_t i) {
  selectAddress(i);
  delayMicroseconds(50);
  readEnc(i);
}

does this delay have to be there? delayMicroseconds(50);

I would rather have no delays.. can I use millis() here?
 
I didn't write the linked code but I assume that the delay is meant to wait for the switching time of the used mux but 50µs seems to be quite long. Look in the datasheet of the port extender you intend to use, it probably is much faster.
 
does this delay have to be there? delayMicroseconds(50);

Yes, a delay is always required after switching a mux, because the mux output takes time to change. How much time is a good question. 50 us may be overly conservative. With rotary encoders, the time will depend on the pullup resistors. If you want a faster time, use really pullup resistors between 1K to 3.3K. The ones built into the chip are much higher impedance, so the signal takes longer to change.
 
In the linked code, you know what the next value of the variable 'i' is going to be, so you could change that readInputs function to set up the mux address to the next input to be read and reduce or eliminate the delay needed.

Code:
void readInputs(uint8_t i) {

  //delayMicroseconds(50);
  readEnc(i);
  selectAddress((i+1)&7);     // only works for 8 inputs
}
 
Yes, a delay is always required after switching a mux, because the mux output takes time to change. How much time is a good question. 50 us may be overly conservative. With rotary encoders, the time will depend on the pullup resistors. If you want a faster time, use really pullup resistors between 1K to 3.3K. The ones built into the chip are much higher impedance, so the signal takes longer to change.

thanks you :) .. will try this out :)

In the linked code, you know what the next value of the variable 'i' is going to be, so you could change that readInputs function to set up the mux address to the next input to be read and reduce or eliminate the delay needed.

Code:
void readInputs(uint8_t i) {

  //delayMicroseconds(50);
  readEnc(i);
  selectAddress((i+1)&7);     // only works for 8 inputs
}

cool dude :) .. this is a very nice idea .. will check this out
 
guys, this works perfectly!! :)) thank you so much :)

maybe one last question.. how would I decouple this? .. a capacitor to the 4051? or 3k3 resistors from each pin to 5V as pull-ups and one 10nF capacitor from each pin to ground for de-bouncing?
 
I would recommend looking at the manual for the encoders that you have, they usually have their own recommended schematic for this.
 
I would recommend looking at the manual for the encoders that you have, they usually have their own recommended schematic for this.

hi, .. I did .. unfortunately for me as a total noob, this is all chinese to me.. :/
I know that this must be decoupled but i wonder if I should decouple the ICs`? or the encoders itself? or both?
 
This is more or less the filter circuit that my encoders use. I didn’t design that part of the board, but it looks very similar. The board was part of a old Open Labs controller before they went a different direction and stopped making and supporting their controllers. They never released 64 bit drivers for this controller so I repurposed it. I didn’t decouple any of the 4051’s on my board, but I can’t say wether you should or not I just know mine has worked pretty solid so far.
B63AF000-CA4C-4C39-8169-BF14A49C7B02.jpeg
 
I didn’t decouple any of the 4051’s on my board, but I can’t say wether you should or not I just know mine has worked pretty solid so far.

I use this Encoders here: https://www.amazon.de/gp/product/B00NWFECHW/ref=oh_aui_detailpage_o04_s00?ie=UTF8&psc=1
.. when i used directly on my Teensy, without a 4051, I had inconsistent values.. then I read about decoupling and did it like
"one 3k3 resistor from each pin A/B to +3.3V as pull-ups and one 10nF capacitor from each pin A/B to ground for de-bouncing".. and this worked perfectly..

but now I mux them with the 4051s and again I deal with this inconsistent values.. and now I'm asking myself, if I should decouple on the IC-Pins where the Encoder is connected(?) or decouple the IC itself(?)... or both?
 
I use this Encoders here: https://www.amazon.de/gp/product/B00NWFECHW/ref=oh_aui_detailpage_o04_s00?ie=UTF8&psc=1
.. when i used directly on my Teensy, without a 4051, I had inconsistent values.. then I read about decoupling and did it like
"one 3k3 resistor from each pin A/B to +3.3V as pull-ups and one 10nF capacitor from each pin A/B to ground for de-bouncing".. and this worked perfectly..

but now I mux them with the 4051s and again I deal with this inconsistent values.. and now I'm asking myself, if I should decouple on the IC-Pins where the Encoder is connected(?) or decouple the IC itself(?)... or both?

Two questions.
1. Did you make sure to disable interrupts for the encoders?
2. How long of a delay did you use after switching the mux address?
 
Two questions.
1. Did you make sure to disable interrupts for the encoders?
2. How long of a delay did you use after switching the mux address?

Hi,

1) ehm.. no .. oO .. I did not even know that one could do that(?) oO .. how would I do this?
2) no delay.. I use rcarr's suggestion for the code..

Code:
void readInputs(uint8_t i) {

  //delayMicroseconds(50);
  readEnc(i);
  selectAddress((i+1)&7);     // only works for 8 inputs
}
 
Hi,

1) ehm.. no .. oO .. I did not even know that one could do that(?) oO .. how would I do this?
2) no delay.. I use rcarr's suggestion for the code..

Code:
void readInputs(uint8_t i) {

  //delayMicroseconds(50);
  readEnc(i);
  selectAddress((i+1)&7);     // only works for 8 inputs
}


At the very top of your code before the encoder library is defined you have to
Code:
#define ENCODER_DO_NOT_USE_INTERRUPTS

And if that still doesn’t work you can try to add some delay and see if that fixes it.
 
At the very top of your code before the encoder library is defined you have to
Code:
#define ENCODER_DO_NOT_USE_INTERRUPTS

And if that still doesn’t work you can try to add some delay and see if that fixes it.

aaaah okay,.. thank you :)) .. I will try this out
 
Status
Not open for further replies.
Back
Top