Page 1 of 1

Comparators

Posted: Sun Sep 11, 2011 7:52 pm
by Jan Lichtenbelt
Hello,

I want two comparators with internal reference voltage for e.g. PIC16F877A
http://ww1.microchip.com/downloads/en/D ... 39582b.pdf
The CVRON Control register gives me the wanted reference voltage (see chapter 13) and the comparator register CMCON (CIS=CM3) tells me which 2 inputs I can use (=0 for RA3 and RA2 or =1 RA0 and RA1). The output of the comparators can be read from CMCON bit 6 and 7 (CM6 and CM7).

Now I want to use these outputs in the software only and preventing them to come on the outputs RA4 and RA5.

Now my question: How do I prevent that the the comparator-outputs comes on RA4 and RA5? Just by setting trisa?
But if I set RA4 and RA5 as output, can I use RA4 and RA5 as ouptput for other reasaons? Or will RA4 and RA5 as output always comparator outputs?

With kind regards

Jan Lichtenbelt

Re: Comparators

Posted: Sun Sep 11, 2011 10:30 pm
by Spanish_dude
Hi Jan,

I read the datasheet (chapter 13) and they don't seem to say that when using the comparator you can't use RA4 and RA5 as 'normal' I/O.

I'd suggest you to leave RA4 and RA5 as inputs (with trisa) and when you need to output something on those I/O, turn them back to output, but also, disabling the comparator.
Once you're done, set RA4 and RA5 back to input and enable the comparator.

Nicolas

Re: Comparators

Posted: Mon Sep 12, 2011 11:17 am
by Jan Lichtenbelt
Dear Nicolas

The problem is that I want RA4 and RA5 to use as outputs for other purposes and at the same time I need the 2 comparators (form which I read outputs from CMCON register).

Kind regrads

Jan

Re: Comparators

Posted: Mon Sep 12, 2011 11:52 am
by Sean
The selection of RA4 and 5 as comparator outputs is based on the CM2:0 mode bits.

The modes listed as 'with Outputs' in the Comparator I/O Operating Modes table (Figure 12-1 in my copy of the 877 data sheet) control the I/O. The remaining modes leave the I/O unaffected.

The multiplexers that controls the I/O can be seen in the schematics for RA4 and 5 in the I/O Ports section of the data sheet. This is more informative than the comparator table.

Re: Comparators

Posted: Mon Sep 12, 2011 1:51 pm
by Spanish_dude
Hi,
I haven't checked that chapter yesterday, but it seems that setting CM2:0 to 010b will allow you tu use the comparator without outputs.
Thanks Sean :).

Nicolas