PDA

View Full Version : Cannot get comparator to work in PIC16F887



ErikOdinsvej
- 24th August 2014, 12:42
Hi - I am new in programming PIC device and I have a project where I need to use one of the two Comparators in PIC16F887


I have read the datasheet several time but is still unsure about setting up the port - hope someone can come with an solution.


in my project I use tree 7 segment display so I use interrupt to make them work and its works fine.


I do not know for sure if this gives problem for my comparator!?

(I use Pascal as my sw)

- interrupt setup:


Procedure interrupt;
begin
PORTB := 0;
PORTD := ciffer[v] + blink_on;
PORTB := zz; // turn on appropriate 7seg. display
v := v + 1;
zz := zz shr 1;
if zz = 16 then zz := 128; // 4 // prepare mask for digit
if v > 2 then v := 0; // 3 disp. // turn on 1st, turn off 2nd 7seg.
TMR0 := 0;
INTCON := $20;
end;


and my setup for the comparator:


ANSELH := 0;
// setup Port A :
TRISA :=%11011111; // input execp bit A5 - used for output for comparator
ANSEL :=%00001001; // bit A0 and A3 analog = input for comparator
CM1CON0 :=%11100000; // Comparator C1 enabled
SRCON :=%00000000; // no latch enabled
VRCON :=%00100000; // no v ref. enabled


this is the correct setting for comparator as best I know - but not sure because it not work.


here is the code where I retrieve the output


If portA.5=1 then ...


Can any help ? - do I need to do something for getting the the output


Best regards Erik Nielsen, Denmark.

mackrackit
- 24th August 2014, 12:51
I deleted your other post, in the future only post the same question once. No need to duplicate.

And

This forum deals with Pic Basic Pro. You may not get an answer for your question here.

HenrikOlsson
- 24th August 2014, 13:29
Hi,

If portA.5=1 then ...
As far as I can see comparator 1's output is on PortA.4 - not PortA.5.
And, if you're not actually driving anything with the comparator you don't need to have it "connected" to the physical output. In order to get its state you might as well read CM1CON0.6 (the C1OUT bit).

/Henrik.

ErikOdinsvej
- 24th August 2014, 16:29
Sorry for making two question, the first I make look like something went wrong - that why I posted again.
reg. pic basic pro: when I not use that sw to develobment, then I cannot use your forum ?

Best regards Erik Nielsen

ErikOdinsvej
- 24th August 2014, 16:34
Thanks for your answer - the PortA.5 was a typo error - I use PortA.4 in my sorce - I do not need to use the pin to read the result - only intern in pic but when that don't work I was trying to get it on a pin so it was visable on my develebment board.

- can you tell me if my setup of the comparator look ok ?

Best regards Erik

ErikOdinsvej
- 24th August 2014, 16:43
Just want to tell you that I get it to work now - there was nothing wrong in my code but the PIC I used was damaged - when trying new pic all works fine - thanks again

Regrads Erik

ErikOdinsvej
- 24th August 2014, 16:43
Just want to tell you all that it to work now - there was nothing wrong in my code but the PIC I used was damaged - when trying new pic all works fine - thanks again

Regrads Erik

mackrackit
- 24th August 2014, 16:54
Sorry for making two question, the first I make look like something went wrong - that why I posted again.
reg. pic basic pro: when I not use that sw to develobment, then I cannot use your forum ?

Best regards Erik Nielsen
You are more than welcome to post on this forum, I just wanted to point out that you may not get the best answers here when using another compiler.