Propeller pins, resistors, logic level converters, please advise.
ptiago
Posts: 37
Hi,
I made some bullet points to be easy to understand, my background is software, please be patient.
Q1)
I would like to connect the Propeller to an Arduino (5v Logic Level), using serial communications, do i need to use a Logic Level Converter for the TX,RX ?
Q2) If the the Propeller pins cand handle 5v, why we need Logic Level Converter, or resistors (examples below) ?:
Two examples (Same type of sensor):
2.1) HC-SRC04
Two pins:
Trigger (Input) 1K resistor
Echo(Output) 10K resistor
http://propellerpowered.com/shop/?page_id=1789
2.2) Ping Sensor
One single pin (Input/Output),
http://learn.parallax.com/propeller-c-simple-devices/sense-distance-ping: 2K if connected direct to a Pin, 3.9K (on board connected to a servo port )
http://learn.parallax.com/activitybot/build-and-test-ping-sensor-circuit: 2.2K if connected direct to a Pin
http://learn.parallax.com/KickStart/28015: 1K if connected to a Pin
Resistors are related to current, regarding the Ping/HCSRC04 sensor, there are multiple values 1K,2K, 2.2K, 3.9K and 10K why not a single recommended value e.g. 3.9K (similar to the on board value/servo ports) ?
Q3) I understand there are two current conditions: sourcing, and sinking, and the resistors are important to control the current, a pin can be in input or output mode, do we need resistors in both input and output (HC-SRC04 as in both) ?
Q4) Regarding the resistor, what is correct value, do they change if they are attach to a input/output port ? or how to calculate otherwise it seems random number between an interval ?
Q5) If this is all related to different voltage logic level (3.3v - 5v), is not a LLC circuit preferred ?
Regards,
Tiago
I made some bullet points to be easy to understand, my background is software, please be patient.
Q1)
I would like to connect the Propeller to an Arduino (5v Logic Level), using serial communications, do i need to use a Logic Level Converter for the TX,RX ?
Q2) If the the Propeller pins cand handle 5v, why we need Logic Level Converter, or resistors (examples below) ?:
Two examples (Same type of sensor):
2.1) HC-SRC04
Two pins:
Trigger (Input) 1K resistor
Echo(Output) 10K resistor
http://propellerpowered.com/shop/?page_id=1789
2.2) Ping Sensor
One single pin (Input/Output),
http://learn.parallax.com/propeller-c-simple-devices/sense-distance-ping: 2K if connected direct to a Pin, 3.9K (on board connected to a servo port )
http://learn.parallax.com/activitybot/build-and-test-ping-sensor-circuit: 2.2K if connected direct to a Pin
http://learn.parallax.com/KickStart/28015: 1K if connected to a Pin
Resistors are related to current, regarding the Ping/HCSRC04 sensor, there are multiple values 1K,2K, 2.2K, 3.9K and 10K why not a single recommended value e.g. 3.9K (similar to the on board value/servo ports) ?
Q3) I understand there are two current conditions: sourcing, and sinking, and the resistors are important to control the current, a pin can be in input or output mode, do we need resistors in both input and output (HC-SRC04 as in both) ?
Q4) Regarding the resistor, what is correct value, do they change if they are attach to a input/output port ? or how to calculate otherwise it seems random number between an interval ?
Q5) If this is all related to different voltage logic level (3.3v - 5v), is not a LLC circuit preferred ?
Regards,
Tiago
Comments
Generally, any resistor on an output is to protect that pin, in case the external device becomes physically corrupted, or there is a short. The 1K value is pretty typical.
You only need level conversion going out if the device doesn't work with the 3.3V voltage output by the Propeller. This can only be determined empirically, and by reading the spec sheet for that device. If the device requires 5V input, it will often say so.
is possible to move this thread to the propeller forum ? my mistake.
Gordon,
Thanks for the input, it seems too simple ... between the lines:
Propeller output, resistor only needed to protect short circuits.
Propeller input, resistor to limit current, is there a formula ?
ASFAIK, arduino will accept 3.3 V as logic 1, is still necessary a resistor from Arduino Tx to the Propeller Input RX ?
Tiago
For a 5V input to the propeller a minimum of 3.9K is what I recommend. That value takes into account the possibility of the +5V being 5% high and the +3.3V being 5% low. Regulator IC's nominal voltage is not always dead on. For output resistors I generally use 220 ohms unless there is a reason for using some other value. The minimum value I recommend for an output is 120 ohms. That will limit the output current to a safe level if the output of the resistor was shorted to ground.
Let's say it's not complex. The variance you see is mostly from designer's personal choice. There are valid technical reasons for these choices, yet in actual practice, it turns out a 1K resistor on an input pin and no resistor on an output* pin is fine the majority of the time. That's about all I ever do, and so far, haven't fried any Props or Arduinos. However, that's just me, and every reply you'll get here is likely to be different.
(*There is no rule that the resistor on a Prop output pin is only for when interfacing to a 5V device. If you're going to do it between 3.3V->5V, you should do it for everything, given the nature of the faults you're trying to design for.)
For your final question, the answer is yes: you should have that resistor. Avoid leaving out a current-limiting resistor when a Propeller pins is set as an input.
The input current on a Propeller pin should be limited to 500 microamps (this value is from the Propeller's datasheet). If you take into account the voltage drop across the clamping diodes and use ohms law the resistor value ends up being close to 3K. This gets rounded up to the next closest common value which is 3.3K. I generally use 10K since I have lots of them.
This question seems backwards. Did you mean " is still necessary [to use] a resistor from Propeller Tx to the Arduino Input RX?"? The question you asked is answered with yes. No is the answer to the question I wrote.
You can use a resistor between the Propeller's output and a 5V input but it may prevent the 5V device from reading the 3.3V logic as high (this has happened to me many times). If you use a resistor on a Propeller's output, I'd suggest using 1K (or lower).
My question is from Arduino Tx (5v) -> Propeller Rx everyone agrees i need a resistor should i go with the common sense 1K ?
the other flow:
Propeller Tx (3.3) -> Arduino Rx, No resistor: Arduino ports default to inputs, if by mistake i set the Arduino Pin Rx to Output, and no resistor in the middle, some damage can happen right ?
To avoid that i'll need a resistor, is there a relation between the resistor value (e.g. 220 ohm, 1K) and noise/interference in the signal ?
To be honest i don't know how a resistor (current) can interfere with voltage levels, the only explanation i can find is I = E/R, means more resistance less current ?
TP
-Phil
1K is not a safe value. It should be at least 3K to keep the current below 500uA.
When the Prop first came out 1K was suggested as a safe value but Parallax revised this value up (it might be as low as 2.7K but I see 3K mentioned frequently). As I said earlier, I generally use 10K.
I've read posts from people, I consider to know more about this kind of thing than myself, who suggest using resistors to reduce noise. I generally don't use resistors if they're not needed to protect the Propeller (the reason will be included in the answer to your next question).
I don't know what causes the problem but if I use 10K ohm resistors to drive many 5V devices, the 5V device doesn't recognize the 3.3V logic. This has happened with servos and ultrasound sensors.
The problem I've had with servos is the main reason I don't use resistors if they're not needed to protect the Propeller. I don't claim this is the best practice.
HOWEVER, that's not wise to do. If you accidentally reprogram the Arduino to use that pin as an output,
that will trash the Prop-pin.
If you want to do a proper job in level shifting, get a level shifter module or use
relevant logic families as "glue":
You can use the 74HCTnn logic family powered at 5V to map 3V inputs to the Arduino,
and 74LCXnn logic family powered at 3.3V to map 5V inputs to the Prop (the LCX family
have 5V tolerant inputs (truly tolerant I mean, not "tolerant if you use resistors"). The
advantage of using proper logic gates like this is you'll get 30MHz+ out of them without
a murmur - the various resistor hacks reduce bandwidth considerable (this won't
matter for serial at 115200 baud, if does matter for SPI for instance).
Thanks for the all feedback and time, i made a few tests, and there are simple scenarios where a resistor can work, but there are others were you will get annoyances, i got a few LLC circuits and i'll use.
I don't know if others have similar needs but a simple "shield" with:some LLC circuits and some extra pins (gnd rail, vcc rail) aligned with signal pins
can help a lot,
i hate the mess of using resistors, bread boards to have gnd/vcc rails, I always end up building a small perforated board for that.
Tiago
btw: I'm struggling with the new forum layout...
Go to www.parallax.com and search for AN010. AN010 addresses mixed voltage interfacing and recommends a 4.7k current limiting resistor when interfacing the prop to a 5 volt device. I don't know who wrote it but it's on Parallax Semiconductor letterhead and makes some good points.
I've been meaning to write two little PASM objects. One object sets pin 0 high and records the value of cnt. The other waits for pin 1 to go high and records the value of cnt when it goes high. Pin 0 will be connected to pin 1 by a resistor. It will be interesting to see the time difference with different resistor values.
Sandy
There isn't much difference between the values. This is using the 3.3 volt output of pin 0. If you were using 5 volt inputs the time might get shorter but I haven't tested that.
I might develop this further and see what difference a 5 volt input makes.
Sandy
Sandy
A 5V signal as input to a propeller pin is another matter. Each I/O pin has a pair of clamping diodes, one going to gnd and one to 3.3V. Those diodes have a current limit of 500uA, so for a 5V input a series resistor would have to drop (5 - 3.3 + 0.6) / .0005 volts (assuming a 0.6V drop for the diode) to limit the current to 500uA. That would be 1.1 / .0005 or 2.2K.
However, that's not the whole story. Some of the older regulators are rated at +- 5% of their nominal voltage, so worst case the 3.3V supply could be as low as 3.135V, and the +5V as high as 5.25V. Now the current limiting resistor would need to be (5.25 - 3.135 + 0.6) / .0005 or 4.35K. The next higher standard resistor value is 4.7K.
I think you mean (5 - 3.3 - 0.6), don't you?
-Phil
However, that's not the whole story. Some of the older regulators are rated at +- 5% of their nominal voltage, so worst case the 3.3V supply could be as low as 3.135V, and the +5V as high as 5.25V. Now the current limiting resistor would need to be (5.25 - 3.135 + 0.6) / .0005 or 4.35K. The next higher standard resistor value is 4.7K.
My interest was input voltage and I was specifically interested in what effect different values of current limiting resistor would have on response time for a pin. My tests show anything up to 100k is okay for most cases. Note the use of the word 'most'. The 4.7k value you mentioned is the same as the value specified in the attached application note.
If 4.7k and 100k resistors produce the same result, wouldn't you want to go with the higher value? It would make life just a little bit easier for the clamping diodes.
If 4.7k and 100k resistors produce the same result, wouldn't you want to go with the higher value? It would make life just a little bit easier for the clamping diodes.
Exactly what I keep saying (and doing) but everyone seems to be using the very low value "just to be safe". This is something you can get away with on one of two inputs but the substrate currents add up and cause other problems too. So "just to be safe" would be better to use 100k rather than 4k7.
btw, the "recommended" value of 4k7 is not actually the recommended value, only the recommended "minimum" as in the limit.
I think you mean (5 - 3.3 - 0.6), don't you?
-Phil
No, I meant +. The diode is forward biased so a positive input signal would have to be higher than Vcc (3.3V) plus the forward voltage of the diode before any current starts to flow.
However, that's not the whole story. Some of the older regulators are rated at +- 5% of their nominal voltage, so worst case the 3.3V supply could be as low as 3.135V, and the +5V as high as 5.25V. Now the current limiting resistor would need to be (5.25 - 3.135 + 0.6) / .0005 or 4.35K. The next higher standard resistor value is 4.7K.
My interest was input voltage and I was specifically interested in what effect different values of current limiting resistor would have on response time for a pin. My tests show anything up to 100k is okay for most cases. Note the use of the word 'most'. The 4.7k value you mentioned is the same as the value specified in the attached application note.
If 4.7k and 100k resistors produce the same result, wouldn't you want to go with the higher value? It would make life just a little bit easier for the clamping diodes.
You're right, 100K works fine for most cases, but it will affect the rise and fall times of both input and output signals. That can be a problem for high speed circuits, particularly if you are driving capacitive loads like mosfets in pwm circuits.
If 4.7k and 100k resistors produce the same result, wouldn't you want to go with the higher value? It would make life just a little bit easier for the clamping diodes.
Exactly what I keep saying (and doing) but everyone seems to be using the very low value "just to be safe". This is something you can get away with on one of two inputs but the substrate currents add up and cause other problems too. So "just to be safe" would be better to use 100k rather than 4k7.
btw, the "recommended" value of 4k7 is not actually the recommended value, only the recommended "minimum" as in the limit.
I agree, 4k7 is the recommended minimum value for use with 5V inputs. It's also a pretty good value to use on output pins as well. Great for driving small signal and switching bjt's. I have quite a few breadboarding jumpers with 4k7 resistors soldered between the ends. Very handy for prototyping. Of course I also have jumpers with 120, 240, 10K, 100k, and other values as well. No single value works for every purpose.
I think you mean (5 - 3.3 - 0.6), don't you?
-Phil
No, I meant +. The diode is forward biased so a positive input signal would have to be higher than Vcc (3.3V) plus the forward voltage of the diode before any current starts to flow.
Exactly! That's why the sign for 3.3 and 0.6 need to be the same. IOW, (5 - 3.9). As you've written it, it would be (5 - 2.7) -- unless you add some parentheses: (5 - (3.3 + 0.6)). In any event, the voltage drop across the limiting resistor will be 1.1V, not 2.3V.
-Phil
I think you mean (5 - 3.3 - 0.6), don't you?
-Phil
No, I meant +. The diode is forward biased so a positive input signal would have to be higher than Vcc (3.3V) plus the forward voltage of the diode before any current starts to flow.
Exactly! That's why the sign for 3.3 and 0.6 need to be the same. IOW, (5 - 3.9). As you've written it, it would be (5 - 2.7) -- unless you add some parentheses: (5 - (3.3 + 0.6)). In any event, the voltage drop across the limiting resistor will be 1.1V, not 2.3V.
-Phil
Sorry for the misunderstanding, that is what I meant.
Very interesting indeed.
So, at what point below 100K would some recommend before rise and fall time changes?
Or maybe better for us dummies, what are the actual effects we would see or have to take into consideration if we were to now use the recommened 100K?
Is there a break somewhere, like up to 50K there is no real world impact, or no?
Very interesting indeed.
So, at what point below 100K would some recommend before rise and fall time changes?
Or maybe better for us dummies, what are the actual effects we would see or have to take into consideration if we were to now use the recommened 100K?
Is there a break somewhere, like up to 50K there is no real world impact, or no?
There is no general "break" point, it is more of a slope function, and it depends on the circuit it is connected to. Using a 100k vs 4k7 on an input that is measuring the width of a pulse may change the measurement by a few nanoseconds. Not much of an error for a 100 millisecond pulse, but a substantial one for a 100 nanosecond pulse. Also, if you are driving a mosfet a slight delay in going from fully off to fully on (and on to off) is not a problem if it only happens a few times a second. At higher frequencies like those used in pwm it can cause a large increase in power consumption and overheat the mosfet.
To crisp up the edges, add a capacitor in parallel with the resistor. That will take care of the AC component of the signal.
During a transition the cap's low XC puts electrons where they're needed, then the resistor holds the DC level where it needs to be.
What value capacitor???? Start with a value equal to the input side. For example a MOSFET gate capacitance of 800pf will work well with 800pf in parallel with the resistor.
If the cap is too small there will be rolloff. If it's too big there will be overshoot - spikes.
BTW: I don't use protection diodes for level shifting. It's easy enough to add external diodes connected to Vcc and ground.
@kwinn: not sure why you are referring to a 5V to 3.3V input current limit resistor for outputs as well. If I do use a current limit resistor on an output it's for an entirely different reason and usually this resistor value is more like 220R. Most CMOS outputs including the Prop are very tolerant of short circuits and I have never had one damaged because of it. The 220R is a handy value if I drive an LED directly for instance.
@all: I see a diode drop of 0.6V being referred to but that voltage is for a regular discrete silicon diode whereas the substrate diode drop is more like 0.4V which is why the absolute max voltage on a pin is spec'd at Vdd+0.3V
@kwinn: not sure why you are referring to a 5V to 3.3V input current limit resistor for outputs as well. If I do use a current limit resistor on an output it's for an entirely different reason and usually this resistor value is more like 220R. Most CMOS outputs including the Prop are very tolerant of short circuits and I have never had one damaged because of it. The 220R is a handy value if I drive an LED directly for instance.
@all: I see a diode drop of 0.6V being referred to but that voltage is for a regular discrete silicon diode whereas the substrate diode drop is more like 0.4V which is why the absolute max voltage on a pin is spec'd at Vdd+0.3V
Re: "not sure why you are referring to a 5V to 3.3V input current limit resistor for outputs as well"
Basically meant that while 4k7 resistors are needed for current limiting on input pins that are connected to 5V signals there is no reason they cannot be used for outputs that connect to other chips with high impedance inputs, the base of npn small signal transistors, and the base of pnp transistors as long as the voltage on the emitter is less than 4.3V.
I agree, 220 ohm resistors are all that is needed if protecting pins from shorts to ground or
driving leds is the only concern. For my main prototyping board I wanted a bit more protection (mainly for working with 5V input signals) so I soldered 4k7 resistors on P0 - P23. That board still works perfectly four or so years later, and on those rare occasions when I needed higher output currents I can solder a resistor or jumper across the 4k7 resistor.
Basically meant that while 4k7 resistors are needed for current limiting on input pins that are connected to 5V signals there is no reason they cannot be used for outputs that connect to other chips with high impedance inputs, the base of npn small signal transistors, and the base of pnp transistors as long as the voltage on the emitter is less than 4.3V.
I agree, 220 ohm resistors are all that is needed if protecting pins from shorts to ground or
driving leds is the only concern. For my main prototyping board I wanted a bit more protection (mainly for working with 5V input signals) so I soldered 4k7 resistors on P0 - P23. That board still works perfectly four or so years later, and on those rare occasions when I needed higher output currents I can solder a resistor or jumper across the 4k7 resistor.
Fair enough then, but you had me worried because you were talking about driving MOSFETs when the question was more about inputs
I normally calculate with 6 pF per pin. The I get the following values:
Andy