GPIO lowest input voltage that still reads logic high.


24 posts
by Pihkal » Sat Dec 29, 2012 11:13 am
Hi all,

i'm wondering what the minimum voltage on a digital GPIO pin must be to still read a logic 1.
Would 2,5V still register as logic 1?
On the other hand,would 3,4V cause any damage?
These are the 2 options i have for the moment.

Thanks
Posts: 52
Joined: Sun Sep 04, 2011 9:50 am
by joan » Sat Dec 29, 2012 11:32 am
2,5V should read as high. 3,4V shouldn't do any damage but 2,5V is safer.
User avatar
Posts: 5206
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by Gert van Loo » Sun Dec 30, 2012 9:51 am
These are the 2 options i have for the moment.


I am not sure if you have only a 2.5V supply or 3.4V supply or if you have a 2.5V signal and a 3.4V signal.

It the former: a 2.5V supply should still work. Make sure the signals coming out are rail-to-rail.
(That means they are very close to 0V when low and close to 2.5V when high).

if you have a 2.5V signal or a 3.4V signal then you have a problem.
Both will always seen as high (1).
I was thinking of a resistor divider to bring the values down but the difference is only 0.9V which is too little to make a reliable difference.
I am afraid you will need a complex circuit to reliably distinguish between those two values.
Probably an Op-amp with a reliable reference voltage.
User avatar
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1988
Joined: Tue Aug 02, 2011 7:27 am
by Pihkal » Sun Dec 30, 2012 1:01 pm
Hi,

thanks for the comprehensive explanation.
I'll explain what i was doing,it's really simple.
I just wanted to connect a TSOP1738 (i have a bunch of them) IR-receiver to use with XBMC,but it's a 5V device and the SoC isn't 5V tolerant so i figured i'd just put a voltage divider behind it to lower the voltage.
So i took 2 4K7 resistors to divide the voltage by 2,so i soldered it up and connected it,however it didn't work.
I started measuring the output voltage of the TSOP and it was only 0.65V after the divider and 1.3V before it,once it detected an ir-signal it pulled that voltage low.
So i removed the 4K7 resistor connected to signal and ground so it would give me 1.3V at the input pin of the SoC,this surprisingly works great.

Greets
Posts: 52
Joined: Sun Sep 04, 2011 9:50 am
by Grumpy Mike » Sun Dec 30, 2012 1:09 pm
The TSOP1738 output is a transistor with an 80K pull up resistor to +5V. By putting such a low resistor you are overloading the output.
I do not believe you get 1.3V from it with nothing connected, I suspect there is something wrong with your measurement equipment, maybe the impedance is too low.
By directly connecting it you are subjecting the Pi's input pins to 5V which is not good. What is happening is that the diodes in the Pi are clamping the input voltage allowing you to temporarily get away with it. You would be better off feeding the output through another transistor before feeding it into your Pi.
User avatar
Posts: 783
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
by Pihkal » Sun Dec 30, 2012 1:35 pm
You are right,the 1.3V was when it was connected to the pi.
I just took another TSOP,connected it to a 5V powersupply and measured the output of it,it's outputting 5V,just like you said.
So i'm wrong.
I could use a transistor but i prefer to use a divider.
If i just use higher value resistors it should be fine,or am i mistaking again?
Posts: 52
Joined: Sun Sep 04, 2011 9:50 am
by aTao » Sun Dec 30, 2012 1:46 pm
Voltage divider calc:
Code: Select all
Vi          R1          Vo           R2           0V
 --------/\/\/\/\/\-------------/\/\/\/\/\-------


Vo = Vi *(R2/(R1+R2))

Vi = 5V
R1 = 80k
Vo= 3.3V

-> R2 ~= 150k
except that the RPi will add to R2 a little bit, personally 100k should do.
except that a direct connection of the sensor to the RPi would put only 20uA into the pin surely this wouldnt be a problem?
>)))'><'(((<
User avatar
Posts: 439
Joined: Wed Dec 12, 2012 10:41 am
Location: Swine Town UK
by Pihkal » Sun Dec 30, 2012 4:43 pm
Thanks for the tip.
I have another question,someone stated before that i"m overloading the TSOP but the datasheet says it can deliver 5 milliamps,since there's a 4K7 resistor in series with the output the maximum current that can be pulled from it is 1,06 mA (I=5/4700) so how is it overloading?
I understand the voltage is to high for the SoC but it seems to be handling it just fine,it's running for over 24 hours...
The SoC's internal clamping diodes should be quitte robust so i'm wondering if it can really cause major damage?
Posts: 52
Joined: Sun Sep 04, 2011 9:50 am
by Gert van Loo » Sun Dec 30, 2012 10:24 pm
CMOS inputs (which is what the Raspberry-Pi has) have a very, very high impedance.
So, NO: you will not be overloading the TSOP.

The reason why you have seen no problems yet is because the current flowing into the clamp diodes is very low.
That is because your output has a pull-up resistor of the 80K resistor. Normal outputs have driving transistors which
try to put the full 5V of the supply rail on the output.
Thus you have 5V on the one side and about 3.3V at the other side.
(I say 'about 3.3V' as the clamp diodes will also have a bit of a voltage drop but I ignore that for now).
So your current is (5-3.3)/80000 = 0.02125 milli amps, which is 21.25 micro amps.
My guess is that it will probably work indefinite under those conditions, but good practice says: put the voltage divider in.
User avatar
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1988
Joined: Tue Aug 02, 2011 7:27 am
by Pihkal » Sun Dec 30, 2012 10:39 pm
Thanks,i think i finally understand why i haven't seen the magic smoke yet.
I will put another voltage divider after the tsop,i was going to do that anyway but now at least i understand why it works as is.
Thanks again for the good explanation.
Posts: 52
Joined: Sun Sep 04, 2011 9:50 am
by joan » Sun Dec 30, 2012 10:45 pm
I have a similar chip, the SFH5110, http://uk.rs-online.com/web/p/ir-remote-receiver/6548930/

It has a 23K internal pull up to 5V.

I have not been able to get it working with a voltage divider. I have the output plugged straight into a gpio.
User avatar
Posts: 5206
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by Gert van Loo » Mon Dec 31, 2012 9:18 am
joan wrote:I have a similar chip, the SFH5110, http://uk.rs-online.com/web/p/ir-remote-receiver/6548930/

It has a 23K internal pull up to 5V.

I have not been able to get it working with a voltage divider. I have the output plugged straight into a gpio.


Using the same formula: Vo = Vi *(R2/(R1+R2))
But with a different R1:
Vi = 5V
R1 = 23k
Vo= 3.3V

I have reworked the formula so R2 is isolated this gives: R2 = R1*(Vo/(Vo-Vi)) ***
In your case R2 = 3.3*(23K/(5-3.3)) = 44.64K.
You can not buy a 44.64K resistor so try 47K.
Thus you must add a resistor of 47K between your output and ground.
That gives a Vo of 3.35V.


*** See the symmetry between the original formula and the reworked one. I just love maths!!!!
User avatar
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1988
Joined: Tue Aug 02, 2011 7:27 am
by joan » Mon Dec 31, 2012 10:15 am
Ah, aren't I dumb!

I had completely ignored the internal resistor as far as the voltage divider was concerned. I assumed the output was 5V so I was using combinations like

IR out - 100R - gpio in - 160R - ground.

I'll try the 47K to ground after my chores.

Deleted and re-entered post with hopefully the resistors the right way around.

A 33K resistor was the first my aging eyes could recognise so I used that. It works.
User avatar
Posts: 5206
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by Pihkal » Mon Dec 31, 2012 1:26 pm
Hi again,

i've changed the circuit can you please confirm if i did it correct?
So,i've added a total of 133K (100K + 33K in series) between the tsop output pin and ground,since the internal pull-up resistor is 80K it should give me an output voltage of around 3.1V .
Is it ok now or am i still mistaking?
Posts: 52
Joined: Sun Sep 04, 2011 9:50 am
by Gert van Loo » Mon Dec 31, 2012 2:24 pm
Pihkal wrote:Hi again,

i've changed the circuit can you please confirm if i did it correct?
So,i've added a total of 133K (100K + 33K in series) between the tsop output pin and ground,since the internal pull-up resistor is 80K it should give me an output voltage of around 3.1V .
Is it ok now or am i still mistaking?


I don't know if it is ok :-). You have to check that but in principle that should work.
The 33K worked for Joan.....
User avatar
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1988
Joined: Tue Aug 02, 2011 7:27 am
by Gert van Loo » Mon Dec 31, 2012 2:25 pm
Pihkal wrote:Hi again,

i've changed the circuit can you please confirm if i did it correct?
So,i've added a total of 133K (100K + 33K in series) between the tsop output pin and ground,since the internal pull-up resistor is 80K it should give me an output voltage of around 3.1V .
Is it ok now or am i still mistaking?


I don't know if it is ok :-). You have to check that but in principle that should work.
The 33K worked for Joan.....
User avatar
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1988
Joined: Tue Aug 02, 2011 7:27 am
by Pihkal » Mon Dec 31, 2012 2:30 pm
Well it works,but so did the other one so yeah,we'll see.
I'm measuring 2.9V on the GPIO pin,which is a little less than expected.
Posts: 52
Joined: Sun Sep 04, 2011 9:50 am
by joan » Mon Dec 31, 2012 2:34 pm
How do you plan to decode the IR pulses?

I've been looking around to decode IR remote controls but can not find a solution which works on all remotes.
User avatar
Posts: 5206
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by Pihkal » Mon Dec 31, 2012 2:36 pm
LIRC,it works great.

http://www.lirc.org/

I'm using an old VCR remote,it transmits RC5 code.
Posts: 52
Joined: Sun Sep 04, 2011 9:50 am
by joan » Mon Dec 31, 2012 2:45 pm
I'll have a look at the code.

Most code assumes a known protocol, e.g. Sony, RC6, Mitibushi.

Most are active low but I have some which appear to be active high.
User avatar
Posts: 5206
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by Pihkal » Mon Dec 31, 2012 2:51 pm
The easiest way would be to just install LIRC and try your remote with it.
LIRC autodetects the protocol etc used by the remote.
Take a look here http://forum.stmlabs.com/showthread.php?tid=1954 ,allthough this is written for use with xbmc it could be used for general configuration of LIRC.
Good luck.
Posts: 52
Joined: Sun Sep 04, 2011 9:50 am
by joan » Mon Dec 31, 2012 3:01 pm
Several of us are playing with using DMA to read the gpios.

Currently I'm sampling the gpios at 200K Hz (every 5 microseconds) and I am converting some functions from "wait" to "event" driven.

I am trying to convert (level transitions in microseconds)

******************************
5806 140 289 60 1176 75 2934 140 525 121 190 230 679 140 280 460 2480 225 465 190 110 150 1100 175 241 150 619 50 366 215 609 135 290 140 1215 130 3200 150 1520 135 2885 131 900 50 1514 136 925 115 7700
******************************
12290 125 800 110 400 135 1765 150 4300 155 1095 150 590 155 1505 135 1660 125 810 125 2455 125 810 75 685 45 450 135 705 60 635 165 1005 165 160 60 655 140 3195 145 820 115 560 180 4770 100 5000 45 1820 60 540 170 485 130 500 220 785 135 1960 230 710 125 5370
******************************
6020 230 1435 335 460 415 260 225 295 140 345 160 285 135 1125 150 1415 120 4020 370 150 450 2780 140 510 120 800 130 605 110 4055 245 5380
******************************
5605 125 2385 125 500 140 995 140 470 390 3790 125 385 75 240 360 600 345 75 560 3275 130 4220 150 710 35 3505 130 1315 130 2570 250 1845 125 735 45 360 150 10545
******************************
8405 125 1655 50 3375 360 580 140 2465 50 1080 135 805 255 1935 70 2020 60 100 290 490 255 250 465 460 90 1595 60 1385 140 820 110 295 150 150 160 5865

into a sensible number!
User avatar
Posts: 5206
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by Pihkal » Mon Dec 31, 2012 3:05 pm
Oooh,that's something completely different.
Sorry,still good luck.
Posts: 52
Joined: Sun Sep 04, 2011 9:50 am
by joan » Mon Dec 31, 2012 3:19 pm
Oops, sorry, don't mean to derail your thread. Just got lost in my own enthusiasm. :oops:
User avatar
Posts: 5206
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK