PIC18F13K22 comparator problem


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    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.

  2. #2
    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

  3. #3
    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 : 0

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