Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ANSELx and digital outputs?

Status
Not open for further replies.

AGCB

Member
I'm trying to understand the use of the ANSELx registers on a 18F46K22. I read that the ANSEL registers do not affect digital outputs. What type of situation could there be where you would want a digital output and an analog input on the same pin? Doesn't the TRISx bits determine this anyway?

And concerning the PBADEN bits in the config settings, Doesn't setting or clearing the ANSELB bits over ride those settings? So, why set or clear PBADEN bit anyway?

I have read and reread the data sheet but still don't have a good grip on this (actually no grip at all !!) . If there's an easy explanation, I'd like to hear it. Thanks Aaron
 
ANSEL simply determines whether you want that particular pin to be digital or analog.

If you want it to be a digital input or output, then clear the appropriate ANSEL bit. If you want it to be an analog input (including comparator and VREF inputs), then set ANSEL.

The tables for each port (for example table 10-1: PORTA I/O Summary) will tell you whether you need the ANSEL bit set or not for your particular purpose.
 
If you set a bit in ansel, as mentioned that pin becomes an analogue in, this overides the tris bit, so no matter what the pin allready is it becomes an analogue in.
Its good practice however to set the i/o as an input before using it as an analogue.

I've never done it but you could have an analogue and a digital i/o on the same pin, you might do that for a component tester project or the like.
 
Last edited:
The tables for each port (for example table 10-1: PORTA I/O Summary) will tell you whether you need the ANSEL bit set or not for your particular purpose.

For some reason I had completely skipped over that use of the table.

So if most of my projects are digital, I can just clear all of the ansel bits in the main init program and then set them differently when I init a A/D for example?

Thanks Gobbledoc and dr peppers for the help
 
So if most of my projects are digital, I can just clear all of the ansel bits in the main init program and then set them differently when I init a A/D for example?

Yep that's all I do.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top