TTL input - 3rd states possible?
Hello,
I was asking myself about the possibility of using any TTL input of my PIC to "read" 3 different levels.
Roughtly, for TTL values, the LOW level is from 0V to 1V and the HIGH is from 3,5V to 5V.
Assuming this is not completely wrong, would it be possible to read 3 different states on the PIC?
I tried to make it a simple way with a 2 resistor divider between Vdd and Vss. The middle point of the divider is logically connected to the pin.
Two buttons are parallel connected each to a resistor.
In theory, I can simulate 3 states:
1.- 0V (if button "A" is pressed)
2.- something around 2V (no button is pressed)
3.- 5V (if button "B" is pressed)
I can't achieve to read state 2.- but is it really possible... or am I dreaming?
Just tried - didn't want to go to bed frustrated...
Well,
I've still got one led always ON.
In my understanding, I should get a state where no Led is ON.
Is this correct?
1 Attachment(s)
Not tested hastily made after reading post
Hi,
This is just an idea using the MChip Tips n' Tricks. No timer, no comparator just an idea. Flotulopex please test it out. Others on the forum please comment if it is crap.
Attachment 1507
Code:
READ_SWITCH:
TRISA.0 = 0 ' MAKE THE PIN AN OUTPUT
PORTA.0 = 0 ' MAKE IT LOW
PAUSE 100 ' WAIT FOR THE CAPACITOR TO DISCHARGE
TRISA.0 = 1 ' MAKE THE PIN AN INPUT
PAUSE 100 '
IF PORTA.0 = 1 THEN SWITCH_HIGH '
LED1 = 0 ' DEFINATELY NOT HIGH
TRISA.0 = 0 ' MAKE THE PIN AN OUTPUT
PORTA.0 = 1 ' MAKE IT HIGH
PAUSE 100 '
TRISA.0 = 1 ' MAKE THE PIN AN INPUT
PAUSE 100 '
IF PORTA.0 = 0 THEN SWITCH_LOW '
LED0 = 0 ' DEFINATELY NOT LOW
GOTO READ_SWITCH
SWITCH_LOW:
LED0 = 1
GOTO READ_SWITCH
SWITCH_HIGH:
LED1 = 1
GOTO READ_SWITCH
P.S. - The code can be made shorter!! :D
Time for your schematic and entire code
Hi,
It is possible. Did you connect your PIC according to the schematic I provided. <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1507&d=1175158348" align="absmiddle">Try increasing the pause. Please post your entire code and schematic. It is possible in one way or the other. I have chosen the Digital way. Detecting multiple switches with one pin is also possible using the ADC. By the way the circuit doesn't work when both the switches are pressed simultaneously. The 1K resistors are provided for that purpose so that you don't blow up your PS. When both are pressed most likely your PIC would read a logic high. As you get 1/2VDD and @ 5 volts it is good enough to be a logic 1. In any TTL/CMOS gate your cannot have anything other than 0 or 1 in your output whether your inout is at 0,1 or Z. So software tricks does it. By switching your port pin between input and output and detecting the holding capacitors state. I repeat please post your exact code and schematic and it should work.
Let me clarify my understanding about your requirement.- You need to use only one pin of your PIC.
- You need to connect 2 switches to that.
- You need to determine whether your input is hanging idle (Z)
- Switch connected to VDD was pressed (H)
- Switch connected to VSS was pressed (L)
I am waiting.