Author Topic: Why am I getting an incorrect voltage from my level shifting circuit?  (Read 6375 times)

0 Members and 1 Guest are viewing this topic.

Offline StarlordTopic starter

  • Frequent Contributor
  • **
  • Posts: 325
  • Country: us


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.

 

Offline StarlordTopic starter

  • Frequent Contributor
  • **
  • Posts: 325
  • Country: us
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #1 on: November 30, 2016, 06:58:23 pm »
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. 
 

Offline madires

  • Super Contributor
  • ***
  • Posts: 8177
  • Country: de
  • A qualified hobbyist ;)
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #2 on: November 30, 2016, 07:25:08 pm »
Voltage dividers are very poor level shifters, because the load will change the divider's voltage.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19990
  • Country: gb
  • 0999
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #3 on: November 30, 2016, 07:30:16 pm »
Whare did you get 3.3V from? Show your working.

The voltage across R6 with nothing connected to it will be 0.436V

1000*5/(10000+470+1000) = 0.436V.
 

Offline StarlordTopic starter

  • Frequent Contributor
  • **
  • Posts: 325
  • Country: us
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #4 on: November 30, 2016, 07:50:38 pm »
I get the 3.3V supply from a TLV702 with 1uF ceramic caps on the input and output.

http://www.ti.com/product/TLV702
 

Offline Monkeh

  • Super Contributor
  • ***
  • Posts: 8068
  • Country: gb
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #5 on: November 30, 2016, 07:56:29 pm »
I get the 3.3V supply from a TLV702 with 1uF ceramic caps on the input and output.

http://www.ti.com/product/TLV702

He 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.
 

Offline StarlordTopic starter

  • Frequent Contributor
  • **
  • Posts: 325
  • Country: us
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #6 on: November 30, 2016, 08:05:24 pm »
> 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.asp

Also 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.
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #7 on: November 30, 2016, 08:07:04 pm »
What gives?  R4 should pull MISO up to 5V, and R6 and R7 should reduce it to 3.4V.
That'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?
 

Offline Monkeh

  • Super Contributor
  • ***
  • Posts: 8068
  • Country: gb
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #8 on: November 30, 2016, 08:22:05 pm »
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.asp

That 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.

Quote
But I'm thinking I screwed up in my thinking here. I failed to account for the 470 + 1K path to ground. 

No, you failed to account for the exact opposite side of the problem.
 

Offline StarlordTopic starter

  • Frequent Contributor
  • **
  • Posts: 325
  • Country: us
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #9 on: November 30, 2016, 09:24:57 pm »
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.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9935
  • Country: us
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #10 on: November 30, 2016, 09:47:25 pm »
The voltage divider is (5.0 / (R4 + R6 + R7)) * R4 or 5.0 / 11470 * 1000 or 0.43V - no signal applied
If 5.0V is stuffed into MISO, the divider is 5.0 / (R4 + R7) * R7 or 5.0 / 1470 * 1000 or 3.4V
So, 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.
 

Offline StarlordTopic starter

  • Frequent Contributor
  • **
  • Posts: 325
  • Country: us
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #11 on: December 01, 2016, 07:36:59 am »
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.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19990
  • Country: gb
  • 0999
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #12 on: December 01, 2016, 12:32:09 pm »
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.
Yes, we tried to tell you that.

Quote
I still don't understand where the 1.75V is coming from though.
Perhaps 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.
 

Offline StarlordTopic starter

  • Frequent Contributor
  • **
  • Posts: 325
  • Country: us
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #13 on: December 01, 2016, 02:31:15 pm »
Quote
I still don't understand where the 1.75V is coming from though.
Perhaps something on SD_MISO is pulling it up slightly?

There'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.
 

Offline StarlordTopic starter

  • Frequent Contributor
  • **
  • Posts: 325
  • Country: us
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #14 on: December 01, 2016, 07:05:59 pm »
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.asp

And I input 5V VIN, 10470 for R1, and 1000 for R2, I get .436V
If I input 10000 for R1 and 1470 for R2, I get .641V

Neither 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?
 

Offline StarlordTopic starter

  • Frequent Contributor
  • **
  • Posts: 325
  • Country: us
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #15 on: December 01, 2016, 07:23:57 pm »
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.

Hm... 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.

 

Offline StarlordTopic starter

  • Frequent Contributor
  • **
  • Posts: 325
  • Country: us
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #16 on: December 01, 2016, 07:51:43 pm »
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!
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19990
  • Country: gb
  • 0999
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #17 on: December 02, 2016, 11:36:13 am »
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?

 

Offline StarlordTopic starter

  • Frequent Contributor
  • **
  • Posts: 325
  • Country: us
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #18 on: December 02, 2016, 01:08:30 pm »
Why are you using an oscilloscope for static voltage measurements? Use a multimeter instead. It's far more accurate.

I 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!

Quote
Is there anything else connected to SD_MISO which is not shown in the schematic?

Only the microcontroller and the ISP header. And nothing is attached to the header.

Quote
Are you sure the resistors are the values you think they are?

WTF? 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.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19990
  • Country: gb
  • 0999
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #19 on: December 02, 2016, 01:36:20 pm »
Why are you using an oscilloscope for static voltage measurements? Use a multimeter instead. It's far more accurate.

I 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!
What 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.

Quote
And I don't need a precise reading to tell that something is seriously wrong.  But I do need more practice with my scope
I agree.

Quote
Are you sure the resistors are the values you think they are?
Quote

WTF? R4 is reading 129 ohms!
Could 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?

 

Offline StarlordTopic starter

  • Frequent Contributor
  • **
  • Posts: 325
  • Country: us
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #20 on: December 02, 2016, 01:59:01 pm »
Quote
I 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!
What 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.

Precision != 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.

Quote
Could it be possible that there's an error on the PCB?

I suppose it's possible there could be a short somewhere. That would make two errors on one PCB though!

Quote
Have you tried assembling the bit that's causing the problem on a prototyping board?

No. I don't really see the benefit of doing that in this case.
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #21 on: December 02, 2016, 02:13:50 pm »
Precision != 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.
You're right, and the ADC in your scope (any scope) is neither accurate nor precise. The only thing 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.
 

Offline Monkeh

  • Super Contributor
  • ***
  • Posts: 8068
  • Country: gb
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #22 on: December 02, 2016, 02:33:27 pm »
Quote
I 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!
What 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.

Precision != 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.

How cute.

Your scope is as bad as ±4%. Your average cheap, nasty multimeter is as bad as ±0.1%.
 

Offline StarlordTopic starter

  • Frequent Contributor
  • **
  • Posts: 325
  • Country: us
Re: Why am I getting an incorrect voltage from my level shifting circuit?
« Reply #23 on: December 02, 2016, 07:04:27 pm »
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.

[edit]

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. 
« Last Edit: December 03, 2016, 02:46:34 pm by Starlord »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf