Noise and grounding issues with piezo analog input with Teensy 3.2

Status
Not open for further replies.

Bryan42

Active member
I've been exploring piezo triggering with the Teensy 3.2 board (yes, yet another piezo project), and am seeing strange behavior with noise on the analog signal line and/or grounding issues. Basically, in quiescent mode (no tapping on box with piezo attached), and after a reboot, I see 30-40 mV of noise. However, most of the time, after a tap (light, medium, heavy, doesn't really matter though happens more often with heavy tap) the quiescent noise jumps to 90-100 mV and stays that way until I reboot the Teensy, whereupon the quiescent noise goes back to 30-40 mV. This occurs with the Teensy board connected (and powered) via a Raspberry Pi (3B+) and I also get similar results when connected via USB to a fully loaded (hardware and software) desktop Windows 10 PC.


Here is a diagram of the circuit I'm using:

Teensy Piezo circuit.jpg


If I hook up an oscilloscope, attaching leads to the signal line and ground, I see noise in the 1 MHz range (and some 60 Hz noise too). Interestingly enough, sometimes the mere attaching of the oscilloscope drops the noise to an average 10 mV and sometimes all the way down to 1 mV. Also, connecting the ground of my circuit to a direct ground on the oscilloscope can at times instantly drop the noise though not always. This can happen even with the scope not even turned on (but still plugged into the wall socket). So clearly, there is some grounding phenomenon going on.

One question I have about the use of the ground pins on the Teensy 3.2 board: I'm using the Agnd pin as suggested by other posts in this forum (and perhaps I read this elsewhere too) and the reference manual for the MCU seems to suggest this as well, but frankly, I find the ground pin on the opposite set of pins (the "digital side"), as shown in the diagram above to be quieter, and I've also experimented with tying these grounds together, though I think I read somewhere this may not be a good idea. Either way, I get the same strange behavior. So what is the official recommendation for the use of these ground pins? I know that's been answered before in this forum but I'm just looking for a good, clear confirmation of the recommended approach. As far as the signal conditioning in the circuit, I experimented with 10K, 20K, 47K, 100K and 1M and 2M ohm load resistors on the (35mm size) piezo, and found that the 1M ohm resistor appears to give the best SNR. I'm using diode clamping as well.

Here is the code I'm using (I have the Teensyduino sketch type set to "Serial"). In this code, I find the peak and average voltages read on the A0 pin using sample sizes of 50,000 samples per set, and then spit the results out to the serial port and display them on the serial monitor. This is done repeatedly:

Code:
// Compiled in Serial mode

const int led = 13;

const int analogPin = A0;

void setup() {
  pinMode(led, OUTPUT);
  digitalWrite(led, HIGH);
  Serial.begin(115200);
  while (!Serial && millis() < (2500+7500)) /* wait for serial monitor plus some more */ ;
  digitalWrite(led, LOW);
  delay(500);
  digitalWrite(led, HIGH);
  Serial.println("Piezo circuit noise monitor - 50,000 samples per set");
}


void loop() {
  int sig = analogRead(analogPin);
  noiseMonitoring(sig);
}

void noiseMonitoring(int sig)
{
  static int cntr = 0;

  static int peak = 0;
  static float sum = 0;

  // Take averages and find peaks of sample sets
  // with size of 50,000 samples
  
  if (cntr++ < 50000)
  {
     sum += sig;
     if (sig > peak)
     {
        peak = sig;
     }
  }
  else
  {
    float peakVolts = float(peak) * 1000.0 / 1023.0;
    Serial.print(peakVolts);
    Serial.print(" mV peak -- ");
    float avg = (sum / cntr) * 1000.0 / 1023.0;
    Serial.print(avg);
    Serial.println(" mV avg");
    peak = 0.0;
    cntr = 0;
    sum = 0;
  }
}


And here is a snapshot of the serial monitor window during a sample run, where you can see the quiescent noise jumping to 90-100 mV after a slap on the wood box the piezo is attached to. The noise stays in that range (remember, I'm taking statistics of 50K samples/set over and over) until the next reboot, whereupon the noise goes back to 30-40 mV:


Teensy Piezo results.jpg

Any advice is greatly appreciated, and I have to say I'm enjoying using this board. Just wish I could figure out how to correct the aforementioned problem.


Bryan
 
I don't have an answer as to *why* the variable behavior occurs, but I do have a suggestion for the noise in general.

From the data sheet, the MK20DX256VHL7 microcontroller wants to see less than 5K source impedance at the A/D input, and it is recomended the source impedance be as low as possible. The data sheet notes that the specs it contains were obtained with a source resistance of less than 8 ohms.

I would try buffering the piezo with a unity-gain op-amp and see if that makes the weirdness go away. If the opamp is very close to the piezo, this will also greatly reduce the noise.
 
I would try buffering the piezo with a unity-gain op-amp and see if that makes the weirdness go away. If the opamp is very close to the piezo, this will also greatly reduce the noise.

I would modify this suggestion slightly: use op-amp with FET imput, especially if you use the piezo differentially, which you should do anyhow.

alternatively, if you stick with single ended and have only a normal op-amp, use a FET as close as possible to piezo.
 
The piezo isn't so much of a voltage source as it is a charge source. The usual thing to do is to include a charge amplifier which will have a low output impedance suitable for driving the ADC input.
 
I don't have an answer as to *why* the variable behavior occurs, but I do have a suggestion for the noise in general.

From the data sheet, the MK20DX256VHL7 microcontroller wants to see less than 5K source impedance at the A/D input, and it is recomended the source impedance be as low as possible. The data sheet notes that the specs it contains were obtained with a source resistance of less than 8 ohms.

I would try buffering the piezo with a unity-gain op-amp and see if that makes the weirdness go away. If the opamp is very close to the piezo, this will also greatly reduce the noise.

Thanks for the reply.

Yes, I discovered yesterday after reading the reference manual for the MK20DX256VHL7 that anything over 5K source impedance could cause problems unless you set the right conversion rate. In my case, I was using a 1M load across the piezo, which is certainly much greater than 5K. (The piezo itself has gigaohms of DC resistance, and we measured 30 nF of capacitance in the lab yesterday).

So I went back to basics and hooked up a battery voltage source as a "signal" and tried a 1M ohm by 1M ohm voltage divider (and thus my signal was 1.6-1.8 V at 500K source impedance), and used the default conversion rates for 10 bit A/D (straight from Paul's code) and indeed the analog value read was way off the mark, and with the battery turned off would yield 100 mV of noise, or more. Then I switched to a 1K by 1K voltage divider (hence 500 Ohms source impedance) and got accurate readings, (using a voltmeter to compare against) with noise down in the 3 mV range (which is the quanta for a 10 bit ADC).


Then I switched to using Pedvide's ADC library and set the conversion rate to very low speed, and with the 1M by 1M voltage divider could get accurate readings and a quiescent noise floor of 3 mV, again which is the 10 bit quanta value.

The other thing I discovered with a high impedance source is that it's easy to upset the Teensy board. This was evidenced by two actions: (1) The practice of plugging and unplugging the USB cable from the Raspberry Pi to the Teensy board while the Raspberry Pi was still running would often result in a 30-100 mV or more noise floor on the analog input pins on the Teensy that would stay there until a reboot. (2) I accidently unhooked the grounding resistor of my battery voltage divider and thus delivered 3.6 V to the analog input pin (it still went through 1M ohm resistor in series) and ended up with a 2.88 V (yes volts) noise floor that would not go away even after turning off the battery. The voltage would stay there until I rebooted the board. This was even with a 0.1 uF capacitor between the analog input pin and ground. Both a voltmeter and the analog values read in the software would indicate this 2.88 V. So the ADC was measuring the right value, it's just what was the 2.88 V doing there in the first place? (Remember it would stay there even with the battery off).


So the aforementioned experiments demonstrated the need for lower source impedance and/or lower conversion rates, and the phenomenon of upsetting the board enough to cause high noise voltages to stay on the input pins until reboot. (Don't know why those voltages hang around but that's what they do.) By the way, the 0.1 uF cap on the input pin does help the accuracy. My noise floor without the cap was often 30 mV, and with the cap, 3 mV. This was with the high impedance source.


In my case, I don't need a fast sampling rate, so probably just slowing down the conversion speed will solve my problems. I have thought about using buffering on the piezo's, although I really don't want to complicate the circuitry if I don't have to. The fact that the Teensy board can easily be upset with high impedance sources would lean towards using buffering though. Also, I've grown cautious about hot swapping the USB cable. Now whenever I change my circuitry I power down the Raspberry Pi (and hence the Teensy) first, instead of just unplugging the Teensy from the Pi while the latter is running.
 
Last edited:
Originally Posted by Kjhales99
I would try buffering the piezo with a unity-gain op-amp and see if that makes the weirdness go away. If the opamp is very close to the piezo, this will also greatly reduce the noise.
I would modify this suggestion slightly: use op-amp with FET imput, especially if you use the piezo differentially, which you should do anyhow.

alternatively, if you stick with single ended and have only a normal op-amp, use a FET as close as possible to piezo.


Yes, I have thought of these things, especially after finding out the input impedance on the analog input pins is only 5K. I don't want to complicate the circuitry if I don't have to. I don't need high accuracy, but the useful low end range of my signal is in the 100 mV region, so having noise that high is problematic. If the noise is down in the 3 mV region, which I was able to achieve yesterday, then I'm good to go.
 
The piezo isn't so much of a voltage source as it is a charge source. The usual thing to do is to include a charge amplifier which will have a low output impedance suitable for driving the ADC input.

Yes, I'm aware of such things. Was trying to keep the circuitry simple. I wasn't aware till yesterday of the need for low impedance sources on the Teensy analog input pins.

Thanks for the reply.
 
Status
Not open for further replies.
Back
Top