Tri-state pulsout?

BeanieBots

Moderator
Is it possible to make a PICAXE pin pulsout to a valid logic level but end in a tri-state condition without losing the precision of the pulsout period.
That is, go from tri-sate to logic high (and/or low) then return to tri-state with the valid logic state being precisely defined as with a "normal" pulsout command?
Not too fussed which PICAXE but also require 3 ADC inputs.

At the moment I am using a series diode on an OP with pulsout but want to avoid the diode volt-drop problems.
 

westaust55

Moderator
The only way to make a pin of a port tri-state is to change it to in input.
That can be done with the TRIS register corresponding to the port involved.
For example TRISB for port B.

Do not think you can achieve what you wish to do.

a few test would ascertain whether:
(a) the PICAXE firmware will allow an output pin to be force into input mode and stay that way.
(b) whether the PULSOUT command would set the pin back to an output just as the pulse was to be generated.

However I cannot foresee that after the PULSOUT, the PICAXE firmware would revert to point back to an input/tri-state condition

Have a look at my PICAXE memory map for the SRF locations for the TRIS registers (133 to 137) if you want to experiment.
http://www.picaxeforum.co.uk/showthread.php?t=9525&page=2 post 14
 
Last edited:

InvaderZim

Senior Member
I think it'd work fine if you output to a transistor inverter with a very large (100k-1M ohm) pullup. Or possibly no pullup at all, just use open-collector logic. Use an NPN transistor to toggle between active low/high imp. and a PNP to toggle between active high/high imp.

The output "pulse" is inverted, but you can correct for that in software.
 

hippy

Ex-Staff (retired)
I can only think of using the diode as you have suggested. It should be possible to replicate a PICAXE / PICmicro output port configured as you want but I'll leave the design of that to the electronics experts :)

Or you could just use a PICmicro. It's a simple enough program to write and might even work with the BAS800 programmer and its Basic to Assembler converter although you might need a couple of lines of tweaking. That said, it shouldn't be more than a couple of lines of code in total.
 

womai

Senior Member
Instead of a diode, programming a PIC uC, or building a tristate-able driver out of discrete components, a much better - and very simple - idea is to use a standard 74xx logic chip with tristate outputs: easy-to-procure choices are e.g. 74HC125 or 74HC126 (both are quad three-state drivers). Apply the desired logic level (high or low) to the driver input (i.e. connect it to one of the Picaxe's output pins), and switch between this level and the high impedance state using the tristate input (i.e. connect the tristate input to the Picaxe's pulsout output pin). Those chips cost less than 50 cents a piece and come in easy-to-handle 14 pin DIP packages. And the output does not show a voltage drop because there aren't any diodes.

Wolfgang
 

InvaderZim

Senior Member
Got a drawing up; see attached. An NPN and resistor total ~15 cents, offers no appreciable distortion to your pulse, and gives rail-to-rail voltage output(especially if you use a FET, though I'm sure an old bi-polar would work fine).
 

Attachments

BeanieBots

Moderator
Thanks for the replies.
Programming a PIC (which would be the ideal solution) is out due to excessive learning curve and the BAS800 does not support all the other commands I'd need.
Using a discrete tranny (without pull-up/down) is nice and simple but for purely lazy reasons I'll go with using a tri-stateable buffer IC.
Bit obvious really once it's pointed out:eek:
 

Ralpht

New Member
Invaderzim,

I think BB wanted a true tristate output.
Your circuit is perfectly adequate for normal use but may not provide the true tristate output that BB wanted. Tristate being interpreted as the output "floating or not connected" either to logic hi or low.
The drawing has the output from the collector of Q1 connected to +5V (Hi) via the 500k resistor. While the resistor value is high enough to possibly simulate a "tristate" condition, when the PIC output is lo, there still will be slight current flow and depending on the requirements/circuit conditions of the device connected to the collector the output may still be read as a weak logic hi.

The resistor cannot be optional as the collector will never be able to go hi which is a requirement of BB's circuit.

When pulse in is hi, Q1 collector will be lo, when pulse in is lo, Q1 collector will be a weak hi. There is no tristate - not connected to hi or low possibilities here.

I personally will go for a tru tristate chip like Womai suggested though that will require a seperate Pic output to switch the chip into tristate mode.
 

westaust55

Moderator
Tri-state pulsout

Even with Womai’s suggestion, used directly, with no other components as Ralph says, will need for two outputs and there will still be a short time between turning the Tri-state buffer output on and the pulse occurring and likewise when the pulse is completed and having the PICAXE turn the output back to tri-state. So two brief low state periods occur for each pulse.

That would be no better than using the PICAXE output directly if tri-state control as I mentioned in post 2 is possible.

Another option at the expense of more components and true tri-state to high-state to tri-state with no low-state would be:
1. tie the 74HC125 input high,
2. use an inverter or transistor to inver the pulse signal and apply the pulse signal to the tri-state control pin of the 74HC125.


EDIT:
Another option may be the 74HC386 hex inverting tri-state buffer.
Tie the enable for one group high and use one inverting buffer to invert the pulse signal which is used as a control for the second tri-state control line. The tie an input for buffer in the second group of buffers low so the output is high when the tri-state condition is removed. See the attached diagram
 

Attachments

Last edited:

womai

Senior Member
Hi Westaust,

I don't think there is a problem with using the driver; simple set up the desired drive state before you turn on the driver through the tristate input. So to drive a low pulse surrounded by tristate:

low my_drive_level_output ' goes to 74HC125 driver input
pulsout my_pulsout_pin ' goes to 74HC125 enable input

and to drive a high pulse:

high my_drive_level_output ' goes to 74HC125 driver input
pulsout my_pulsout_pin ' goes to 74HC125 enable input

In both cases there won't be any glitch.

That way you have program control over the desired logic level to drive. If you only need a single level, you can of course tie the 74HC125's drive input hard to GND or VCC, respectively, and save an output pin on the Picaxe.

Wolfgang
 

westaust55

Moderator
Tri-state pulsout

Hi Wolfgang,

What you propose may be acceptable to Beaniebots.

Beaniebots had stated:
Is it possible to make a PICAXE pin pulsout to a valid logic level but end in a tri-state condition without losing the precision of the pulsout period.
I read into this that BB did not want any period with an low logic level present at the output while maintaining the accuracy of the high active logic state.
 

InvaderZim

Senior Member
Invaderzim,

I think BB wanted a true tristate output.
Your circuit is perfectly adequate for normal use but may not provide the true tristate output that BB wanted. Tristate being interpreted as the output "floating or not connected" either to logic hi or low.
The drawing has the output from the collector of Q1 connected to +5V (Hi) via the 500k resistor. While the resistor value is high enough to possibly simulate a "tristate" condition, when the PIC output is lo, there still will be slight current flow and depending on the requirements/circuit conditions of the device connected to the collector the output may still be read as a weak logic hi.
There is slight current flow with any high Z circuit; "high Z" never means "infinite Z." That being said, 5V out of 500K ohm is 10 uA: any logic driver worth its salt can do that. Not good enough? Make it 1M ohm. Or 10M. You can get whatever your definition of "high Z" is.

The resistor cannot be optional as the collector will never be able to go hi which is a requirement of BB's circuit.
I read the requirement to be: output a pulse that is either 1) low or 2) high Z. An alternative requirement is to output a pulse that is either 1) high or 2) high Z. For the former, the NPN will do; for the latter, the PNP will work. The pullup is not required to achieve high impedance, since the transistor is already high Z.

When pulse in is hi, Q1 collector will be lo, when pulse in is lo, Q1 collector will be a weak hi. There is no tristate - not connected to hi or low possibilities here.
The fact that it is a "weak high" instead of a random (floating) voltage is irrelevant; I guarantee that anyone foolish enough to read a high Z data line will always get either a 1 or a 0...and it will be wrong half of the time. The rule is you never read an undriven data line!

The goal of a high Z data line is to allow other drivers to "take over" the wire and drive it at their will with minimal interference. With a decent transistor you'll do just that.

I personally will go for a tru tristate chip like Womai suggested though that will require a seperate Pic output to switch the chip into tristate mode.
If it's a chip that gives you, say, 8 outputs for the price of 2 or 3, then I'm all for it (assuming you need them). But if you just need the one wire, well, I'll stay stubborn here and say that my circuit is the bestest circuit in the whole wide world :)
 

BeanieBots

Moderator
Wolfgang has my requirement spot on.
InvaderZim's circuit would be fine but I need as high an impedance as possible so NO resistor.
This is to combine a digital drive with an analogue op-amp circuit.
I require both a High->tri-sate and a low->tri-state drive.
The idea is to switch on a +/- known constant current into a virtual earth for a known short duration. The current is in the region of 100uA so leakage IS an issue. Normally, I'd do it with analogue switches.

As mentioned, at the moment I'm getting away with just a diode but the temp-coef of the diode is introducing an error which makes the design borderline for the spec I want. I was hoping to be able to just "do something clever" with the PIC but it would appear that is not an option whilst keeping with PICAXE.

I've done a few quick tests with an octal tri-state buffer. The inputs harwired to the required logic level and using pulsout on the tri-state control. It seems to work well except they need to be independantly controlled so two chips would be required. If I need to add another chip (the issue I was trying to avoid) then I will probably go back to my trusty old 4066.
Will try the single tranny version as well.

Thanks for the help guys.
 
Top