Analog input pulldown resistor?

Hi all,
I've got a project going right now where I'm scanning a bunch (~50) inputs and reading in analog voltages ~0-5V. I've got a few 'slave' CD4051's feeding into the inputs of 1 master CD4051 and the output of that goes to A0. The scan portion of my code seems to work fine and I'm getting responses from the channels that I'm triggering but I'm actually also getting additional responses on the trigger channels that aren't being triggered.

After thinking about this a while and getting frustrated the only thing I could come up with is that there's some input/internal capacitance on the A0 input that's holding up the voltage from the previous CD4051 selection after the CD4051 has switched over to the next channel. I'm thinking I need a pulldown, maybe 1k or so, to discharge that voltage in between channel reads. The input impedance to A0 is like 100M and differences in the voltage I'm reading from Vdrop across the pulldown when active would be negligible enough for what I'm doing, I think. I haven't tried it yet, I'm wondering if anyone's seen this problem before and know a way around it.

Thanks!

I'm wondering if anyone's seen this problem before

Yes it called "cross talk" and comes of having too higher an input impedance on the channels.

I'm thinking I need a pulldown, maybe 1k or so, to discharge that voltage in between channel reads.

pull up or pull down you can use either, 10K to 100K should work.
If it is too low you can load the unnamed sensor too much.

s that there's some input/internal capacitance on the A0 input that's holding up the voltage from the previous CD4051 selection after the CD4051 has switched over to the next channel.

Yes this is called the sample and hold capacitor on the front of the A/D inside the processor chip..

Thanks for the quick reply! Glad it's as simple a fix as I was hoping for. The 'unnamed sensor' is a typical piezo from Tayda (http://www.taydaelectronics.com/piezo-electronic-tone-buzzer-alarm-3-28v.html) so you're right the PD resistor has to be bigger. I think anything over 2.4k should actually work but may as well go higher like you said (10k) for some breathing room.

You said it could be pulldown OR pullup but I think it has to be a pulldown in this case otherwise the analog input will sense 5V when the piezo isn't being triggered. Unless I'm missing something really obvious...

I'm confused. That is a buzzer with electronics in it to drive the piezo. How are you using it as a sensor? Have you taken it apart and mean that you are using the piezo element alone as a sensor?

How are you handling the AC nature of the output of the piezo? What do you mean by the piezo being triggered?

Yup, it is a buzzer circuit. I got them with the intention of having to pull the driver circuits off the piezo element but I tried it with them still on there and they worked so I guess that driver circuit is 2-way as well. Lucky break for me not to have to modify 50 of those things.

The output of the piezo after smacking it is a damped sin wave. I deal with only looking at the first peak by setting an input 'threshold' in my code. That took a little tweaking but I've got it to the point where it's sensitive to pick up light hits but discerning enough to ignore the 2nd, 3rd, etc wave crests of the piezo output. This also happens to filter out an accidental touches if i graze a sensor or any vibrations that are transferred from one trigger to the other through the piece of wood they're taped to.

When I say triggered I mean I have the piezos taped (for now) to a piece of extruded rubber. I've been tapping the top of the rubber pad with my hands but they'll eventually be mallets.

OK. Keep in mind that the output might damage your ICs via the protection diodes. Not sure how much current can come out of your piezos, especially if they get smacked harder than usual. Probably just adding a 1k resistor in series between the piezo and the IC would be enough.

Of course, in this case your circuit likely already provides that resistive protection through the parts inside.

polymorph:
OK. Keep in mind that the output might damage your ICs via the protection diodes. Not sure how much current can come out of your piezos, especially if they get smacked harder than usual. Probably just adding a 1k resistor in series between the piezo and the IC would be enough.

Of course, in this case your circuit likely already provides that resistive protection through the parts inside.

I'm using 5.1V zeners across every piezo for protection of the inputs.

UPDATE: I tried using the 10k pulldown in parallel with the A0 input but I'm still getting multiple triggers being activated by hitting only 1 piezo. Any thoughts? I'm not too familiar with the crosstalk Grumpy_Mike was talking about.

The sample-and-hold capacitor inside the Arduino may still have some charge left from the previous input measured. That small amount of capacitance is the reason why the AVR spec sheets say that the impedance of the source should be 10k or less.

Try two analogRead in a row with a 1 millisecond wait between, and only look at the second read.

That definitely seemed to help the multiple notes issue a lot! I’ve lost a lot of the responsiveness of the circuit now though. Takes a few hard hits to make the trigger go off and two fast hits never triggers twice. Starting to suspect my code has some major flaws. Posting here in case you/anyone is interested in helping more (but thanks for all the help so far). It’s a midi implementation which should be straight forward but it’s just not responding like I hoped it would.

const int TH = 1; // threshold
const int ANA_0 = A0;

int s0 = 5; // slave registers
int s1 = 6;
int s2 = 7;

int m0 = 2; // master registers
int m1 = 3;
int m2 = 4;

int currentRead = 0 ; // current read
//int lastState = 0; // previous states
int currentVel = 0; // current velocity of read
int note[37]; // notes array

void setup() {
  Serial.begin(31250);
  //Serial.begin(38400);
  pinMode(m0, OUTPUT); digitalWrite(m0, LOW);
  pinMode(m1, OUTPUT); digitalWrite(m1, LOW);
  pinMode(m2, OUTPUT); digitalWrite(m2, LOW);
  
  pinMode(s0, OUTPUT); digitalWrite(s0, LOW);
  pinMode(s1, OUTPUT); digitalWrite(s1, LOW);
  pinMode(s2, OUTPUT); digitalWrite(s2, LOW);
    
  // fill notes array
  note[0] = 0x2B; // lowest note
  for (int i = 1; i < 37; i++) {
    note[i] = note[i-1] + 0x1;
  }
}

void loop()
{
  int temp;
  for (int countm = 0; countm < 8; countm++) {
    selectMaster(countm);
    for (int counts = 0; counts < 8; counts++) {
      selectSlave(counts);
      temp = analogRead(ANA_0);
      delay(1);
      currentRead = analogRead(ANA_0);
      if(currentRead > TH) {
        //Serial.print(currentRead); // TEST /////// /////// /////// /////// /////// ///////
        //Serial.print("\n");
        currentVel = map(currentRead, 0, 1023, 0, 127); // map velocity
        noteCmd(0x90, note[countm*8 + counts], currentVel); // note on
        //delay(50);
      }
    }
  }
  //delay(100);
}

void noteCmd(int cmd, int pitch, int vel) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(vel);
}

void selectMaster(int count) {
  digitalWrite(m0, count & 0x1);
  digitalWrite(m1, (count >> 1) & 0x1);
  digitalWrite(m2, (count >> 2) & 0x1);
}

void selectSlave(int count) {
  digitalWrite(s0, count & 0x1);
  digitalWrite(s1, (count >> 1) & 0x1);
  digitalWrite(s2, (count >> 2) & 0x1);
}

An unfiltered signal from a piezo is going to be a ringing waveform at about the resonant frequency of the piezo.

You might be able to hack the internals of each piezo to use a transistor BE junction as a diode. Then if there is a small capacitor in there and a resistor to drain it, now you have a smoother, longer pulse that is simpler to detect.

Some kind of electronic xylophone?

Please use code tags.

polymorph:
Some kind of electronic xylophone?

Bingo.

polymorph:
An unfiltered signal from a piezo is going to be a ringing waveform at about the resonant frequency of the piezo.

You might be able to hack the internals of each piezo to use a transistor BE junction as a diode. Then if there is a small capacitor in there and a resistor to drain it, now you have a smoother, longer pulse that is simpler to detect.

I've got the clamping diode and a resistor both in parallel with each piezo already (I don't think it needs a rectifier, but I haven't put a scope on the raw piezo output yet myself) but I hadn't thought about adding a capacitor in parallel as well to smooth the waveform. Great idea!

A clamping diode is not a rectifier. Merely adding a capacitor in parallel will likely just attenuate the waveform.