Reading from Piezoelectric disk at 44.1kHz?

I am looking for a way, using the MKRZero, to read the voltage from a piezoelectric disk at a rate of 44.1kHz or the highest frequency possible. From what I understand, analogRead will allow me to read it at 10kHz and I am looking for a higher frequency than that. Is there a way to use the Amplitude Serial Plotter or Audio Frequency Meter library to do this? Or something else? Thank you much.

Matt

If you're looking to digitise some analog signal, you may have to look into external ADCs. 44.1 kHz (standard CD frequency) should be no problem to find. The Arduino's built-in ADC is way too slow for that.

Well, I am looking to find a peak in the signal that happens in 0.00005s, would I be able to find it with the built-in ADC? I also need to measure the time when that peak happened. Is there a way I can read it at 44.1kHz until a threshold is reached?

mattjones188:
Well, I am looking to find a peak in the signal that happens in 0.00005s, would I be able to find it with the built-in ADC?

No.

Thank you!

MKRZero -- an audio-capable Arduino with ARM.

Arduino Sound library – a simple way to play and analyze audio data using Arduino on SAM D21-based boards.
I2S library – to use the I2S protocol on SAMD21-based boards. For those who don’t know, I2S (Inter-IC Sound) is an electrical serial bus interface standard for connecting digital audio devices.

That's a 48MHz 32-bit chip. It runs rings around the 16MHz 8-bit AVR-chip Arduinos.

Read the piezo as sound?

One problem: the board will NOT take more than 3.3V and piezo disks can spike wayyyyyyyyy higher voltages.

I have found that cheap BJT's can deal with piezos. I haven't tried driving opto-isolators with piezos but you can blink a red led by tapping a good piezo -- look up 'piezo generator' on youtube. Problem is that samples per second will be low, the harder the piezo is tapped the longer the blink (in 2 or 3 digit milliseconds).

Even so, 50us is too short a pulse to be detected reliably with a 44.1ks rate, because in a typical audio codec it undergoes extremely sharp filtering around 20KHz, which makes it not phase accurate at such a high frequency.

GoForSmoke:
One problem: the board will NOT take more than 3.3V and piezo disks can spike wayyyyyyyyy higher voltages.

If it's just a single peak within a whole lot of nothing, a zener or schottky clamping diode may be able to take care of that.

Yes the piezo will be reading sound. It will be in a very quiet environment and the sound it will be looking for is a chirp that is about 100us long at 10kHz. I am looking to find the time to that first peak. So I could use a clamping diode to stop it from going over 3.3V? Or a BJT? So how could I use an external adc to find the peak? Or is there something out there that is small and can record at 44.1kHz?

mattjones188:
Yes the piezo will be reading sound. It will be in a very quiet environment and the sound it will be looking for is a chirp that is about 100us long at 10kHz. I am looking to find the time to that first peak. So I could use a clamping diode to stop it from going over 3.3V? And how could I use an external adc to find the peak?

You should probably use some kind of active preamplifier, such as an op amp circuit. Piezos don't function well when loaded with a low impedance. Then run tests and capture the waveforms - look at those and decide how to handle it.

An Arduino method would be to use an OpAmp to “digitise” the signal (background levels are kept at 0V, anything above a certain level including the chirp comes out at +5V or +3.3V), then connect that to a digital port, and connect it to an interrupt on rising edge. The moment you get the interrupt check the time and you know when it happens. This can give you a timing as precise as the Arduino can do.

So there is an op-amp that you can adjust to where it outputs +3.3V when a certain input voltage level, from the piezo, is reached? What is an interrupt on rising edge?

Well, I am looking to find a peak in the signal that happens in 0.00005s, would I be able to find it with the built-in ADC? I also need to measure the time when that peak happened. Is there a way I can read it at 44.1kHz until a threshold is reached?

You've got your answer, so you know you'll need different hardware to read that fast, or to read the highest frequencies.

But, to get the practical "peak" or "loudness" of real-world sound you don't need to read that fast and you don't need the highest frequencies.

Sound is dominated by lower/mid frequencies... If you want to get a "feel" for that., load a music file into [u]Audacity[/u] and apply a high-pass filter at 5kHz. You'll hear how quiet it is and you'll see the same thing on the meters and in the waveform display. Then try the opposite experiment with a 5kHz low-pass filter. The peaks/loudness won't change noticeably. It will just sound a little "dull" or a little "lower quality". In fact the measured peaks may be higher when you filter-out the highest frequencies, due to the "side effects" of filtering.

Depending on your application, you might also consider using a [u]Peak Detector[/u]. The peak detector quickly charges a capacitor to the peak and then it slowly discharges (typically over several milliseconds or more) giving you plenty of time to read the peak and potentially freeing-up the microprocessor to do other things between reads.

There are real-world limitations to how-fast a peak detector can work (depending on the components) so you may have to experiment to see if it's fast enough for you.

mattjones188:
So there is an op-amp that you can adjust to where it outputs +3.3V when a certain input voltage level, from the piezo, is reached?

With the appropriate external components, that's a typical thing for an OpAmp. Do a Google search on OpAmps and their use.
A schmitt trigger may also do the job for you (they can be bought as ready made ICs, or quite easily constructed using an OpAmp).

What is an interrupt on rising edge?

https://www.arduino.cc/en/Reference/AttachInterrupt

(and indeed with this kind of sensing you have completely diverted from sound detection to peak detection, because from your description this is what you seem to be looking for: a loudness peak).

Piezos make big spikes when physically hit. A tap can flash a led. A chirp will need amplifying to even register. Don't worry about the 3.3V.

If your circuit limits the peak voltage then how will you know when the peak is reached?

mattjones188:
I am looking for a way, using the MKRZero, to read the voltage from a piezoelectric disk at a rate of 44.1kHz or the highest frequency possible. From what I understand, analogRead will allow me to read it at 10kHz . . .

I don’t know what the A/D sample rate is achievable using analogRead on the MKRZero but the SAM D21 MCU datasheet quotes a 350k sample per second top sample rate which is considerably faster than the garden variety Atmega328 Arduino boards. That top sample rate probably requires using DMA and some continuous sampling mode if one can figure out how to configure it, but I would expect the single sample analogRead conversion rate is also considerably faster than ~10k samples per second.

MrMark:
I don't know what the A/D sample rate is achievable using analogRead on the MKRZero but the SAM D21 MCU datasheet quotes a 350k sample per second top sample rate which is considerably faster than the garden variety Atmega328 Arduino boards. That top sample rate probably requires using DMA and some continuous sampling mode if one can figure out how to configure it, but I would expect the single sample analogRead conversion rate is also considerably faster than ~10k samples per second.

You also have to be able to process the signal at any rate you capture it at.

Would the logic follow, that if the MKRZero can play sound at 44.1kHz it can read a voltage at the same frequency? In some of the example codes online I have seen that it can read from an SD card and play at 44.1kHz.

For my application, the loudness or peak of the sound will vary in magnitude as a result of a maximum 900mbar pressure variation and adjusting the intensity of the sound produced. So I would need to vary the threshold with pressure. Is that possible with a Schmitt trigger? Also, would an op-amp or a Schmitt trigger be affected by temperatures in the range of -40C to 40C?

Is there a way to adapt this example to using a piezo disk?

I was hoping to read in the values from the piezo disk for around 0.2s at most and then I can look through the values to find when the peak happened.

What you need to know is that sample rate is not equal to the frequency. It's at least double. Look up the "Nyquist criterion".

mattjones188:
Yes the piezo will be reading sound. It will be in a very quiet environment and the sound it will be looking for is a chirp that is about 100us long at 10kHz.

A piezo disk can be used as contact microphone, but not to pick up low level sound through air.
A common electret microphone would be my preferred choice.
If you use a board with high gain pre-amp and threshold detector (digital out), then any Arduino can be used.
You might have to tweak the board to reject low frequencies.
Leo..