Comparator not tripping above 0.6V (Vref) on PIC 16F690


+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french part)
    Posts
    731

    Default Comparator not tripping above 0.6V (Vref) on PIC 16F690

    Hi All,

    I'm struggeling to get my 16F690's comparator 2 output to trip when the measured voltage gets above 0.6V (for battery level monitoring).

    Code:
    ' ====== FUSES =====================================================================================
    @ __config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_INTRC_OSC_NOCLKOUT &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF
      
    ' ====== REGISTERS =================================================================================
    ' Registers   76543210
    OPTION_REG = %10000000 ' PORT A&B Pull-Ups and Prescaler        (def.: %11111111)
    OSCCON     = %01100000 ' Internal Oscillator 4MHz               (def.: %01101000)
    TRISC      = %00001000 ' Set Input/Output (0 to 7)              (def.: %11111111)
    
    CM2CON0    = %10100011 ' Comparator2 Module                     (def.: %00000000)
    ' Bit1/C2ON = Comp C2 is ON
    ' Bit5/C2OE = Output is PORTC.4
    ' Bits1-0   = Input is PORTC.3
    
    VRCON      = %00110000
    ' Bit2/C2VREN = Comparator C2 voltage ref is ON
    ' Bit4/VP6EN  = 0.6V ref is ON
    
    ' ====== DEFINES ===================================================================================
    DEFINE OSC 4
    
    ' ====== PROGRAM START =============================================================================
    MAIN:
        GOTO MAIN:
    END


    These are the registers:

    Name:  000242.png
Views: 42
Size:  75.1 KB
    Name:  000240.png
Views: 41
Size:  57.0 KB


    And this is my PIC:
    Name:  000243.png
Views: 39
Size:  66.7 KB

    My voltage divider (that comes from Vbatt) is connected to PORTC.3 and I'm expecting the PORTC.4 (C2 output pin) to trip when Vbatt exceeds 0.6Volts, but this nevers happens.

    What am I missing please?
    Last edited by flotulopex; - 22nd May 2020 at 22:44.
    Roger

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    1,610

    Default Re: Comparator not tripping above 0.6V (Vref) on PIC 16F690

    this works if you mean "trip pin" means pin is set when below 0.6v and cleared when over



    #CONFIG
    __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOD_ON & _IESO_ON & _FCMEN_ON
    #ENDCONFIG

    ' ====== REGISTERS ================================================== ===============================
    ' Registers 76543210
    OPTION_REG = %10000000 ' PORT A&B Pull-Ups and Prescaler (def.: %11111111)
    OSCCON = %01100000 ' Internal Oscillator 4MHz (def.: %01101000)
    TRISC = %00001000 ' Set Input/Output (0 to 7) (def.: %11111111)
    led var portc.0 ; proof of life
    CM2CON0 = %10100111 ' Comparator2 Module (def.: %00000000)
    ' Bit1/C2ON = Comp C2 is ON
    ' Bit5/C2OE = Output is PORTC.4
    ' Bits1-0 = Input is PORTC.3
    ;bit2 connect c2+ to fvr output
    ansel.4=0 "just to prove c2+ is not connected to this
    VRCON = %00110000
    ' Bit2/C2VREN = Comparator C2 voltage ref is ON
    ' Bit4/VP6EN = 0.6V ref is ON

    ' ====== DEFINES ================================================== =================================
    DEFINE OSC 4

    ' ====== PROGRAM START ================================================== ===========================
    MAIN:
    toggle led ; proof of life
    pause 1000
    GOTO MAIN:
    END
    This is more entertaining than Free to Air TV

  3. #3
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french part)
    Posts
    731

    Default Comparator not tripping above 0.6V (Vref) on PIC 16F690

    Thanks Richards,

    Sorry, maybe the word "trip" is not adequate (I'm speaking french)

    BTW, what would be the correct word: "latching"?

    I found this interresting video which made me start to try battery monitoring:

    .

    Unlike the video, I started with a 2 resistors divider. But a potentiometer (maybe easier for a start) and a corrected register CM2CON0 as you suggested made it work.

    So, I missed this one you kindly pointed me to:
    Name:  000246.png
Views: 28
Size:  7.9 KB

    Finally, the "shortest possible" working code for a 0.6Volt threshold detection could be:
    Code:
    TRISC      = %00001000 ' Comparator's input port
    
    CM2CON0    = %10100111
    ' Bit7     = comparator 2 is ON
    ' Bit5     = comparator's output pin (i.e. LED) is PORTC.4 (for "proof of life")
    ' Bit2     = connect Vref to C2Vin+
    ' Bits1:0  = comparator's input pin (i.e. Vbatt) is PORTC.3
    Roger

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    1,610

    Default Re: Comparator not tripping above 0.6V (Vref) on PIC 16F690

    Sorry, maybe the word "trip" is not adequate (I'm speaking french)


    BTW, what would be the correct word: "latching"?
    the only problem with it is that the comparator state can be programmed to be high or low on either side of the transition point
    the word trip conveys no indication of preference
    This is more entertaining than Free to Air TV

Similar Threads

  1. 16F690 VREF PGC question
    By dsicon in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 2nd February 2014, 16:14
  2. Replies: 2
    Last Post: - 31st May 2013, 18:19
  3. 18F2525 A/D, Comparator and Vref modules
    By fbraun in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 20th May 2005, 23:17
  4. accurate vref < 1vdc 16F876 comparator
    By mslaney in forum Schematics
    Replies: 1
    Last Post: - 23rd March 2005, 01:44
  5. switching external vref+ and vdd vref
    By alejandro_halon in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th February 2005, 20:13

Posting Permissions

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