PIC18F13K22 comparator problem


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005
    Location
    France
    Posts
    50

    Default PIC18F13K22 comparator problem

    Hi,

    May be it's because I don't understand the data sheet ?
    I'm trying to compare with 18F13K22
    My ref is connected to portA.1 (C12IN0-)
    The other signal connected to portA.0 (C1IN+)

    Doesn't work

    Here is my code:

    ANSEL = %00000011
    ANSELH = %00000000
    TRISA=%11111011 ' Set Inputs
    TRISC=%00000000 ' Set Inputs
    TRISB=%00000000 ' Set Inputs
    CM1CON0 = %1000000

    C1OUT VAR CM1CON0.6

    mainloop:
    IF C1OUT = 1 THEN
    HIGH PORTB.6
    ELSE
    LOW PORTB.6
    endif
    PAUSE 200
    goto mainloop
    END

    Thank's for help

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: PIC18F13K22 comparator problem

    As crazy as it seems, you want to disable the ADC on these specific pin, but enable the comparator. it also seems you miss a bit in your CM1CON0 register?

    Give this a shot
    Code:
            C1OUT VAR CM1CON0.6
     
            PORTA = 0
            PORTB = 0
            PORTC = 0
     
            TRISA = %00000011 'PORTA<1:0> = Input
            TRISC = 0 
            TRISB = 0 
     
            ANSEL = 0 ' Disable 
            ANSELH = 0 ' All ADCs
     
            CM1CON0 = %10001000
                    ' -1-------- C1ON: Enable comparator 1 
                    ' --x------- C1OUT: Read only
                    ' ---0------ C1OE: C1OUT set to internal 
                    ' ----0----- C1POL: C1OUT Logic not inverted
                    ' -----1---- C1SP: Operate in normal power mode
                    ' ------0--- C1R: C1Vin+ Connected to C1IN+ (A.0)
                    ' -------00- C1CH<1:0>: C1Vin- connected to C12IN0- (A.1)
    MainLoop:
            LATB.6 = C1OUT
            PAUSE 200
            GOTO MainLoop
    END
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Sep 2005
    Location
    France
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: PIC18F13K22 comparator problem

    Thank you Steve !

    Yes it's crazy to disable the ADC... I realized the opposite of what is written in the data sheet. (may be because it's in English ?)

    Ok, now it's working fine.

    I have a question to ask you. What is "LATB.6" ? (This is true for any LAT(PORT number)?

    Regards

    Herve

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: PIC18F13K22 comparator problem

    In fact it is crazy ... or not. You want to set a specific I/O to use ONLY what you want to. Sure we read analog thing... but with the comparator.. not the ADC... ANSEL & ANSELH set a pin as analog to use with tthe internal ADC... kinda thing to understand/remember.

    I realized the opposite of what is written in the data sheet. (may be because it's in English ?)
    Fais-toi en pas avec ça... avec un peu de pratique, le tout deviendra plus clair

    I have a question to ask you. What is "LATB.6" ? (This is true for any LAT(PORT number)?
    LATx is the output PORT Latch. Usually with PIC18 (and all other PIC with LATx register) you want to write to LATx, but read from PORTx. In THIS specific case, you shouldn't experiment any problem if you use PORTB.6, but it's something to keep in mind.

    On apprends les bonne habitudes en premier
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Members who have read this thread : 1

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

Posting Permissions

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