Why am I getting an incorrect voltage from my level shifting circuit? - Page 1
Forum section: electronics / beginners

author: Starlord
author_rank: Frequent Contributor
timestamp: November 30, 2016, 06:19:40 pm
content: When I probe the junction of R6 + R7 (voltage divider 5V->3.4V) while no MicroSD card is inserted, instead of seeing the expected 3.3V, I see 1.75V on my scope.What gives? R4 should pull MISO up to 5V, and R6 and R7 should reduce it to 3.4V.I did this to protect the MicroSD card from 5V logic on the ISP header it is also connected to, as well as accidentally setting the MISO pin high in code. And if MISO were set low, I would expect to see 0V on my probe point, but 1.75V makes no sense.Also, I should probably mention that when the card is sending data to the microcontroller, the circuit shouldn't affect it beyond the pull up being there for when that pin on the MicroSD is in open drain mode during startup.

author: Starlord
author_rank: Frequent Contributor
timestamp: November 30, 2016, 06:58:23 pm
content: To add another piece to the puzzle, I've tested with the MicroSD card attached, and the probe point still sits at 1.75V initially, but after around 200ms it jumps up to 3.3V. I'm guessing this is the card exiting the open drain mode on the MISO line. Also, after my firmware fails to talk to the card (I am also probing the clock line) the MISO line goes to 0V. Which again, I assume is the work of the card.But when the card isn't attached, the MISO line never changes from 1.75V.

author: madires
author_rank: Super Contributor
timestamp: November 30, 2016, 07:25:08 pm
content: Voltage dividers are very poor level shifters, because the load will change the divider's voltage.

author: Zero999
author_rank: Super Contributor
timestamp: November 30, 2016, 07:30:16 pm
content: Whare did you get 3.3V from? Show your working.The voltage across R6 with nothing connected to it will be 0.436V1000*5/(10000+470+1000) = 0.436V.

author: Starlord
author_rank: Frequent Contributor
timestamp: November 30, 2016, 07:50:38 pm
content: I get the 3.3V supply from a TLV702 with 1uF ceramic caps on the input and output.http://www.ti.com/product/TLV702

author: Monkeh
author_rank: Super Contributor
timestamp: November 30, 2016, 07:56:29 pm
content: Quote from: Starlord on November 30, 2016, 07:50:38 pmHe means your divider output. Think about what the 10k is doing. Quite where 1.75V comes from.. you might have to show the whole problem.

author: Starlord
author_rank: Frequent Contributor
timestamp: November 30, 2016, 08:05:24 pm
content: > Whare did you get 3.3V from? Show your working.Oh, I think I misunderstood, you wanted me to show how I came to the conclusion that MISO should be pulled up to 3.4V.> The voltage across R6 with nothing connected to it will be 0.436V> 1000*5/(10000+470+1000) = 0.436V.I don't understand your math. I used this tool to calculate the values I needed for the voltage divider:http://www.raltron.com/cust/tools/voltage_divider.aspAlso I'm pretty sure I simulated this a couple times before I created the circuit, but now I'm questioning what I've done.Anyway, if you plug in 5V on the input, 470 and 1K for the resistors, you get 3.4V on the output.So I put a 10K pullup on the 5V side to pull that up to 5V...But I'm thinking I screwed up in my thinking here. I failed to account for the 470 + 1K path to ground.So if I use that calculator and put in 5V, 10K for R1 and 1470 for R2... I think that will tell me what the voltage seen by the microcontroller will be when the open/drain output of the MicroSD card is open. And that would be 0.641V... not the 5V I was thinking.

author: suicidaleggroll
author_rank: Super Contributor
timestamp: November 30, 2016, 08:07:04 pm
content: Quote from: Starlord on November 30, 2016, 06:19:40 pmThat's your problem. How/why would R4 pull MISO up to 5V when an even stronger resistance (R6+R7) is trying to pull it to Gnd?

author: Monkeh
author_rank: Super Contributor
timestamp: November 30, 2016, 08:22:05 pm
content: Quote from: Starlord on November 30, 2016, 08:05:24 pmThat tool assumes your input voltage has no impedance. This is never the case, but it's more than close enough normally. However.. your source impedance isn't 0. Nowhere even remotely close. It's 10k ohms.QuoteNo, you failed to account for the exact opposite side of the problem.

author: Starlord
author_rank: Frequent Contributor
timestamp: November 30, 2016, 09:24:57 pm
content: Do you have any suggestions how I could fix this, given I have already had the PCB manufactured?I would prefer for the card to continue to be protected from 5V on the MISO line from the microcontroller side. However, if this is not possible it's not the end of the world, I will just have to make sure to take the card out when I am using the ISP header.But I can't simply remove R6 because then I would also have to remove R4. I can't have a 5V pull up on the MISO line. The card may have over voltage protection diodes in it that can handle small currents, but I don't know if I can count on those.I could change the values of R6 + R7, but I don't know how large R7 can be before it will impact the max bus speed, and I need that to stay 8MHz.

author: rstofer
author_rank: Super Contributor
timestamp: November 30, 2016, 09:47:25 pm
content: The voltage divider is (5.0 / (R4 + R6 + R7)) * R4 or 5.0 / 11470 * 1000 or 0.43V - no signal appliedIf 5.0V is stuffed into MISO, the divider is 5.0 / (R4 + R7) * R7 or 5.0 / 1470 * 1000 or 3.4VSo, while the uC is starting up, the voltage on the SD MISO line is 0.43V - I don't know if that matters.If the uC can't pull the pin to 5V, the input voltage to the card will suffer.

author: Starlord
author_rank: Frequent Contributor
timestamp: December 01, 2016, 07:36:59 am
content: Well after getting some sleep, I guess the easiest solution to my problem without spinning up a new PCB or resorting to bodge wires may be to replace R6 with a 20K resistor.I would lose the level translation from the 5V side to 3.3V, so the card would not be protected when I am programming the board via the ISP header, or from accidentally setting MISO high, but that isn't a big deal.I think I won't even need to remove the 470 ohm resistor on R7.I still don't understand where the 1.75V is coming from though. A voltage divider with 5V passing through 10470 ohms of resistance, and a 1K resistor pulling to ground should give 0.436V at the junction of the two resistors.

author: Zero999
author_rank: Super Contributor
timestamp: December 01, 2016, 12:32:09 pm
content: Quote from: Starlord on December 01, 2016, 07:36:59 amYes, we tried to tell you that.QuotePerhaps something on SD_MISO is pulling it up slightly?By the way, there should be no need for potential dividers for over voltage protection, as most ICs have ESD diodes to either supply rail. All that's needed is a series resistor to limit the current through the diodes to a safe level: normally under 2mA.

author: Starlord
author_rank: Frequent Contributor
timestamp: December 01, 2016, 02:31:15 pm
content: Quote from: Hero999 on December 01, 2016, 12:32:09 pmThere's nothing that could be, as far as I can tell.The only things connected to the circuit when I am doing the measurement is the Microcontroller and the 10x probe. The 1.75V appears even when there is no MicroSD in the slot, so even if that could be the cause, it's not. And if the microcontroller pin were high, I would be reading 3.4V. And if the internal 100-200K pullup were enabled that would hardly have an effect.The schematic I posted is all that is connected. There is an ISP header in the middle that isn't shown, but it is not connected to anything when I am doing the measurements.But I'll do some more probing with my scope and see what voltages I get at various locations.

author: Starlord
author_rank: Frequent Contributor
timestamp: December 01, 2016, 07:05:59 pm
content: So probing the resistors:I get 5V on the 5V rail, 2.5V at the junction of R4 and R7, 1.75V at the junction of R7 and R6, and 0V at GND.And I have no idea why, because if I use this voltage divider calculator:http://www.raltron.com/cust/tools/voltage_divider.aspAnd I input 5V VIN, 10470 for R1, and 1000 for R2, I get .436VIf I input 10000 for R1 and 1470 for R2, I get .641VNeither of which match my results at those probe points. Am I doing something wrong here? I mean I know this isn't really the right way of going about calculating this stuff but that's a voltage divider there, right? Regardless of whether I am taking into account a couple of the resistors being in series depending on where I probe. So why am I getting weird results?

author: Starlord
author_rank: Frequent Contributor
timestamp: December 01, 2016, 07:23:57 pm
content: Quote from: Hero999 on December 01, 2016, 12:32:09 pmHm... if that's the case then perhaps I could get away with simply removing R6? The 5V pullup is 10K, and I'm guessing to calculate the current I should use the voltage above the MicroSD supply rail? So 5V-3.3V = 1.7V. And 1.7V / 10K = 0.00017A. I guess I'll try that and see what happens.

author: Starlord
author_rank: Frequent Contributor
timestamp: December 01, 2016, 07:51:43 pm
content: Well I tried removing R6 and now I'm more confused than ever.Now when I probe between R4 and R7, or R4 and R6, I read 2.5V.And the 5V side of R7 is still 5V as it should be.So how can I be reading 2.5V? Well it may be closer to 2.75V but it's hard to tell on the scope. But either way... this is impossible!I have no card inserted.If I had accidentally set the pin low, it would overpower the 10K pull up and read 0V.If I had accidentally enabled the internal pull up, it should read 5V.And I could not have accidentally enabled an internal pull down because an ATMEGA doesn't have them!

author: Zero999
author_rank: Super Contributor
timestamp: December 02, 2016, 11:36:13 am
content: Why are you using an oscilloscope for static voltage measurements? Use a multimeter instead. It's far more accurate.Is there anything else connected to SD_MISO which is not shown in the schematic?Are you sure the resistors are the values you think they are?

author: Starlord
author_rank: Frequent Contributor
timestamp: December 02, 2016, 01:08:30 pm
content: Quote from: Hero999 on December 02, 2016, 11:36:13 amI may be able to get a precise reading, but I would hope that a $20 Radio Shack multimeter is not more accurate than a $400 Rigol scope!And I don't need a precise reading to tell that something is seriously wrong. But I do need more practice with my scope!QuoteOnly the microcontroller and the ISP header. And nothing is attached to the header.QuoteWTF? R4 is reading 129 ohms!But I just checked five more of these boards and R4 is 10K as it should be. Which makes no sense as these boards were all assembled by machine. (The resistors are 0402 so there are no markings on them to tell me what values they are.) I suppose I might have gotten unlucky and picked the one board that had some rework done on it after that resistor fell off during reflow? (I don't actually know that any boards had rework done on them, I am merely speculating.)I guess there is a slight chance I damaged the resistor while removing R6, but R6 and R4 are separated by R7 on the board. They're laid out side by side. So I don't think I could have damaged it with heat, and I cleaned the board up with alcohol and I don't see any damage to it, and it's measuring the same 129 ohms after I cleaned the flux off.And I still don't understand what's going on. R7 is 470 but I removed R6, so there is no longer a path to ground. So why am I reading 2.5V when I probe a 129 ohm resistor connected to a 5V supply?Using the voltage divider calculator, if I assumed there were a short across R6 so I had 470 ohms to ground, I should get 3.9V there. So that's not the culprit. Hell, I don't even need the voltage divider calculator to know that I would need another 129 ohm resistor to ground to get 5V down to 2.5V. But there isn't one! This is really weird.Anyhow, I should probably run all my tests again on one of the boards with the correct 10K resistor on R4 and see what results I get. Perhaps my MicroSD cards will just start working again.

author: Zero999
author_rank: Super Contributor
timestamp: December 02, 2016, 01:36:20 pm
content: Quote from: Starlord on December 02, 2016, 01:08:30 pmWhat makes you think price is an indicator of accuracy? Unless you spend a lot, an oscilloscope will only have an 8-bit ADC, which is only 256 counts and even a cheap meter will have +/-2000 counts.QuoteI agree.QuoteCould it be possible that there's an error on the PCB?Have you tried assembling the bit that's causing the problem on a prototyping board?

author: Starlord
author_rank: Frequent Contributor
timestamp: December 02, 2016, 01:59:01 pm
content: Quote from: Hero999 on December 02, 2016, 01:36:20 pmPrecision != accuracy. You can have a 12-bit ADC that is more precise, but still less accurate than an 8-bit ADC. If the Radio Shack meter is out of whack because it's 15-20 years old or because it was never well calibrated in the first place, it will still be precise, but not accurate. At least that's how my theory goes. I have no idea of the real world accuracy of your average multimeter vs your average scope, but price does generally coincide with the quality of a tool.QuoteI suppose it's possible there could be a short somewhere. That would make two errors on one PCB though!QuoteNo. I don't really see the benefit of doing that in this case.

author: suicidaleggroll
author_rank: Super Contributor
timestamp: December 02, 2016, 02:13:50 pm
content: Quote from: Starlord on December 02, 2016, 01:59:01 pmYou're right, and the ADC in your scope (any scope) is neither accurate nor precise. Theonlything it's good at is speed. The 10 bit ADC built into a $1 MCU will be more accurate and precise than the ADC in your scope. Go to Digikey, find the cheapest multi-channel GSPS (or whatever your scope is) ADC, and check the datasheet for its DC characteristics. It will be horrible, that's not what it's built for.

author: Monkeh
author_rank: Super Contributor
timestamp: December 02, 2016, 02:33:27 pm
content: Quote from: Starlord on December 02, 2016, 01:59:01 pmHow cute.Your scope is as bad as ±4%. Your average cheap, nasty multimeter is as bad as ±0.1%.

author: Starlord
author_rank: Frequent Contributor
timestamp: December 02, 2016, 07:04:27 pm
content: Well, I'm getting around 0.5V at the junction of R6 and R7 now. Of course, that's not what I wanted, but it is what I'm supposed to be seeing there.I think I'm gonna first test my MicroSD card to see if it can be read before I remove R6. It's possible it will work despite how I've mucked things up.Doesn't work with R6 in place, except with some cards that don't even need the pull up. But does work with R6 removed. Of course I lose some of the protection from the ISP header's 5V logic, but the design functions with R7 in place and that should provide some protection should I ever screw up and have the MicroSD in while using the programming header.I suppose if I were to redesign this I would remove R6 and R7 and it would probably be a good idea to bump R4 up to 100K and/or connect it to the 3.3V supply.Actually in retrospect it might have made more sense to put a voltage divider on CS instead and run MISO through the level shifter, since CS doesn't need to support high speed data.