PDA

View Full Version : Analog pins for digital input



Charles Linquis
- 8th September 2005, 05:41
I know that if a pin is configured for analog, I can't use it as a digital output, but if a pin is configured as an analog input, can I still read the pin as a digital input?

Melanie
- 8th September 2005, 08:14
Not normally if you've configured it as Analogue Input. If you need to use it as digital, you must recondfigure as such... there's no problem doing this mid-program flow.

For a concise answer, most PIC pins have a simplified block diagram of it's configuration in the Datasheet. If it looks like the pin is simultaneously connected to both analog and digital circuitry regardless, then there's no harm doing an experiment to see if it works in Digital whilst configured for Analogue.

picnaut
- 8th September 2005, 15:52
Hi,

As long as you only need to read digital "input", you can leave the pin configured as analog.

I believe TTL logic high (when using a 5 volt supply) is 2V.
So, just read your analog input and if the voltage is higher than 2V, set a logic flag high. If it's less than 2V, set the flag low.

That being said, you could just reconfigure the pin as Melanie suggested.
However, it sounds like you want to leave it configured as analog for some reason.

I'd be curious to see if you could simply read the pin's input value (not the ADC value) when it's configured as analog. It would be interesting if it registered as a 1 when the voltage was greater than 2V. You should try it.

Cheers!

mister_e
- 8th September 2005, 15:57
i never tested the above suggestion but it can work. But for safety sake i will turn them to digital.

Another solution...use ADCIN to read the pin.


If result<XYZ => pin is LOW
if result>ABC => pin is HIGH.

That will allow to determine your own HIGH/LOW threshold.

Just an idea.

Charles Linquis
- 9th September 2005, 00:32
I realize that I could just do a conversion to determine the pin's state, but I need to sit in a loop and look for a really short toggle.

The reason I have to configure it as analog is that the signal is connected to AN1, and I need to configure AN2 & AN3 as analog. The circuit is already built and I can't change the wiring.

I think the best solution is to do what Melanie suggested and configure the port as digital, read the pin, convert to analog, read channels 2&3, and switch back to digital.