Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Protection circuit for Analog Pin

    Scheduled Pinned Locked Moved Discussion
    protectionanalog in3v33.3v
    13 Posts 4 Posters 1.5k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E Offline
      Eric Waai
      last edited by

      @martinnn said in Protection circuit for Analog Pin:

      Also, the ESP32 ADC seems to be the worst one in existence on this planet,

      this is absolutely true

      the impedance from this circuit is way to high.
      I don't know the input impedance from the ADC from the ESP32(somehow almost nobody knows)
      but this is probably way to high. you should add an opamp to divide the voltage.
      but if you're adding opamps already you can also add an external adc with external opamps.

      robert-hhR M E 3 Replies Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @Eric Waai
        last edited by

        @eric-waai Accordingh to my observations, the static input impedance of the ADC is pretty high, >> 10 MOhm. It's only that during sampling some charges are intaken, so a capacitor at the input helps.
        Give the initial question, -0.1V at the 3.3V pin is not aproblem. Whether the circuit is good enough for purpose, we cannot tell.
        Surely, an external op-amp for level shifting is better.
        and also, the 1N4004 could be replaced by a Mosfet transistor. Although, the small curent (~75µA) that could leak through the 40k should do no harm.

        1 Reply Last reply Reply Quote 0
        • M Offline
          Martinnn @Eric Waai
          last edited by Martinnn

          @eric-waai said in Protection circuit for Analog Pin:

          I don't know the input impedance from the ADC from the ESP32(somehow almost nobody knows)

          This is also something that's missing from the data sheet. Most nowadays' ADC (unless sigma delta) are based on capacitive DACs with a charge balancing scheme. On sampling, you need to charge the sampling capacitors (I'd guess them to be in the 10-20 pF range) to an accurate enough value. Mostly, you can select the sampling time so that you have enough RC time constants to get the necessary accuracy (assuming a resistive driving circuit). Didn't see this for ESP32.

          Another way is to add a large enough external capacitor in parallel to the input. Assuming a 10 pF sampling capacitor, adding a 10 nF capacitor means you have a 1:1000 capacity range and would expect a 1/1000 (roughly 10 bit) change by sampling. A large capacitor makes achieving a good high frequency response difficult though.

          See https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/adc.html#adc-api-adc-calibration "minimizing ADC noise"

          1 Reply Last reply Reply Quote 0
          • E Offline
            Edward Dimmack @Eric Waai
            last edited by Edward Dimmack

            @Martinnn @robert-hh @Eric-Waai Thanks everyone for your advice.

            My accuracy is not a massive concern, I only need a ball park reading and most of the time the readings will be between -2v and +1v. +/- 100mV should be fine. Anything outside that range and there is reason to be concerned.

            Protection is important though. These are going to be in a remote area and if they die then it is a massive upheaval to replace.

            So if I used an external ADC like this one
            https://www.adafruit.com/product/1085
            Can I use this with 2 differential inputs for -3V to +3V? Are there pro's and con's for doing this instead of doing with op amps?

            If so can I then just protect it from overvoltage with 2 zenner diodes? or should I do it a different way?

            Kind regards,
            Edward

            M 1 Reply Last reply Reply Quote 0
            • M Offline
              Martinnn @Edward Dimmack
              last edited by Martinnn

              @edward-dimmack As you only need ballpark readings, I don't see the benefit of using an external ADC. The differential mode does not help you as the input voltage range (datasheet: see "common mode voltage") is within the supply rails (there are only some exotic amplifiers where this is not so).
              You don't use zener diodes in input protection. They are slow, noisy and inaccurate. Just use an input series resistor and clamp to VCC/GND. What speed do you need (frequency/how many readings/s)? What is the impedance of your source - what does it look like?

              E 1 Reply Last reply Reply Quote 0
              • E Offline
                Edward Dimmack @Martinnn
                last edited by

                @martinnn

                @martinnn said in Protection circuit for Analog Pin:

                @edward-dimmack The differential mode does not help you as the input voltage range (datasheet: see "common mode voltage") is within the supply rails (there are only some exotic amplifiers where this is not so).

                I am a little confused by this. Not sure I understand what you mean but I want to use the differential input like the guy in this article does. Sorry if I don't understand. I still want it to read +/- 3V and I thought this would help. Then protection to make sure it doesn't go above +/- 5.8V.
                http://henrysbench.capnfatz.com/henrys-bench/arduino-voltage-measurements/arduino-ads1115-differential-voltmeter-tutorial/

                Just use an input series resistor and clamp to VCC/GND.

                If I do that won't it clamp at 0V and 3.3V? If I am doing the differential input option then wouldn't I need to clamp at -3V and 3V? Also couldn't that damage the FiPy on the 3.3v pin?

                What speed do you need (frequency/how many readings/s)? What is the impedance of your source - what does it look like?

                I am getting a reading of 100 samples every half hour. I am not sure of the impedance of the source and the source will change on different locations.

                M 1 Reply Last reply Reply Quote 0
                • M Offline
                  Martinnn @Edward Dimmack
                  last edited by

                  @edward-dimmack said in Protection circuit for Analog Pin:

                  http://henrysbench.capnfatz.com/henrys-bench/arduino-voltage-measurements/arduino-ads1115-differential-voltmeter-tutorial/

                  This is crap. He uses a floating source that will eventually drift inside the voltage range of the protection diodes (datasheet 9.3.1)

                  Please look at the ADS1115 datasheet: http://www.ti.com/product/ADS1115
                  7.2 absolute input voltage is between VDD and GND.

                  "differential input" means it can measure the difference between two inputs, which is very useful for many precision applications. However, both inputs have to be between VDD and GND. The DIFFERENCE can be positive or negative.

                  Just use an input series resistor and clamp to VCC/GND.

                  If I do that won't it clamp at 0V and 3.3V? If I am doing the differential input option then wouldn't I need to clamp at -3V and 3V? Also couldn't that damage the FiPy on the 3.3v pin?

                  OK, let's forget about the ADS1115 for the moment. Your original circuit was basically OK as it shifted the +-3 V input to 0-3 V at the ESP32. So a starting point would be:
                  remove the zener diode
                  remove the 1N4004
                  remove the 1 MOhm resistor
                  At the input, clamp to VCC also (add one BAT48 to 3.3 V)
                  add a 100 nF capacitor from analog input to GND

                  The schottky input clamp diodes are somewhat redundant as the ESP32 probably has those also in its pad structure, but it's good practise nonetheless. Now you should lower the resistance of the 20k divider, if possible, which brings us to...

                  What speed do you need (frequency/how many readings/s)? What is the impedance of your source - what does it look like?

                  I am getting a reading of 100 samples every half hour. I am not sure of the impedance of the source and the source will change on different locations.

                  which is not very helpful. What are you doing with the 100 readings? Are you averaging those? Are you recording them and want to show them in a scope like display (or do FFT analysis...)?
                  You need to know the source impedance or all this is moot. If you have a sensor with 100 k output resistance, obviously the 20k input divider is nonsense. If you measure the voltage of a car battery with 1 mOhm input resistance, you can make the divider obviously much lower impedance.
                  Of course you can use the ADS1115, which is probably a good idea anyway, but you have to understand the basics first.

                  E 1 Reply Last reply Reply Quote 0
                  • E Offline
                    Edward Dimmack @Martinnn
                    last edited by

                    @martinnn Thank you so much for your help.

                    That all makes much more sense to me now and the circuit with your changes works better.

                    My only remaining concern is won't it damage the FiPy on VDD when there is an over voltage?

                    The reason that I had a zener diode was so that it clamped to ground like it does in figure 13 of this article.
                    https://www.digikey.com.au/en/articles/techzone/2012/apr/protecting-inputs-in-digital-electronics

                    which is not very helpful. What are you doing with the 100 readings? Are you averaging those? Are you recording them and want to show them in a scope like display (or do FFT analysis...)?

                    Sorry, I am averaging them for 1 reading and doing that once every half hour.

                    You need to know the source impedance or all this is moot. If you have a sensor with 100 k output resistance, obviously the 20k input divider is nonsense. If you measure the voltage of a car battery with 1 mOhm input resistance, you can make the divider obviously much lower impedance.

                    I understand what you mean now. Since I won't know the source impedance can I use a trim pot in place of the two resistors and then adjust it for the application?

                    M 1 Reply Last reply Reply Quote 0
                    • M Offline
                      Martinnn @Edward Dimmack
                      last edited by

                      @edward-dimmack said in Protection circuit for Analog Pin:

                      I understand what you mean now. Since I won't know the source impedance can I use a trim pot in place of the two resistors and then adjust it for the application?

                      How exactly so you suppose this to function?

                      My only remaining concern is won't it damage the FiPy on VDD when there is an over voltage?

                      The reason that I had a zener diode was so that it clamped to ground like it does in figure 13 of this article.
                      https://www.digikey.com.au/en/articles/techzone/2012/apr/protecting-inputs-in-digital-electronics

                      This is a digital input, not an analog one. Re-read what I wrote about input protection. How much current flows into the input? Draw a schematic including the input protection as in the article you are referring to (hint: Figure 6).

                      1 Reply Last reply Reply Quote 0
                      • E Offline
                        Edward Dimmack
                        last edited by Edward Dimmack

                        @martinnn said in Protection circuit for Analog Pin:

                        How exactly do you suppose this to function?

                        This is what I put into a online simulator. If I change the impedance on the right then I can adjust the trim pot and it changes the working range.

                        0_1551398011776_c8ac1f5a-9119-49ea-a614-6e56c948f1a1-image.png

                        This is a digital input, not an analog one. Re-read what I wrote about input protection. How much current flows into the input? Draw a schematic including the input protection as in the article you are referring to (hint: Figure 6).

                        Do you mean what you wrote when you said to use an input series resistor. Is the circuit above what you meant?

                        EDIT: I have since found out that the impedance will be minimal. It is just the resistance of a short cable. So less than 1 ohm. Also this device will go into deep sleep in which case there will still be the analog but no power to the FiPy. Won't this then apply a voltage to VDD?

                        1 Reply Last reply Reply Quote 0

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • 1 / 1
                        • First post
                          Last post

                        Pycom on Twitter

                        Pycom