Pinmode query

theboot900

Well-known member
So im sharing an analog pin to read analog in from a multiplexer. The multiplexer gets enabled, reads various values then gets disabled.

That same pin then switches into a digital out pin (as part of a 16 bit parallel output to a display).

This all works fine, however i am getting some jitter on the analogRead 12 bit (+-2) which wasn't there before the multiplexer (MC74HC4067ADWG) This is usable however i was reading on another thread about not having an analog pin switched to pinMode(i, INPUT) before doing an analog read but instead use pinMode(x, INPUT_DISABLE). I wanted to try this to see if it reduces some jitter.

But i would like to confirm ive got this correct and dont blow anything. This will be the flow

1) pinMode(x, INPUT_DISABLE)
2) EnableMultiplexer
3) AnalogRead Multiplexer
4) DisableMultiplexer
5) pinMode(x, OUTPUT)
6) Digital out to Screen

Does setting pinMode(x, INPUT_DISABLE) disable the currently set OUTPUT mode on the pin as well. I don't want to pass voltage in from the multiplexer analogValues while the pin is in OUTPUT mode. Im assuming pinmode will set the pin in only one specific state in the different calls but would like to confirm
 
So im sharing an analog pin to read analog in from a multiplexer. The multiplexer gets enabled, reads various values then gets disabled.

That same pin then switches into a digital out pin (as part of a 16 bit parallel output to a display).

This all works fine, however i am getting some jitter on the analogRead 12 bit (+-2) which wasn't there before the multiplexer (MC74HC4067ADWG) This is usable however i was reading on another thread about not having an analog pin switched to pinMode(i, INPUT) before doing an analog read but instead use pinMode(x, INPUT_DISABLE). I wanted to try this to see if it reduces some jitter.

But i would like to confirm ive got this correct and dont blow anything. This will be the flow

1) pinMode(x, INPUT_DISABLE)
2) EnableMultiplexer
3) AnalogRead Multiplexer
4) DisableMultiplexer
5) pinMode(x, OUTPUT)
6) Digital out to Screen

Does setting pinMode(x, INPUT_DISABLE) disable the currently set OUTPUT mode on the pin as well. I don't want to pass voltage in from the multiplexer analogValues while the pin is in OUTPUT mode. Im assuming pinmode will set the pin in only one specific state in the different calls but would like to confirm

Yes, setting the pinMode to INPUT_DISABLE (which is the correct setting when using the pin to read input analog voltages) definitely sets the pin to an input, disabling the pin's output drivers.

Make sure to note that when using analog MUXs (in my original TeensyMIDIPolySynth project, I used multiple Sparkfun 74HC4067 16-channel analog MUXs, some of them cascaded, all to allow reading 48 variable pots & 40 pushbuttons), make sure to provide enough settling time (the time from setting the 1-0f-16 address selection to the time that the analog voltage is actually read) to avoid inconsistent readings.

Good luck & have fun !!

Mark J Culross
KD5RXT
 
G
Yes, setting the pinMode to INPUT_DISABLE (which is the correct setting when using the pin to read input analog voltages) definitely sets the pin to an input, disabling the pin's output drivers.

Make sure to note that when using analog MUXs (in my original TeensyMIDIPolySynth project, I used multiple Sparkfun 74HC4067 16-channel analog MUXs, some of them cascaded, all to allow reading 48 variable pots & 40 pushbuttons), make sure to provide enough settling time (the time from setting the 1-0f-16 address selection to the time that the analog voltage is actually read) to avoid inconsistent readings.

Good luck & have fun !!

Mark J Culross
KD5RXT
Great thanks heaps for that Mark!
 
Back
Top