…about Linux, electronics, digital photography, whatever…
Icône RSS Icône Accueil
  • Piezo transducer signal conditioning

    Posté le 6th juin 2009 leucos 37 commentaires

    Piezo transducer are very common, very cheap, and can be very useful as sensors : sound, knock, shock, whenever it « moves » or « makes noise », a piezo sensor can help.

    However, the signal from those things is very unpleasant for the digital hacker : it’s roughly a sinewave that dampens over time. Also, the signal often goes negative which is pretty bad for mots digital chips out there. The ATmega168 (and most of the atmel 8 bit microcontrollers), for instance, indicates that voltage on any pin must be between -0.5V to VCC+0.5V. Piezo transducer easily go far beyond those bounds.

    In the capture below, voltage from the piezo goes a down as -52V and goes up to 9.2V. This is more than 60V peak to peak. If you don’t do anything, your poor microcontroller might get sick rather quicly :

    Raw signal from piezo (2)

    Raw signal from piezo

    In this capture, the signal first drops to -20V, and then flies up to over 35V. Almost 60Vpp here too.

    Raw signal from piezo

    Raw signal from piezo (bis)

    These are just examples, I didn’t tweak the piezo or smashed it with a hammer : just a hit with a fingernail, and you almost always end up having huge Vpp values. Also, the behaviour is not predictable (well piezos are, but the way we smack it isn’t), so it might go up first, then down, then up, who knows…

    A close up shows the « dampening sine-like signal » that occurs after the first big spikes :

    Piezo signal close up

    Piezo signal close up

    So signal conditioning is a must with those pesky animals if you’re doing digital.

    Let’s recap what has to be done :

    1. make that signal all positive :  most of the time, piezos signals are read by ADC, so we want positive voltages
    2. restrict signal bounds to 0 – VCC so voltage doesn’t climb to scary values (scary at least for microcontrollers and ADCs),
    3. shape the signal so it doesn’t make bumps and stays clean and predictable

    All these requirements are surprisingly easy to achieve. We will get to this goal in three steps, each spect taking care of one item above. Respectively :

    1. add a half-wave rectifier, in order to keep positive part of the waves
    2. add a zener diode, so signal doesn’t climb over zener’s breakdown voltage
    3. add a RC pair so ripples get filtered

    Half bridge rectifier

    First, we want to rectify the piezo signal, i.e. make it all positive. We’ll use Schottky diodes for that. Schottky are more interesting since they have a pretty low (compared to standard rectifier diodes) forward voltage drop (Vf), around 0.3V.

    Piezo signal as seen after a full-wave rectifier

    Piezo signal as seen after a full-wave rectifier

    You might ask : why not use a complete Schottky-based bridge rectifier, and make the whole signal positive, instead of filtering negative voltages ?

    Well, look back at the first scope shots of raw piezo signals. When signal changes sign, it makes it rather violently, and can even be higher on the new side than it was on the previous side. Now try to make the math abs() operation on the shape, mirroring the negative part of the shape on the other side of the time axis. You’ll end-up with an erratic plot : low, then high, then low. This means that, even with some filtering, you wont end-up with clean shape, but with a jittering thing that will look like the first signal, but all positive and less wild. This is not what we want, so we are sacrificing the negative part of the signal to get something nicer (the fine Agilent firmware bug is provided free of charge :) .

    Piezo signal rectified by only one Schottky diode

    Piezo signal rectified by only one Schottky diode

    In fact, well do a bit more than a half wave rectifier. If we just put a Schottky diode in series with the positive we’ll end up with the kind of signal shape shown on the left. We can see there is a fair amount of signal that is still below 0v, and in our circuit, we’re not supposed to have negative voltages. Even if the ADC can stand it, it probably won’t do any interesting measures with a negative signal.

    There is probably a good reason for this to happen, but I don’t have a clue right now. If you do, please leave a comment.

    So we have to get rid of this negative leftover, by adding a second Schottky diode, between ground and signal lines. We’ll just keep the positive signal, but it will be much easier to filter this way.

    Piezo signal rectified by two Schottky

    Piezo signal rectified by two Schottky

    Our piezo signal rectified by two Schottky looks like this (the wavefom has been moved to the bottom of the screen for cosmetic reasons). We still have negative voltable building up, but it’s pretty negligible now. I wonder if that -400mV is linked to the diode’s forward voltage.

    Althought the scale isn’t the same, the small ripples seem to have disappeared. This might be due to the Schottky diode capacitance (14pF), which, while low, could impact the small ripples with higher frequency. I didn’t have time to check that though.

    Now, we need to cap the maximum voltage in circuit, so we don’t fry our ADC.
    Zener diode

    As seen above, voltage range is pretty high and can climb quickly to unappropriate values for digital purposes. So wee need to tame the voltage created by the piezo. Zeners have this ability, and can limit voltage to a fixed value. Whenever voltage is higher than the Zener’s rating, the Zeners lets current flow thru and as a side effect, help maintain voltage to a fixed value.

    Piezo signal, after Schottky rectifiers and Zener

    Piezo signal, after Schottky rectifiers and Zener

    We usually have to add a resistor between the Zener and ground, so voltage builds up around it and current is limited thru the Zener. But this is not necessary with piezo, since involved currents are very very low.

    After we add a 5.1v Zener in the circuit, the voltage read from a piezo looks like this.

    You can smash the piezo as hard as you want, you’ll never exceed the Zener’s rated voltage.

    If we just use this shape as is, we’ll have a hard time trying to guess if the piezo has been smashed or not. We have to filter those spikes to get a smoother shape.

    Filtering the signal

    This signal can be filtered by using a RC cell. Whe just need to know how long we want the shape to last. For my application (drum trigger), I want the signal to fade out in 10ms maximum. Since we know that the voltage drops to 10% of the initial voltage after t_(90%) = 2.2*R*C, we can find the right resistor knowing the capacitor value, and vice-versa.

    Let’s say we use a 1MΩ resistor, we’ll have to use a{10*10^-3}/{2.2*1*10^6} approx 4.5nF capacitor.

    So we end up with this simple little circuit :PiezoFinalCircuit

    And get this nice little shape :

    Finaly, a clean, ADC friendly signal

    Finaly, a clean, ADC friendly signal

    Hope this can help you using those pesky beasts. Be warned that piezo are all differents, and that size matters… So experiment with that before engraving the above stuff in copper.

     

    34 réponses à “Piezo transducer signal conditioning” Icône RSS

    • excellent ! thank you very much for this information. i found your post after looking on the v-usb forum:
      http://forums.obdev.at/viewtopic.php?f=8&t=1352&start=30#p11080

      my question is about the second circuit mentioned in the post:
      http://ispf.de/modules.php?name=News&file=article&sid=6&page=1

      C1 holds the voltage pretty long and gets deloaded after a succesfull measurement by pulling the appropriate pin to low.

      is this really required for an electronic drum?

      my other question (merci pour ton temps):

      your RC is for 10ms, why did you choose 10ms and not let’s say 1ms?

      pat

    • Hey Patrick,

      Thanks for tour comment.

      C1 holds the voltage pretty long and gets deloaded after a succesfull measurement by pulling the appropriate pin to low.
      is this really required for an electronic drum?

      Well, the idea is interesting. But you’d have to be careful : piezo voltage spikes can go pretty high, and nothing in the circuit shown limits voltage (no zener for instance). So the µ pin can suffer from it.
      Also, I don’t think it helps in getting a meaningful value into the ADC, since piezo outputs are pretty wild and unpredictable. Yiou can smash it softly and yet get a good short spike, and smash it hard and get lower spikes for a longer time. Reading voltage alone wont help in guessing the smash velocity.

      your RC is for 10ms, why did you choose 10ms and not let’s say 1ms?

      Well, the point is to be able to do some measurements on the signal as long as possible. I used the 10ms limit to avoid noticeable lag. May be it’s too high and can be shortened.

      The best is to try as much as possible, and hook an oscilloscope to the circuit and see what happens I’m not an EE, so, you’d better check twice what I say ;)

      Good luck with your project.

    • Hi Leucos,

      Again thank you! About the RC value, is there a reason for choosing 1M resistor? For my design, i used 10k resistor + 0.1uf capacitor and i am wondering if it\’s a \"smart combo\"? Maybe it\’s better to have bigger resistance and less capacitance?

      pat

    • Salut leucos,

      I just wanted to get around to thank you for your in depth description of yours here.

      When thinking about it. Leucos you did a mistake with your 10ms. 10^-3 = 0,001 which is 1ms not 10!

      @patrick
      If you have a piezo element which produces significant less voltage (like me) you have to have a high resistor to not let it suck almost the whole signal from the ADC. Therefor the cap becomes smaller (at a given time).

      greetings K-Duke

    • @K-Duke
      Thanks for passing by K. I’m sorry but I can not see my mistake on the page. I must be blind !

      @patrick
      I prefer a higher resistor value to have a high impedance input on the ADC. Again, this is mostly empiric, and tests showed better results with this values.

    • Oops sorry. Actually I misread your formular. Thought you had 1 * 10^-3 there though you got 10 * 10^-3. Sorry for confusing you -.-

    • No problem K-Duke ! Thanks for proof-reading !

    • I am using 44 mm diameter piezo. When using a 10k resistor + 0.1uf capacitor the maximum voltage when striking the piezo is around 3v. I was happy with this result, because i’m not using a 5.1v zener diode to limit the voltage. Instead, i am using a op-amp to boost / limit the voltage.

      BUT, i think my RC is not well suited for an electronic drum, the fact that i’m using a bigger capacitor seem to cause a problem (not detecting all the hits). So i tried your 1M + 4n7 and it’s more sensible (soft hits are detected + all the hits are detected).

      QUESTION, since your RC is much more sensible (the voltage can go up to 15v without a zener diode) would it be a good idea to use a voltage divider to bring the voltage down under 5v? using a potentiometer for the voltage divider, it will be possible to adjust the sensibility of the piezo?

      /me trying to find _THE_ best solution

    • hi,

      here’s my final circuit:
      http://imagebin.ca/view/VoCkp1.html

      i am using a voltage divider before filtering the piezo. this bring the voltage to 0v – 5v (approx). to be sure not to exceed 5v, i am using a zener diode.

      cheers!

    • Hi Patrick,

      Sorry for the delay, and thanks for your schematic. What the idea behind using a voltage divider ? Since you have a zener, and since this setup will decrease C charge, is there any interest in doing it this way ?

    • Hello Leucos,

      I am not sure about the voltage divider. The idea was to scale down the voltage to 5 volts (without the voltage divider it was around 50 volts) instead of just omitting anything above 5 volts.

      A new proposition:
      http://imagebin.ca/view/6_-R02bH.html

      This time with a trim pot to adjust the sensibility of the pad. Does it make any sense?

    • Patrick,

      In your schematic, you’re not voltage dividing : the wire to the lower BAT85 schottky should be plugged between the 10k and the trim to be effective.
      About making sense, I’m not sure. But with piezos, there is sometimes surprises between the drawing board and the field. You really should try it out in real life so you can juge by yourself if your setup yields any improvment.

    • Hi.
      I’m newbie in electrical material, and I don’t speak English as I speak Spanish, so please forgive me if I made a mistake writing this.
      Well, I found your post and I think that it’s exactly what I need (I’m working with arduino + piezos), but if I go to the electronics store and I ask for « Two BAT85 Schottky Diodes », « 1 Zener Diode 5.1v » and « one 4n7 capacitor » probably salers will make some technical questions that I couldn’t answer.
      So may I ask you to tell me please the exact specs for diodes (1 Zener diode,2 schottky diodes?) and the « 4n7″ (capacitor?), the other elements (piezo,resistor,etc.) aren’t problem.
      I’ve tried software tricks (reading by count or elapsed time + signal thresholds) but I think that your solution should be better.

      Thanks in advance.

    • Hey Fernando,

      For the BAT85 : Schottky *is* the spec. Schottky diodes are special diode with a low forward voltage drop. So you could ask « a diode with a low Vf », but you’d better ask for a « schottky diode ».
      For the Zener : the spec here is the voltage, 5.1 V. The other parameters aren’t that important.
      For the capacitor : 4n7 means « 4.7 nano Farads ». So just ask for a « cuatro nano siete » and it should do the trick ;)

      glhf,

    • Thanks for the fast answer Leucos.
      And by the way, my world is the software and in the last time i have working hard on vst’s and midi software, sequencers, etc., and i’ve hacked a gamepad (wheel) to build a midi floorboard and the sustain pedal for my keyboard, and now i’m programming the arduino to get the piezo signals to finally build the drum and perform a vst like addictive drums. My next project will be to build a breath controller (maybe hacking a broken clarinet). In the music world i play guitar and keyboard, but we (almost a band) need the drum, so with your work we are closer to get it.
      I know that i’m still a newbie in the hardware world but maybe i can help in some way to thank you, so any doubt just let me know.
      Thanks again.

    • @Fernando : check out http://drummaster.digitalcave.ca/index.jsp
      There are loads of informations there to build an electronic drum.

    • Hello,

      You say this circuit acts as an RC filter, but looking at http://en.wikipedia.org/wiki/Rc_circuit
      isn’t the R and C suppose to be connected in Series ?
      whereas in your schematic they are connected in parallel ?

    • Hey Gal,

      Please scroll down on the wikipedia page ;)

    • thank you very much. It has usefully for me.

    • Hi,

      I did scroll down to the wikipedia page …
      There they mention the *Parallel* RC circuit that
      you are using.

      It says : \"The parallel RC circuit is generally of less interest than the series circuit. This is largely because the output voltage Vout is equal to the input voltage Vin — as a result, this circuit does not act as a filter on the input signal unless fed by a current source.\"

      Here, in all your scope captures, you talk of voltage, and not current, so I don\’t understand..

    • @gal : the point here is to remove voltage swinging. When you smash a piezo, you have a lot of spikes going up and down.

      Having R & C in // will dampend « down voltage spikes ».

      Imagine you have a high voltage spike. The cap will charge instantly and Vo will be as high as Vi (Vo and Vi used here are according to the wikipedia schematic).
      Now when Vi drops to 0, the cap is still charged and will « slowly » discharge thru R.

      All in all, Vo will rise exactly like Vi, but will fall slowly (according to the RC constant).

      You can test this at http://www.falstad.com/circuit/

      Create a circuit with a R, C, voltage source and a switch and test it out.

    • Hi Leucos,

      thanks for sharing your work!

      I have a more general question regarding piezos, as I am currently starting work here and am mch more aware of soft- than of hardware.
      So: Is it possible to distingish between pressing an d depressing the piezo? Will that give any different output using your circuit?
      In the situation I am using the piezo in, it will be pressed and after a longer time, it will be depressed.

      Sadly I do not have an oscilloscaope available so it woud be nice if you could help

    • This is a very nice article, but i have done some playing with piezos and i have to say it is not that simple. I want to put a piezo in a box and hitting the box will trigger some event. The box is 16mm woods. SO, the voltage spiked from a hit is about 100-200mV only. But you hit it really hard then you’ll get around 10V. I need to detect both types of hits (not distinguish, just detect, they are all the same to me). The problem here is the diode. With only 200mV spike the diode will not let it through. So, i need to amplify it first! A simple NPN transistor might help, do you think? So, when the signal from the piezo will go to the base the output voltage with like 100x more (i’ll take a trans with gain of around 100) but not more than the Vcc. Fo example, 50mV from piezo will result in 5V output (Vcc). However, I, again, don’t know what to do with +10-20V on the base from the piezo? Allowed max Base-emitter voltage is usually around 6V. Put a zenner to the base? Then what will happen to it on negative voltage it? It will conduct and we’ll have a short cicuit. Any ideas?

    • Hi Leucos, it’s me again.
      Your sketch gives 5v in the output and in my project with arduino over the 6 analog inputs it works like a charm. But now i get a mux that needs -0.5v to 0.5v, and at the moment it gives me signals on wrong inputs (the highs in the right , so could you please help me again to get this 0.5v ?. I’ve tried putting resistors but it doesn’t work.
      Thanks in advance.

    • Hi Leucos, it\’s me again.
      Your sketch gives 5v in the output and in my project with arduino over the 6 analog inputs it works like a charm. But now i get a mux that needs -0.5v to 0.5v, and at the moment it gives me signals on wrong inputs (the highs in the right , so could you please help me again to get this 0.5v ?. I\’ve tried putting resistors but it doesn\’t work.
      Thanks in advance.

    • Hi, just wondering what scope software did you use to make the screenshots?

      Thank you!

    • Hi Leucos

      Thanks for the really clear instructions and explanations. I have built the circuit you describe, and it yields much better results than previous attempts (i’m using Doepfer PE – http://www.doepfer.de/pe.htm to convert piezo transients into midi) but it is still only registering some strikes/hits of my drum triggers.

      i’ve tried using better piezos hoping they’d be more sensitive, but no luck.

      Any suggestions?
      Regards
      Joel

    • I think the circuit will function lot better when the first Bat85 get replaced with a short circuit. The second Bat85 across the input is enough to get the signal conditioned.

      I don’t see the purpose of the first Schottky, remember we can either have a full wave rectification or half wave. There is nothing such as « Half Bridge ».

    • First off thanks for the great article. I have a question:
      I’m not getting an adequate voltage reading off of the piezo circuit to trigger my microcontroller’s (digital) input. I’m using an Arduino Uno and trying to use piezo sensors as simple, non-velocity-sensitive, drum triggers, so i can have up to 13 of them.

      1.i’m not using capacitors in my circuit, could this be a serious issue in if im not hoping to get velocity data

      2. could i use a transistor to boost the signal, and any suggestions on where to start with that process/ballpark estimates for values?(sorry im a bit of a nube when it comes to electronics, im just getting started)
      Thanks,
      Tom

    • First off thanks for the great article. I have a question:
      I\’m not getting an adequate voltage reading off of the piezo circuit to trigger my microcontroller\’s (digital) input. I\’m using an Arduino Uno and trying to use piezo sensors as simple, non-velocity-sensitive, drum triggers, so i can have up to 13 of them.

      1.i\’m not using capacitors in my circuit, could this be a serious issue in if im not hoping to get velocity data

      2. could i use a transistor to boost the signal, and any suggestions on where to start with that process/ballpark estimates for values?(sorry im a bit of a nube when it comes to electronics, im just getting started)
      Thanks,
      Tom

    • Thank you very much for what has to be one of the best walk-through tutorials on the subject anywhere on the net!

      I’m wanting to drive a piezoelectric diaphragm from a MCU GPIO – and equally protect the MCU from any shock-induced transients from the piezo. After roughly modelling it in LTspice, I think all that’s needed are the zener and schottkey diodes – both between earth and line. Any thoughts?

      Hamish

    • Hi Hamish

      If you omit the cap, you’ll probably have spikes ranging between the zener breakout value and ground. It all depends on what you want in the end but yes, it shouldn’t harm.

    • Tom,

      Sorry for the delay, it seems I don’t get emails anymore when comments are posted.

      It’s wierd you’re not triggered. Are you using interrupts or just reading with digitalRead ? In the latter case may be you’re not fast enough.

      1/ If you don’t use a cap, you’ll get a shaky signal between your zener breakout voltage and ground, and if you read with digitalRead you might miss the « HIGH » ctransient condition.

      2/ You probably should use a FET, which is voltage trigerred. You probably won’t get enough current from the piezo to drive a transistor.

      Bye,

      M

    • Hi Artem,

      Sorry for the delay !!

      You might want to check out http://drummaster.digitalcave.ca/schematics.jsp
      He’s doing a real good job in getting a clean & amplified piezo signal.

      M


    3 Trackbacks / Pingbacks

    Laisser une réponse

    Security Code: