PIC Comparator problem

Thread Starter

Bdiddy311

Joined Mar 3, 2018
6
I'm programming a pic12f675 as a simple comparator, using mplab xide and xc8 compiler. I made a voltage divider (2.5V) as an external reference, and another divider with a pot to create a voltage range of 0 to 3.7V, all verified with a multimeter. I configured CMCON as a non-inverting comparator with output (last three cmcon bits 001). It works perfectly if my main code is:

TRISIO = 0b00000011
ANSEL = 0b00000011
CMCON = 0b00000001
While (1)
{
GPIObits.GP2 = CMCONbits.COUT;
}

but it does not work if I eliminate the GPIObits line and leave the while loop empty, as I thought it should. Configuring the comparator as "with output" should simply place the comparator output at GP2 automatically, shouldn't it?
 

MaxHeadRoom

Joined Jul 18, 2013
30,658
I don't use C but if you look through the Gooligum Tutorials he shows a comparitor examples for the 12F675 I believe in Assy and C.
Max.
 

Thread Starter

Bdiddy311

Joined Mar 3, 2018
6
Try without the ADC module... I don't think its connected.. The comparators were on pics before the ADC..
Yes, sorry, forgot to include in my post that I also set ADCON to 0 to disable ADC. I had an 'aha!' moment when I read in the '675 data sheet that while comparator is in an output mode the TRISIO <2> bit acts as an enable/disable bit for the comparator output, so I changed trisio <2> to a 1, but it was still a no-go.
 

Thread Starter

Bdiddy311

Joined Mar 3, 2018
6
No... That's my point.. They are bien directed to the ADC even if its turned off..
Success, thank you so much, it was driving me nuts. Wasn't realizing that ansel isn't associated with the comparator module. I knew it was something simple I was overlooking, thanks again!
 

Thread Starter

Bdiddy311

Joined Mar 3, 2018
6
That was the problem, though. The output wasn't present at gp2 without that statement, until I set ansel to 0 as you suggested, then it worked fine with an empty while loop.
 

Picbuster

Joined Dec 2, 2013
1,058
I'm programming a pic12f675 as a simple comparator, using mplab xide and xc8 compiler. I made a voltage divider (2.5V) as an external reference, and another divider with a pot to create a voltage range of 0 to 3.7V, all verified with a multimeter. I configured CMCON as a non-inverting comparator with output (last three cmcon bits 001). It works perfectly if my main code is:

TRISIO = 0b00000011
ANSEL = 0b00000011
CMCON = 0b00000001
While (1)
{
GPIObits.GP2 = CMCONbits.COUT;
}

but it does not work if I eliminate the GPIObits line and leave the while loop empty, as I thought it should. Configuring the comparator as "with output" should simply place the comparator output at GP2 automatically, shouldn't it?
look at :
www.microchip.com/PICMCUComparatorTipsnTricks1243
https://electrosome.com/analog-comparator-pic-microcontroller

it might help you.

Picbuster
 
Top