28x1 PortA - both ADC and Digital ?

manie

Senior Member
I have wired PortA as below:

adc0(leg2)=analogue
adc1(leg3)=analogue
adc2(leg4)--------|
. |
. dig input---/\//\/\/\----0v
. 10k
Can I now test PortA pin2 for high/low state while still doing ADc reading on adc0 and adc1 ?

Do I need to "set" the portA pin2 to "input" or will it automatically assume a High/Low depending on the applied input voltage ?

I have looked at some older threads such as:
http://www.picaxeforum.co.uk/showthread.php?t=12901&highlight=porta
and
http://www.picaxeforum.co.uk/showthread.php?t=11994&highlight=porta
but those do not mention having to "set" the pins to digital or analogue inputs.
The manual is quite clear on how to us the pins but I am unsure of the "setting-up"......
 
Last edited:

hippy

Ex-Staff (retired)
There is no need to configure the pins; use READADC to read an analogue input and "IF PORTA <pin> = <0/1> THEN" to determine the state of a digital input.

When used as digital inputs they are TTL level sensitive. For a 4V5 supply or above, a voltage at or below 0V8 will read low, at or above 2V0 will read high. Between those the result will be unpredictable and may vary.
 

manie

Senior Member
Thanks Hippy.

I just want to tie the 5V supply to one pin to indicate module number eg. If high then= number 1, If low then = number 0. So the pin will be either pulled low via the 10k or set high (+5V supply). Is the 10k to 0V OK ?
 

westaust55

Moderator
Whether as analogue inputs using READADC or digital inputs (IF porta pin 1 . . .)

both types of signal are inputs so the is no need to use a DIRS = ... command.

There is also no BASIC commands to switch between analogue and digital so my assumption is that the BAASIC interpreter automatically handles the PIC control to change the type of input.

so just use the if port a pin 1 . . . type command

or are you having a problem ?


EDIT: looks like my typing is a bit slow tonight:rolleyes:
 
Last edited:

manie

Senior Member
Westy: No problem YET !!!! I have boldly gone where ........ and the PC board is made and drilled. I have assumed (the mother of all....) that I can switch between digital and adc by simply providing a jumper to tie the 10k to 0V. If jumper= open, then = adc, else = digital..... seems I was right (and lucky !!). Thanks.

EDIT: Tonight ???? Its early afternoon man, where do you live ? In Western Oz ???:D:D:rolleyes:
 
Last edited:

hippy

Ex-Staff (retired)
westaust55 is right, the selection between analogue and digital input is automatic, depending on command used, same for most other PICAXE chips.

The X2's are slightly different; "AdcSetup =" should be used to define which pins will be used for analogue. Even if one doesn't it still generally works though is not recommended.
 
Top