Need input pin low when not connected.

Garahbara

New Member
Guys,

Using a Picaxe-20M. I've discovered that if an input pin is not connected, then it will test high. i.e.

pin3 = 1.

I need it to = 0 when not connected. The reason? The pin will received PULSINs of varying length, however, the target of these pulses will be manually switched between processors.

When connected to another processor's output pin, the input pin is pulled (if that's the right terminology) negative, and the "pulse" is +, of course.

Diagramatically, wire like this.

A---------------------\
B--------------------------------C

Processor C does the OUTPUT pulses. which get read by INPUTS on processor A or processor B. The switch between the two is manual. ( at the "\" point). The ------------ represents railway tracks. A, B and C prepresent signals (and therefore, each Picaxe-20M).

When OUTPUT C is connected to INPUT A, the INPUT pin on B (not connected) is always High ( = 1). Not good, as it thinks the "pulse" is never ending. I believe the term for "not connected" is "floating". The inputs are currently tied to the + with a 10K ohm resistor.

I know, if I used an appropriate manual switch, I could tie the "floating" input of the "not connected" processor to the negative.

This is not possible, as I'm limited to a particular switch (single pole slide switch), as it is model railway specific, and the clip on switches for underneath the points/turnouts is a single pole slide switch only.

Is there any way I can make an input pin default/work/be = 0 when not connected (floating)? Maybe via a resistor to the negative, still allowing the "pulse" (when switched through to the other processor's output) to pull the input +?

I know what I mean. :D If you're not sure :confused::confused: I'll try and word it differently.


Thanks guys.
 

Charliem

Senior Member
Is there any way I can make an input pin default/work/be = 0 when not connected (floating)? Maybe via a resistor to the negative, still allowing the "pulse" (when switched through to the other processor's output) to pull the input +?
try using a 10K resistor tied to ground.
 

Garahbara

New Member
Eclectic,

Not sure that would help. The logic is pretty hairy.
But the code in ALL the processors is the same.

Processor A detects a train (via a threshold reading using the ADC input and LDR), and sets the signal to RED. (via LED output pin). It then sends a "pulsout" ( on standard output pin) of length "red", to tell the PRIOR signal it can turn yellow.
When a "pulse" is received, I use the "interrupt" command to process it immediately. (well, two pulses are sent. One to trigger the interrupt, and the next of particular length to indicate the signal's status).

If pulse length RED recieved, then set the signal to YELLOW, and send a pulse of length "yellow" to the PRIOR signal, which will then set itself to GREEN, and so on down the line.
Each signal, is, of course, monitoring the LDR after every "pause 500", until a "pulse" is recieved, triggering the "interrupt" immedately, and ceasing any "pause" that may be occuring at the time.

This all works beautifully, not only in theory, but in practice. Provided it is all down the one single track. It is the scenario when the prior signal is on an alternate track (the point/turnout is switched), and that "disconnects" the "input" of the prior processor, and switches to another input of another processor. It is on the disconnected processor, the input goes permanently "high", doing nothing but triggering the "interrupt" continuously.
 

Garahbara

New Member
Here's the code, Eclectic. It is the same for ALL processors. Good luck trying to follow it. Detecting the start and end of a train is not as simple as you may think. :)

Code:
'3 Aspect Signal with interrupt V 5.

' set pin symbols
symbol board_led = 7
symbol red_light_alarm = 5
symbol green = 1
symbol yellow = 2
symbol red = 3
symbol pulse_in = 3
symbol pulse_out = 4

' set switches
symbol train_entering_current_section = bit0
symbol wait_for_next_red = bit1

'set counters
symbol thru_current_detector = b1	'
symbol current_detector_count = 4 	' LDR  default = 4
thru_current_detector = current_detector_count

symbol turnout_opposed = b2
symbol turnout_opposed_count = 5  '5 in a row = turnout oppposed

symbol calibrate_check = b3
symbol calibrate_count = 10 	'default 10 


'set variables symbols
symbol adc_read1 = b4
symbol extra = b5
symbol light_meter1 = b6

' set pulsin pulsout symbols
symbol send_pulse_length = w5
symbol received_pulse_length = w6

received_pulse_length = 4

main:

	calibrate_check = 0
	gosub calibrate_lights_check
	setint %00001000,%00001000 ' set interrupt on pin 3 going high
	
determine_signal:

	pause 500
	send_pulse_length = send_pulse_length * 10 + 3
	setint off
	pulsout pulse_out,20
	pause 100
	pulsout pulse_out,send_pulse_length 'send pulse
	setint %00001000,%00001000 ' set interrupt on pin 3 going high
	readadc 1,adc_read1 'check LDR for train
	'debug
	
	if adc_read1 > light_meter1 then ' train  detected entering current section 
		if thru_current_detector = 0  then
			gosub gone_thru_red_light
		endif
		train_entering_current_section = 1
		thru_current_detector = current_detector_count
		send_pulse_length = 8 'Train entering section. This signal is red. Prior signal must be red.
		gosub set_red
		goto determine_signal
	endif
	if adc_read1 < light_meter1 and train_entering_current_section = 1 then 'train fully entered current section 
		if thru_current_detector > 0 then ' retry to ensure train fully entered section
			dec thru_current_detector
			send_pulse_length = 8 '  train might have fully entered section. This signal is red
		else
			wait_for_next_red = 1 ' set detect train entering next section
			train_entering_current_section = 0
			send_pulse_length = 6 'train is fully in sectiom. This signal is red.  Prior signal can be yellow
		endif
		gosub set_red
		goto determine_signal
	endif
	
check_next_signal:

	If turnout_opposed = 0 then 'no pulses received for turnout opposed cycles
		gosub calibrate_lights_check
		'turnout is set opposed
		'signal must be red
		send_pulse_length = 6
		received_pulse_length = 8 ' overide received pulse length
		gosub set_red
		turnout_opposed = turnout_opposed_count 'reset false alarm 
		goto determine_signal
	else	
		dec turnout_opposed
	endif
	
	if wait_for_next_red = 1 and received_pulse_length =< 6 then 'check if train entered next section
		send_pulse_length = 6
		goto determine_signal
	else
		if wait_for_next_red = 1 then
			thru_current_detector = current_detector_count '-----------------
			send_pulse_length = 6
			wait_for_next_red= 0 'train has entered next section
		endif
	endif
	
	if received_pulse_length = 8 then
		'next signal is red but train not yet cleared
		'this signal must stay red. prior signal can be yellow
		send_pulse_length = 6
		gosub set_red
		goto determine_signal
	endif
	if received_pulse_length  = 6 then
		'next signal is red, but train has cleared the signal 
		'this signal can be yellow
		send_pulse_length = 4
		gosub set_yellow
		goto determine_signal
	endif 
	
	send_pulse_length = 4  ' next signal is green
	gosub set_green		  ' this signal can be green	
	goto determine_signal
		
set_red:

	low red
	high yellow
	high green
	return

set_yellow:

	high red
	low yellow
	high green
	return
	
set_green:

	high red
	high yellow
	low green
	gosub calibrate_lights_check
	return
	
gone_thru_red_light:

	setint off
	low red,yellow,green
	'debug
	pause 3000
	setint %00001000,%00001000 '
	return
	
interrupt:
	high board_led
	
	pulsin pulse_in,1,received_pulse_length 'read pulse length
	received_pulse_length = received_pulse_length /10
	turnout_opposed = turnout_opposed_count 'reset false alarm check when pulse received
	setint %00001000,%00001000 ' set interupt on pin 5 going high
	low board_led
	return

calibrate_lights_check:

	if calibrate_check = 0 then
		readadc 1,light_meter1
		calibrate_check = calibrate_count
		extra = 255 - light_meter1 'determine difference between ambient light and complete darkness
		extra = extra / 7			
		light_meter1 = light_meter1 + extra ' set threshold to be exceeded for trigger to activate
	else
		dec calibrate_check
	endif
	return
 

slurp

Senior Member
Sounds like a variation on an axle counter...

As Charliem has suggested try tieing the input to ground with a 10K resistor, when the input is not connected to a sensor it'll not "float".

A "pull down" rather than a "pull up" went you'd like to keep input high when there's no connection. ;)

regards,
Colin
 

BeanieBots

Moderator
Using a Picaxe-20M. I've discovered that if an input pin is not connected, then it will test high. i.e.
That is only true on Tuesdays;)
If you try it again tommorow it is very likely to give a low result.
If your nextdoor neighbour turns on their flouroescent lights, then it will more than likely give you a 50Hz signal.
The biggest dependance is where you left the strongest fingerprint on the board.

Bottom line, NEVER EVER leave a used input floating. Results are unpredictable.
It is also good practice to tie down (or up) ALL inputs even if they are not used.
In most cases, as suggested several times above, a 10k to 0v will do nicely.
 

Garahbara

New Member
BeanieBots,

I have "tied" all the inputs down with a 10K resistor to "+" on the veroboard. (LDR with a 100K resistor, as per manual).

Given that, if the relevant input is connected to another processor's output. It shows low. i.e. = 0. and hence, detects the "pusles". It is when input connection to the other processor's output is broken, (switched), the input continually shows high i.e. +. I want it to show low . i.e. -.

Would tieing this input to - on the verobaord (instead of +) keep it low (i.e. - ) when the connection to the other processor's output is broken? Or would this interfere with any received "pulses"?
 

Garahbara

New Member
hmmmmmmmm..... having just thought about this..........

I might try reversing the whole pulse mechanism.

Set the output "high" to start with. The "pulsout" will go low, if initially high, or high if initally low. Hence, with initally high, the pulse will be low.

If not connected (yet tied to + with a 10K resistor), and it shows "high", the input should then also show high, regardless of whether it's connected to the other processor or not.

the "pulse" taking it low for the duration of the pulse. Otherwise the input pin is high.

wadda youse reckon?
 

BeanieBots

Moderator
Correct.
When you "disconnect" the signal which drives that input, it ends up being left floating. That must not ever be allowed to happen. Connect it to 0v via 10k resistor. When it is re-connected, the signal will drive the input as before just as if the 10k was not there.

Read my earlier post again. I was being serious.
If you change your logic so that the pulses go low but still leave the input floating, it won't work at some indeterminate time in the future when the clouds are in alignment and the current passed by the dirt on your board is no longer enough to keep the floating input high.

FLOATING INPUTS ARE AN INDETERMINATE STATE. YOU CANNOT PREDICT WHAT LEVEL THEY WILL BE AT FROM ONE MINUTE TO ANOTHER. DO NOT EVER LEAVE AN INPUT FLOATING WHEN YOU NEED TO KNOW ITS LOGIC STATE.
Is that clear enough?
 
Last edited:

Garahbara

New Member
BeanieBots,

The "input" is not "floating" per se. It is tied to + with a 10K resistor, as are all the inputs on the veroboard, used or not. It is when it is "disconnected" from the other processor, it goes continuously "high". If I make the "output" of the other processor "high" to start with, and make the pulse go "low", then connected or not, the input should show "high" in the absence of any pulses.

For constistency and neatness, I'd prefer to tie all the inputs to the same polarity. i.e. +. And as I've already made the board that way, I'll try setting the outptu "high" initially, and reversing the "pulse" mechanism to go "low" on the pulse, instead of "high".
 

BeanieBots

Moderator
Might have been useful if you had stated that clearly before!
"Disconnected" is usually used to describe something that is not connected to anything.
If you have your inputs tied high and don't want to change to pull-down then your only option is to reverse the pulse polarity as you describe.
 

hippy

Technical Support
Staff member
Keeping the pull-ups, using a low-going signal pulse and modifying the software as appropriate should get things working as desired.

Only the PICAXE connected to the one generating the low-going pulse will see that pulse ( and input will be high when there is no pulse ), the other PICAXE will always see a high input.
 

Garahbara

New Member
BeanieBots,

I just need to clarify this "floating" bizzo. From what i have read, and understand, you should "tie down" all your inputs, used or not, to keep them stable. By "tie down", I mean a 10K resistor on each input to + or -. This should keep the input stable, be it used or not?

So this is not correct?
 

BeanieBots

Moderator
I've stated it as clear as I can.
Maybe someone else can use different words to make it clearer.
 
Last edited:

Garahbara

New Member
I believe the term for "not connected" is "floating". The inputs are currently tied to the + with a 10K ohm resistor.
I did mention it in the very first post, BeanieBots.
Just "not connected" and "floating" terminology definition confusion.

All is sorted now, I think.
 

BeanieBots

Moderator
No problem, the important thing is that you have a solution.

It was this line which made me assume you meant a floating pin.
Using a Picaxe-20M. I've discovered that if an input pin is not connected, then it will test high.
You didn't discover it as such, because you had already designed it to do that by fitting a pull-up resistor.

Doesn't matter, we got there in the end.
 

westaust55

Moderator
BeanieBots,

I just need to clarify this "floating" bizzo. From what i have read, and understand, you should "tie down" all your inputs, used or not, to keep them stable. By "tie down", I mean a 10K resistor on each input to + or -. This should keep the input stable, be it used or not?

So this is not correct?

An input which has no connecting including no pull-up or pull-down resistors is a floating input.

If you are going to monitor switches and the like then you need a resistor to force the input to the opposite state when the switch is open.

While recommended by some, it is not mandatory to have unused inputs tied to + or - with resistors. Though recall some have had problems with analogue inputs when other pins on the same pot are not pulled down to 0V.
 
Top