• 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.

PIC 16F628A comparator unused I/O pins

Status
Not open for further replies.

BobW

Active Member
It's not clear in the documentation that if you have the comparator config register set up to enable only one of the two comparators, whether the unused I/O pins can be used for regular digital I/O functions.

For example, if I set CMCON=0x05 then comparator 1 is disabled and comparator 2 is enabled. I would like to use RA0 and RA3 (otherwise assigned to comparator 1) as digital I/O. Is this possible?
 

be80be

Well-Known Member
If you look at page 64 figure you have to use 2 pins it shows how they are laid out. the rest can be I/o pins
 

BobW

Active Member
Thanks. I had referred to page 64 of the data sheet, but it never states clearly that the unused comparator pins are available to be used as regular I/O. I also checked the PIC Mid-Range MCU Family Reference Manual, and couldn't find anything definitive there either. I realize it's logical to assume that the unused pins would be available, but I seem to recall making similar assumptions in the past which proved to be wrong.
 

BobW

Active Member
Okay, after reading the data sheet one more time, I finally found what I'd been missing. Just in case others have had similar problems and are as unobservant as I am, I've attached an excerpt from the data sheet with the important parts outlined in red, for future reference.

Comparator.png
 

BobW

Active Member
Now I have another problem. I've configured the PIC to enable a single comparator (comparator 2) using mode 101, but for some reason the non-inverting input (aka, RA2/AN2/Vref) appears to be operating as an output. I've configured the TRISA register so that it is an input. I've configured the VRCON register to all zeroes to disable the Vref output. But that pin still comes up in a low impedance state, on power up randomly as 0v or +5v with enough power to drive an LED. I thought maybe I fried the chip, so I substituted another one, and it behaves the same way. I can't see anything in the docs that would affect this pin. Is there some other configuration register that I've overlooked?
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
Have some code??? The according to the datasheet, it would seem ... RA2 and RA1 should be inputs and C2 is the output!!! However!! Remember this is an opamp... RA2 and RA1 are a virtual ground!! You will see the same voltage on RA2 as RA1 if RA2 isn't connected....
 

Pommie

Well-Known Member
Most Helpful Member
Pause your code and make sure that TRISA is set correctly. It's easy to miss it if you get the bank switching wrong.

Mike.
 

BobW

Active Member
It may have been a MPLABX issue. After my last post, I noticed that the PICkit3 programmer started behaving strangely. So, I shut everything down and rebooted MPLABX. I downloaded the program to the PIC again, and gave it a quick run. It was too late at night to do any serious testing, but it appeared that the input problem might be fixed. I'll do more testing later and report back.
 

BobW

Active Member
Well it turned out to be a simple problem, and now I have another item to add to my PIC gotcha list. Before I rearranged the I/O in order to use the comparator, I made a copy of the project so that I could return to it if the need arose. Then I modified the source code of the new project. However, I forgot to set the new project as the main project. So, whenever I made a change to the new source code, it was still assembling and downloading the code from the old project.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
Well it turned out to be a simple problem, and now I have another item to add to my PIC gotcha list. Before I rearranged the I/O in order to use the comparator, I made a copy of the project so that I could return to it if the need arose. Then I modified the source code of the new project. However, I forgot to set the new project as the main project. So, whenever I made a change to the new source code, it was still assembling and downloading the code from the old project.
Yeah!! Been there before! Takes quite a while for the penny to drop... I'm glad you found it..
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top