il_diavolo
Posts: 138
Joined: Mon Dec 02, 2013 7:56 pm

Pull up - Pull down, have I got it right?

Mon Jul 28, 2014 1:33 pm

I think I understand but I'd be grateful if someone could confirm/deny it.
If I want a GPIO pin to be held "high" I connect it to a 3.3v pin through a resistor. When the GPIO pin receives a signal to go "low" that signal overcomes the resistor?
Similarly for the GPIO to be held "low" it needs to be connected to a Ground pin through a resistor which can then be overcome by a signal to go "high"?
If this is indeed what happens how do I know what value the resistors need to be? As you can tell, I am a beginner in electronics although I've been programming for years. I did manage to get my Acorn "Atom" and my BBC "B" to talk to each other through the user bus but that was 30 years ago!

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Pull up - Pull down, have I got it right?

Mon Jul 28, 2014 1:38 pm


User avatar
joan
Posts: 14376
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Pull up - Pull down, have I got it right?

Mon Jul 28, 2014 1:53 pm

Yes, that is correct.

The Pi also has internal pull-ups/downs of about 50 k ohm for each gpio. You can enable them in software.

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: Pull up - Pull down, have I got it right?

Mon Jul 28, 2014 2:06 pm

Hi,
il_diavolo wrote:I think I understand but I'd be grateful if someone could confirm/deny it.
Pull resistors make sense only when:
- you need to define state of a signal when there is no active signal driver (output) feeding it, and/or
- the type of active signal driver (output) requires the pull resistor. These outputs are named as open-something (open-collector, open-drain).

Pull resistor value depends on few very distinct parameters, like distance of the trace/wire, signal transition shape (rise/fall time), etc. There is always a "conflict" between parameters and current consumption... so the optimum values are defined on per-case bases.
By default, you can use 10k resistors and with some more knowledge gained later on you'll be able to judge when and how much you should decrease this value. Most likely, you'll never need to increase this value over 10k in digital circuits.


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

PiGraham
Posts: 3666
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Pull up - Pull down, have I got it right?

Mon Jul 28, 2014 2:21 pm

Yes, you basically have it right. To make an input a low state it's voltage should be below <=0.8V (typical lvttl values) . To make it high the voltage should be >= 2V. The actual value where state changes is in that range 0.8 - 2.0.
A pull up or pull-down forms a voltage divider with the effective series resistance of whatever is driving the GPIO, plus any series resistor you include to protect the GPIO.You should choose a pull resistor to ensure that the voltage at the pin swings <0.8 or >2.0 as the driving device changes state.

il_diavolo
Posts: 138
Joined: Mon Dec 02, 2013 7:56 pm

Re: Pull up - Pull down, have I got it right?

Mon Jul 28, 2014 7:00 pm

Thanks for the replies, very helpful and it is nice to know I wasn't too far off track.
Another question if I may?
The device I'm trying to attach requires a serial connection so I intend to use the UART on pins 8 and 10. (signal levels will not be greater than 3.3v). The device also requires that pin 8 is raised from low to high (or toggled from high to low and back to high) to confirm that the Pi is ready to receive data.
My question is - can I toggle pin 8 using RPi.GPIO commands while it is open as a serial port or should I send signals via PySerial commands? (I'm using Python 2.7).

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Pull up - Pull down, have I got it right?

Mon Jul 28, 2014 7:04 pm

I guess you could just send a binary 1 i.e. 0x01 over the TX? Depends how long the pulse needs to last for.

boyoh
Posts: 1342
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Pull up - Pull down, have I got it right?

Mon Jul 28, 2014 7:46 pm

il_diavolo wrote:I think I understand but I'd be grateful if someone could confirm/deny it.
If I want a GPIO pin to be held "high" I connect it to a 3.3v pin through a resistor. When the GPIO pin receives a signal to go "low" that signal overcomes the resistor?
Similarly for the GPIO to be held "low" it needs to be connected to a Ground pin through a resistor which can then be overcome by a signal to go "high"?
If this is indeed what happens how do I know what value the resistors need to be? As you can tell, I am a beginner in electronics although I've been programming for years. I did manage to get my Acorn "Atom" and my BBC "B" to talk to each other through the user bus but that was 30 years ago!

Using a Pull / Up or a Pull /Down resistor on a GPIO in/put
Can be very confusing to under stand.
You are delving in to TRI-state 3- state logic.

The input as e very high impedance ( Resistance ) it will
Not sink or sorce a Signal in that state

To use it to receive active 1(high) or a active 0 (low)
You must lower the in/put impedance to suit the wanted
Signal, You can do this in two ways Internal or external
Internal set it in your program

External, If the wanted in/put signal is a active 1(high)
You connect a 10k resistor to the 0v- pin.

If the wanted in/put signal is a active 0( low)
You connect a 10k resistor to the GPIO 3.3v+ pin

Remember the active 1( high) in/put, must not be
Be greater than 3.3v+
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

drgeoff
Posts: 9901
Joined: Wed Jan 25, 2012 6:39 pm

Re: Pull up - Pull down, have I got it right?

Mon Jul 28, 2014 8:42 pm

boyoh wrote: You are delving in to TRI-state 3- state logic.
Not strictly correct.

Tri-state applies only to logic outputs. You don't need pull-ups or downs on tri-state outputs. The 3 states are high, low and high impedance (or float.)

You can have pull-ups (and sometimes require them) on open-collector outputs (or equivalent in CMOS technology.) However, those by definition are not tri-state.

You can have pull-ups (or pull-downs) on inputs. Inputs are not tri-state in the accepted use of the term.

PiGraham
Posts: 3666
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Pull up - Pull down, have I got it right?

Mon Jul 28, 2014 8:49 pm

drgeoff wrote:
boyoh wrote: You are delving in to TRI-state 3- state logic.
Not strictly correct.

Inputs are not tri-state in the accepted use of the term.
We could say that an input mode is when the output is in tri-state. When it's not tri-state the pin is an output.
A read returns the pin state as driven either by the external circuit or the internal output stage.

drgeoff
Posts: 9901
Joined: Wed Jan 25, 2012 6:39 pm

Re: Pull up - Pull down, have I got it right?

Mon Jul 28, 2014 9:14 pm

PiGraham wrote:
drgeoff wrote:
boyoh wrote: You are delving in to TRI-state 3- state logic.
Not strictly correct.

Inputs are not tri-state in the accepted use of the term.
We could say that an input mode is when the output is in tri-state. When it's not tri-state the pin is an output.
A read returns the pin state as driven either by the external circuit or the internal output stage.
1. That is only the special case when the pin can be an input or an output. There are definite cases when input pins are only ever inputs (eg address lines) and when output pins (even tri-state ones) are only ever outputs (eg data pins on masked ROMS.)

2. You appear to be using the term "tri-state" to mean the third state. ie neither the high or low ones. That is not correct. "Tri-state" refers to an output stage which can be put into any of the 3 states. http://en.wikipedia.org/wiki/Three-state_logic

boyoh
Posts: 1342
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Pull up - Pull down, have I got it right?

Mon Jul 28, 2014 9:49 pm

PiGraham wrote:
drgeoff wrote:
boyoh wrote: You are delving in to TRI-state 3- state logic.
Not strictly correct.

Inputs are not tri-state in the accepted use of the term.
We could say that an input mode is when the output is in tri-state. When it's not tri-state the pin is an output.
A read returns the pin state as driven either by the external circuit or the internal output stage.
· A tri-state input detection circuit produces two binary outputs that indicate whether a tri-state input signal is high, low, or in a hi-impedance state.
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

drgeoff
Posts: 9901
Joined: Wed Jan 25, 2012 6:39 pm

Re: Pull up - Pull down, have I got it right?

Mon Jul 28, 2014 10:04 pm

boyoh wrote:· A tri-state input detection circuit produces two binary outputs that indicate whether a tri-state input signal is high, low, or in a hi-impedance state.
More sloppiness. A signal cannot be "in a hi-impedance state".

And please stop talking about "tri-state inputs". Only outputs can be tri-state. Just because an input and a tri-state output can share a common connection does make it a "tri-state input".

You and other engineers familiar with this stuff may be able to converse OK using inexact terminology but it is confusing and unhelpful for beginners.

boyoh
Posts: 1342
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Pull up - Pull down, have I got it right?

Mon Jul 28, 2014 10:36 pm

drgeoff wrote:
boyoh wrote:· A tri-state input detection circuit produces two binary outputs that indicate whether a tri-state input signal is high, low, or in a hi-impedance state.
More sloppiness. A signal cannot be "in a hi-impedance state".

And please stop talking about "tri-state inputs". Only outputs can be tri-state. Just because an input and a tri-state output can share a common connection does make it a "tri-state input".

You and other engineers familiar with this stuff may be able to converse OK using inexact terminology but it is confusing and unhelpful for beginners.
A tri-state input detection circuit produces two binary outputs that indicate whether a tri-state input signal is high, low, or in a hi-impedance state. A pair of transistors conduct a current in response to a tri-state signal presented at an input node. Circuitry is provided to pull the input node to a known voltage when the input signal is in its hi-Z state. The transistors are series-connected to respective current sources, with the junctions between the transistors and their current sources forming the circuit's binary outputs. The output impedances of the current sources are made less than those of their respective transistors, so that when turned on by the input signal, a transistor pulls its associated output high or low. The circuit produces a unique binary output for each of the three input signal states. In a preferred embodiment, sampling pulses briefly activate the circuit, and downstream circuitry latches the circuit's outputs, reducing current consumption to zero except during the sampling period.
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: Pull up - Pull down, have I got it right?

Mon Jul 28, 2014 11:17 pm

Hi,
boyoh wrote:
drgeoff wrote:A signal cannot be "in a hi-impedance state".
A tri-state input detection circuit produces two binary outputs...
Let me start this response with a warning that the content of last few messages is probably not suitable for beginners, because the descriptions are a bit confusing - actually a mixture of a couple of different things.

Below is the summary, how I understand the statements of other corespondents. I'm not 100% sure that I understand correctly what they would like to explain... Anyway, I'm taking a risk to introduce additional dimension of a confusion. ;-)

Facts:
1) There are no hi-Z signals. This state is actually nothing but absence of a signal (eg. disconnected wire). /I don't want to dive into current leaks here./
2) Some chips exist which can detect absence of the signal (eg. disconnected wire) on their inputs and have internal elements to detect & handle this state. This feature can be implemented also with discrete elements.

drgeoff is writing about the first bullet, where boyoh tries to explain the second bullet.


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

drgeoff
Posts: 9901
Joined: Wed Jan 25, 2012 6:39 pm

Re: Pull up - Pull down, have I got it right?

Mon Jul 28, 2014 11:52 pm

boyoh wrote: A tri-state input detection circuit produces two binary outputs that indicate whether a tri-state input signal is high, low, or in a hi-impedance state. ......... reducing current consumption to zero except during the sampling period.
And your point is? Just because you reproduce some patent claim which also uses sloppy terminology doesn't make it gospel. Any more than finding multitudes of pages on the net containing what I and most others say are spelling and grammar errors demonstrates that we are mistaken.

An output stage, a circuit node, a signal line, a bus etc can be in a high-impedance state. A signal cannot. No more than an idea can have a colour.

I have already laboured the point that the term "tri-state" is only applicable to output stages and not to input stages. If you don't want to accept that, it is your prerogative. I don't need you to be convinced. I have attempted to make cogent arguments for the benefit of other readers. They are at liberty to balance those and any others, including yours, when making their own judgement.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: Pull up - Pull down, have I got it right?

Tue Jul 29, 2014 12:21 am

OP, you have it right.

drgeoff, any decent engineer understands the expression "tristate input", and can figure out how to determine its state (high, low, or floating).

drgeoff
Posts: 9901
Joined: Wed Jan 25, 2012 6:39 pm

Re: Pull up - Pull down, have I got it right?

Tue Jul 29, 2014 12:52 am

ame wrote: any decent engineer understands the expression "tristate input", and can figure out how to determine its state (high, low, or floating).
1. He/she might understand it, but in my opinion if he/she utters or writes the expression "tristate input" he/she is not a decent engineer. Only the output(s) connected to it should be termed "tri-state."

2. How to determine the state of an input is not at issue.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: Pull up - Pull down, have I got it right?

Tue Jul 29, 2014 1:04 am

drgeoff wrote:
ame wrote: any decent engineer understands the expression "tristate input", and can figure out how to determine its state (high, low, or floating).
1. He/she might understand it, but in my opinion if he/she utters or writes the expression "tristate input" he/she is not a decent engineer. Only the output(s) connected to it should be termed "tri-state."

2. How to determine the state of an input is not at issue.
Would you prefer the term "ternary input"?

User avatar
jojopi
Posts: 3085
Joined: Tue Oct 11, 2011 8:38 pm

Re: Pull up - Pull down, have I got it right?

Tue Jul 29, 2014 3:17 am

ame wrote:Would you prefer the term "ternary input"?
Surely a ternary input is one that can distinguish three different voltage or current conditions—most likely positive, zero, and negative. Such signalling is used in some forms of Ethernet.

You cannot use high voltage, low voltage, and floating as three distinct signalling states, because the undriven state is fundamentally unsuitable as a high-speed signal. It exists for when you want to stop signalling, possibly to listen to someone else.

Although I cannot rule out the utility of being able to check whether an input is floating, this is not a normal operation.

drgeoff
Posts: 9901
Joined: Wed Jan 25, 2012 6:39 pm

Re: Pull up - Pull down, have I got it right?

Tue Jul 29, 2014 7:00 am

ame wrote: Would you prefer the term "ternary input"?
No. As stated in the wikipedia articlle I linked to above:

"The term tri-state should not be confused with ternary logic (3-value logic)."

il_diavolo
Posts: 138
Joined: Mon Dec 02, 2013 7:56 pm

Re: Pull up - Pull down, have I got it right?

Tue Jul 29, 2014 8:30 am

Fascinating discussion people but perhaps irrelevant to my original posts. It's way over my head as someone who's just dallying with an inexpensive electronic education device aimed at young people and seeking help in the "Beginners" forum. Nobody has completely answered my final question, can I toggle pin 8 using RPi.GPIO commands while it is open as a serial port or should I send signals via PySerial commands?
I'll add to that - will setBreak() or setRTS() from PySerial do the job?
I'm having fun though!

User avatar
joan
Posts: 14376
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Pull up - Pull down, have I got it right?

Tue Jul 29, 2014 8:40 am

il_diavolo wrote:Fascinating discussion people but perhaps irrelevant to my original posts. It's way over my head as someone who's just dallying with an inexpensive electronic education device aimed at young people and seeking help in the "Beginners" forum. Nobody has completely answered my final question, can I toggle pin 8 using RPi.GPIO commands while it is open as a serial port or should I send signals via PySerial commands?
I'll add to that - will setBreak() or setRTS() from PySerial do the job?
I'm having fun though!
What do you mean by toggle?

The line will normally be high but will go low when data is transmitted (start bit). You have no control of the start/stop bits.

If you write from RPi.GPIO you will set the line as an output (mode 1) so it will no longer be in serial mode (mode 4, ALT 0). I am not sure if RPi.GPIO will let you switch it back to serial mode.

You need to be precise about what "toggling" is needed by the remote end.

il_diavolo
Posts: 138
Joined: Mon Dec 02, 2013 7:56 pm

Re: Pull up - Pull down, have I got it right?

Tue Jul 29, 2014 9:01 am

Sorry, I'll try to be a bit precise. The spec from the device says-
Upon detecting a low-to-high signal edge on the DCD line, your driver should:
(I'm ok with that bit, the "DCD" line can simply be connected to another GPIO pin rather than one used by the UART)
Open the serial port, if not already open.
If the signal on the RTS line is LOW, RAISE it from low to HIGH.
If the signal on the RTS line is HIGH, TOGGLE it from high to LOW back to HIGH
.

Note that RTS is the device's RTS which will be connected to pin 8 (TXD) on the RPi header.

I'm in the deep end but my forum life vest is still keeping me afloat.

PiGraham
Posts: 3666
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Pull up - Pull down, have I got it right?

Tue Jul 29, 2014 9:12 am

It seems you can set a GPIO pin to one of its ALTn functions using the SET_GPIO_ALT macro (in c/c++)

Code: Select all

// GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y)
#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
#define OUT_GPIO(g) *(gpio+((g)/10)) |=  (1<<(((g)%10)*3))
#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))

#define GPIO_SET *(gpio+7)  // sets   bits which are 1 ignores bits which are 0
#define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0

#define GET_GPIO(g) (*(gpio+13)&(1<<g)) // 0 if LOW, (1<<g) if HIGH
More info here: http://elinux.org/RPi_Low-level_periphe ... re_hacking

Return to “Beginners”