Comparators

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Comparators

Post 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

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Comparators

Post 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

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: Comparators

Post 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

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: Comparators

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

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Comparators

Post 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

Post Reply