Cannot get comparator to work in PIC16F887


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2014
    Location
    Denmark
    Posts
    5

    Default Cannot get comparator to work in PIC16F887

    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.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Cannot get comparator to work in PIC16F887

    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.
    Last edited by mackrackit; - 24th August 2014 at 12:53.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Cannot get comparator to work in PIC16F887

    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.

  4. #4
    Join Date
    Aug 2014
    Location
    Denmark
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: Cannot get comparator to work in PIC16F887

    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

  5. #5
    Join Date
    Aug 2014
    Location
    Denmark
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: Cannot get comparator to work in PIC16F887

    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

  6. #6
    Join Date
    Aug 2014
    Location
    Denmark
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: Cannot get comparator to work in PIC16F887

    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

  7. #7
    Join Date
    Aug 2014
    Location
    Denmark
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: Cannot get comparator to work in PIC16F887

    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

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Cannot get comparator to work in PIC16F887

    Quote Originally Posted by ErikOdinsvej View Post
    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.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Replies: 2
    Last Post: - 31st May 2013, 18:19
  2. help with pic16f887
    By lerameur in forum mel PIC BASIC Pro
    Replies: 60
    Last Post: - 11th December 2010, 21:38
  3. PIC16F887 and DS1307
    By menta in forum General
    Replies: 21
    Last Post: - 29th September 2008, 17:05
  4. PIC16F887, turn off..
    By xobx in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 18th October 2007, 05:55

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts