Scale down a +/-25V analog signal, but with only 5V power? - Page 1
Forum section: electronics / beginners

author: Saimoun
author_rank: Frequent Contributor
timestamp: June 22, 2021, 09:54:09 am
content: Hi allI have been asking before (seehttps://www.eevblog.com/forum/beginners/use-tvs-diode-to-clamp-analog-voltage/) about how to clamp an analog voltage and with your very appreciated help, I ended up with the following circuit (attached).The analog voltage source is a piezo sensor (a drum pad which is hit) which I have not much control over. Hitting is softly generates a pulse with low voltage, and trying with a few sensors it seems hitting it hard can make the pulse go to 50Vpp.Inside the MCU I want to be able to make the difference between a soft hit and a hard hit, for now I am using:1) a comparator to check if the voltage is above 0.6V2) the ADC to check if the voltage reaches 3.3VIf 1) is activated I know there is a hit, and then 2) decides whether the hit is soft or strong.This works fine in theory, and in practice it is actually decent but because the range is so little compated to the 50Vpp of the sensor, you have to hit the pad very softly to make sure the hit is not detected as "strong". In other words, trying to tap a rythm, like "H S S S H S S S H" (H=hard hit, S=soft hit), it is quite easy to make the soft hits just a bit too strong and then they are detected as hard hits.So I was thinking - to improve the sensitivity I need to scale (with an opamp f.x.?) the analog input from 50Vpp to like 5Vpp - but my whole board runs at 3.3V, from an LDO converting USB 5V. I guess an opamp with rails at 0V and 5V would not like very much a signal that is 50Vpp?What do you guys think, do you maybe have other ideas on how to detect the soft and hard hits (ideally without too much extra hardware on the board)?Thank you!!Simon

author: Kleinstein
author_rank: Super Contributor
timestamp: June 22, 2021, 10:58:04 am
content: With a capacitive signal source one can use a capacitive divider: just add a capacitor (e.g. 10 nF range) in parallel to the piezo. How much depends on the piezo capacitance. This will however also slow down the decay. Depending on the sensor one may want a high values resistor parallel to the sensor to get a defiend DC level in a more defined time.For the protection part one ideally would have an additional resistor just before the ADC input of the µC.As shown the extra diodes for clamping are in parallel to the µC internal diodes - so if the internal diodes have lower forward votlage they would still take most of the hit.

author: tooki
author_rank: Super Contributor
timestamp: June 22, 2021, 04:09:26 pm
content: Quote from: Kleinstein on June 22, 2021, 10:58:04 amIn parallel? A capacitive divider is just like a voltage divider: two caps in series, and the output is the center.

author: magic
author_rank: Super Contributor
timestamp: June 22, 2021, 05:36:55 pm
content: Draw a schematic of your series version and explain how it works

author: Zero999
author_rank: Super Contributor
timestamp: June 22, 2021, 05:53:12 pm
content: Quote from: tooki on June 22, 2021, 04:09:26 pmThe idea is to use the piezo's capacitance as one of the impedances in the divider.Why not just use a resistive divider?Bias the ADC input to half the supply voltage, with a potential divider and connect it to the piezo, via a suitable resistor, which will reduce the voltage further.An op-amp buffer might be still needed to reduce the impedance seen by the ADC pin.

author: Saimoun
author_rank: Frequent Contributor
timestamp: June 23, 2021, 07:12:32 am
content: Thank you all for the replies!!@Zero999: this is super interesting, I did not think about using a simple voltage divider! I am a bit confused though how you could get *exactly* 3.3Vpp on the output...But it doesn't matter I get the idea.I am not really interested in centering the voltage, I can just clip the bottom part of the pulse (code-wise it is easier if the resting voltage is 0V). So all I need are two resistors to divide the voltage, or maybe even one since the piezo already has a high impedance.The MCU actually has an internal pull-down resistor which can be set to 400k or 10k. Unfortunately I cannot use these as resistor divider since the voltage would be clamped by the diodes *before* it would be divided by the voltage divider.@Kleinstein: I would love to hear more about that - I cannot really see how it works thoughJust FYI the pulse is about 300Hz and last about 30ms - see image here:https://www.eevblog.com/forum/beginners/analog-signal-50vpp-into-3-3v-mcu/For the protection diodes you are right, but these diodes are only here because the MCU does not have an internal diode to VDD. The current should not be a problem since the piezo already has a very high impedance (40k'ish) and there is the extra 1.8k resistor before.

author: Zero999
author_rank: Super Contributor
timestamp: June 23, 2021, 10:59:34 am
content: Quote from: simonlasnier on June 23, 2021, 07:12:32 amR1 = R2, so the voltage on U1's input will be half the supply voltage.C1 blocks any DC path on the input. It probably isn't necessary, as the piezo will have a high DC impedance, but some manufacturers recommend not biasing it as DC, which is why included it.R1 and R2 from the lower part of a potential divider, with R3 being the upper part. The supply voltage has a low impedance, so the values of R1 and R2 are in parallel, as far as the signal is concerned.Put that into the potential divider formula and we get:Vout = (Vin*R1||R2)/(R3+R1||R2)R1||R2 = 51k/2 = 25.5kVout = (25*25.5k)/(360k+25.5k)Vout = 637.5/385.5 = 1.65VBecause the peak AC signal voltage is 1.65V and the DC bias is 1.65V, the output will swing between 0V and 3.3V.QuoteYes, you can use that resistor. Move D8 to D9's position and get rid of D9. Increase R23 to get the correct divider ratio, depending on the required ratio and the value of R24. Now the voltage at the MCU's input will be clamped to 3.3V, not the input to the potential divider.Here's some websites which can help you calculate potential dividers.https://www.random-science-tools.com/electronics/divider.htmhttps://jansson.us/resistors.html

author: tooki
author_rank: Super Contributor
timestamp: June 23, 2021, 12:37:21 pm
content: Quote from: magic on June 22, 2021, 05:36:55 pm”my” series “version”? Google “capacitive divider” and you’ll find it. Looks just like a resistive voltage divider, but with caps instead of resistors. It’s a standard thing, not an invention of mine.

author: tooki
author_rank: Super Contributor
timestamp: June 23, 2021, 12:38:52 pm
content: Quote from: Zero999 on June 22, 2021, 05:53:12 pmSure. But that wouldn’t be putting a cap in parallel with it, it’d put it in series.

author: Zero999
author_rank: Super Contributor
timestamp: June 23, 2021, 01:52:12 pm
content: Quote from: tooki on June 23, 2021, 12:38:52 pmThat's subjective.

author: Saimoun
author_rank: Frequent Contributor
timestamp: June 23, 2021, 02:35:33 pm
content: Quote from: Zero999 on June 23, 2021, 10:59:34 amHa this is the part I missed (R1 also being part of the divider), it makes perfectly sense now thank youQuote from: Zero999 on June 23, 2021, 10:59:34 amYes thank you that would work you are right - but then what about the ESD protection?(... I actually started this message about 2 hours ago, then experimented in LTSpice since and found out the following...)I made the math and actually simply changing the internal resistor (R24) from 400k to 10k does what I need!! Hurra - no hardware change neededThat attenuates the signal already by a lot, since the piezo has a high output impedance.See the attached schematics. I could have R2 of about 15k, then the "top" of my range is the 50Vpp, but actually even with R2=0, the range expanded to about 36Vpp (i.e. you need to hit hard enough to generate 36Vpp for the hit to be detected as "hard").I will test this in real life and see how it works

author: Zero999
author_rank: Super Contributor
timestamp: June 23, 2021, 03:52:12 pm
content: Quote from: simonlasnier on June 23, 2021, 02:35:33 pmVia the suppression diode.QuoteBe careful, LTSpice assumes voltage sources are a low impedance at all frequencies. In reality, your piezo transducer will be open circuit, at DC.And I don't see why you're using both a comparator, as well as an ADC? Normally you use one or the other.

author: tooki
author_rank: Super Contributor
timestamp: June 23, 2021, 05:11:43 pm
content: Quote from: Zero999 on June 23, 2021, 01:52:12 pmOhhh, ok, that makes sense now. Thanks for spelling it out for me!

author: Saimoun
author_rank: Frequent Contributor
timestamp: June 25, 2021, 11:51:28 am
content: Quote from: Zero999 on June 23, 2021, 03:52:12 pmOk that makes sense - also after a 150k resistor clearly there is no much current left so I think ESD is not an issue anymoreFor other reasons (mainly because I am using the same input for other purposes), I decided to use the piezo impedance as voltage divider, with the internal 10k pull-down. I tested in practice now, and it works beautifully - the solution was so simple ha haI also experimented a bit by adding an extra capacitor to GND (C1), just after the 1.8k resistor, like some of you guys suggested! That also works very well and reduces the range even more. But I still want to be able to reach the "strong" hit (i.e. to create the 50Vpp you need to hit really hard) so I do not think that is necessary.With C1=0, I need an input pulse of about 2x17.5Vpp to reach the threshold of 3.3V. With C1=68n, I need about 2x23Vpp to reach the threshold of 3.3V.In any case - thank you all for the very helpful answers, as usual! See you for my next question

author: redben
author_rank: Contributor
timestamp: June 25, 2021, 12:37:10 pm
content: This thread is so informative ! I would never have thought that resistors inside the MCU might be used this way.