Drawing a blank on trigger pin polarity
Hello,
I currently am using a dual optocoupler to trigger an input on my pic. One LED is set to be a positive trigger while the other is set to be a negative trigger. They both pull one input on my pic to ground.
I am trying to consolidate my components and wires to be just one wire. What I am seeking to do is have a wire that when left unconnected, will do nothing. If either a positive or negative is applied to this wire, then the input it is connected to will be triggered.
I've seen other boards that use an input wire, but in order to select the trigger polarity, you must use jumpers.
Thoughts that I came up with would be to use the AD input and setup a voltage divider and have it connected to the trigger wire through a resistor.
So in essence, the AD input would see one value through the voltage divider. If the trigger wire was applied to ground, theoretically, the AD value would change. If a positive voltage is applied, then the value should change again.
In my head, this seems like it would work. Does anyone see a problem with this, or am I missing something?
Thanks,
Tony
1 Attachment(s)
Re: Drawing a blank on trigger pin polarity
That will work just fine Tony.
The one A/D input can be used to monitor and trigger to many levels of the input range within tolerance, but your application is a snap with only three states: Max A/D, Mid A/D and Min A/D.
Here's an example using a three state momentary switch:
Attachment 7110
Just make sure the switching value being monitored will not damage your uC.
Now a simple routine can monitor and do what you need:
Code:
SW_1 VAR BYTE ' A/D setup with 8bit
ADCIN 0, SW_1 ' Assuming PIC Vdd is 5V and using A/D input 0
SELECT CASE SW_1
CASE IS < 26 ' Input less than 0.50V
' Do something
CASE IS < 135 ' Input less than 2.64V
' Do something else or nothing at all
CASE IS > 135 ' Input more than 2.64V
' Do something
END SELECT
Re: Drawing a blank on trigger pin polarity
That initially was my thought, but my dilemma is the initial ADC supply will be 5 volts from the VR, but my input is 12 volts. I was thinking of putting a voltage divider on the input wire to supply 5 volts to the ADC pin like you show, but not sure if that would work right or what might happen when the ground signal is applied. Was thinking to maybe add a 5V Zener, but I think when the input is "floating", the ADC will find ground through the Zener.
By the way, does ADC code run in the background like an interrupt would, or does it run in sequence like any other code? Reason being is that I am running other code on the chip right now, so that would have to be one more routine to run.
Thanks,
Tony
1 Attachment(s)
Re: Drawing a blank on trigger pin polarity
This schematic shows what I think you mean and might work for you.
Attachment 7112
The 22K is the recommended value when connected directly to RS232 voltage levels like this. The uC internal protection diodes already clamp the input signal to Vdd so the Zener is a safe option and won't start to conduct until the input approaches the rated value.
I can't remember my voltage divider formula when it comes to introducing the 12V like this, but the results will be:
Switch OFF : Vout = 2.5V
Switch 12V : Vout = Somewhere between 2.5V and 5V
Switch GND: Vout = Somewhere between 2.5V and GND
Maybe someone can fling it mathematically or plug the values into their Proteus simulator to help me out. :smile:
As far as the A/D module running in the background. It does, but you still have to start it with some code and I believe the only interrupt indication you get is the ADIF when the read is complete which is pretty fast anyways, in the us.
Re: Drawing a blank on trigger pin polarity
Got a hold of a simulator and plugged in the circuit. Actually just drew out the same circuit you had, but I had the input pin at 10K and I have a diode on the 5 V supply line to prevent any back flow if the circuit is ever turned off. With my diode in place and using the 22k resistor, I came out to:
Switch OFF : Vout = 2.18 V
Switch 12V : Vout = 4.01 V
Switch GND: Vout = 1.77 V
Thank you so much for your help.