PDA

View Full Version : Setting Up Adc Ports



GEEZER
- 21st August 2005, 02:12
I switched from a 16F887a to 18F4610. I have everything running including a serial output controlling a dual pot.

My problem is always those darn adc ports. I need to set up and read analog on porta 0 -7. I get strange readings or nothing at all. I had it working fine on the 877A, but can't make the transition on the 4610.

A little sample code would be great. I admit I don't grasp the adcon settings, any simplified explanation would help, with examples. Maybe I can get my mind around these adcon settings.

Thanks,

Geezer

rhino
- 21st August 2005, 06:53
Hey Geezer -
One example that really helped me learn what to look for and how to read the data sheet for the A/D modules is HERE. (http://www.rentron.com/PIC12C67XAD.htm) I realize it's not the same micro you're working with, but Bruce does point out some very important steps on how to set up the A/D module. I haven't worked with the Pic 18x's yet, so I'm not even going to try to code anything without testing it. All I can say, is get to know the data sheet. Just by taking a quick look, it says
The module has five registers:
• A/D Result High Register (ADRESH)
• A/D Result Low Register (ADRESL)
• A/D Control Register 0 (ADCON0)
• A/D Control Register 1 (ADCON1)
• A/D Control Register 2 (ADCON2) ADCON0 controls turning on/off the ADC module starting the conversion indicating which channel to read ADCON1 voltage reference configurations AD port configuration bits ADCON2 contains the result format acquistion time selection the conversion clock selection ADRESH & ADRESL, of course hold the result from the A/D conversion. Chances are you'll have to do something with each one of these registers, depending on how you want to execute the A/D conversion. Sorry I don't have a cut & paste example for you, but maybe I've helped steer you in the right direction in figuring out the ADC module.http://www.picbasic.co.uk/forum/images/icons/icon12.gif

peterdeco1
- 21st August 2005, 09:33
If I may put my 2 cents in here, I use A/D converters all the time. However, I don't "set up" anything except tell the device to turn all A/D ports to digital on boot. On 12F675 I use ANSEL = 0. On 16C72A, 16F72 and 16F818, I use ADCON1 = 7. Then, I simply use the ADCIN command and it works every time for a 0-255 reading. ADCIN 0, X will read ANA0 and put value into BYTE variable X. And if Anyone here knows why I shouldn't do it this way, please let me know. Thank you. - Peter

GEEZER
- 21st August 2005, 18:50
Thanks for the input guys. Peter, I am glad it is working out so easily for you.

I have it running now. I just ignored ADCON0 and set ADCON1 and 2. I think I know what i did to turn on 4 of the ports i need right now. We'll see how smart i am when i need to turn on the next 4.

Thanks again, I get a lot of help and good ideas from the forum.

The Geezer

rhino
- 22nd August 2005, 03:04
if Anyone here knows why I shouldn't do it this way, please let me know. Thank you. - PeterMore than one way to skin a cat. Sure the ADCIN command can be used and probably work just fine, and get him up and going quickly. I like using the ADC registers directly to understand what's all involved. Which from Geezer's post, I was under the impression he was after this as well. Other people also do this for speed and efficiency. Instead of telling someone to RTFM... I try to point them in the direction of examples and where to look in the manual to learn what they are after. Just a personal preference. Glad you got your project going Geezer... and hopefully you have a better understanding of the ADC module.