PDA

View Full Version : A/D versus Digital I/O



dallennn
- 31st October 2006, 01:17
I am using PBPro programming the 16F876 for both analog and digital use. I see that the command ADCON1 needs to be set for these purposes. I need 1 A/D channel and as much digital I/O as I can get. Is there a way - or how do I set up the ADCON1 command to enable A01 as the analog input and A02-A05 as digital?
Do I also have to set up any other command?

sayzer
- 31st October 2006, 08:26
Take a look at this post first.
http://www.picbasic.co.uk/forum/showthread.php?t=4880

And try to come up with a register setting and then post it here.

We can then check if you made it right or wrong.

So you can understand how to make it.





---------------------------------------

peterdeco1
- 31st October 2006, 10:28
Hi Dallennn & Sayzer. I use the ADC's on 16F872 frequently. I just make them all digital, then declare the input. When you use the adcin command, it automatically converts it to a byte size analog input. Example using ra0 as ADC input:

trisa = %00000001 'ra0 input
adcon1 = 7 'all inputs digital
x var byte 'place to put the ADC reading

start:
ADCIN 0,X 'read adc value & put into x

sayzer
- 31st October 2006, 11:01
Hi peterdeco1,

Never tried that before.

Sounds a quick jump to actual reading procedure.

Since you say you have done it and it works, I now learn something new.

Thanks for the info.


----------------------

dallennn
- 7th November 2006, 12:46
Hi peterdoco1 and Sayzer,

Peterdoco1, I first tried your solution and it worked! And that is:
trisa = %00000001
adcon1 = %00000111

Sayzer, I then looked at and tried your solution and it worked! Your solution was to look at the register table for adcon1 and find the the values for that which I wished to do which is: ra0 = analog and ra1-5 as digital. This gave me a value of:
trisa = %00000001
adcon1 = %00001110
Is that what you would have used?
I did have one small problem getting ra4 led to turn on until I remembered that ra4 is open drain.

dallennn

peterdeco1
- 8th November 2006, 18:14
Hi Dallennn. You said ...ra0 = analog and ra1-5 as digital. This gave me a value of:
trisa = %00000001
adcon1 = %00001110

As I mentioned previously, I always let the software do the work for me and will work for word variables too. But one thing I see in your post above is the trisa register is set for ra0 input, the rest all outputs.

sayzer
- 8th November 2006, 19:47
dallennn,

TRISA = %00000001 will set RA0 as an input and all others as output pin as you know. So this is ok.

ADCON1= %00001110 will set RA0 as an analog pin and all others as digital pin. This is also as you needed. So it is ok.

Thus, so far you have an analog input pin at RA0 and all others as digital output pins.

One thing to remember is Bit7 anf Bit6 of ADCON1. Depending on your ADC resoultion, you need to set Bit7.

Another thing is Bit6 and this will be set by your DEFINE directive automatically.


-----------------------------

dallennn
- 11th November 2006, 04:31
Hi peterdoco1 and Sayzer,

Sayzer, I know to set ADCON1 bit 7 for left or right justify. All I needed was 8 bit resolution so I set the bit to 0. I couldn't find anything on bit 6 but.........
I think I now have enough information to be dangerous.
Thanks for both of your help.
Dallennn