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

    Posté le 6th juin 2009 leucos 22 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.

     

    22 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


    Laisser une réponse

    Security Code: