• AVR Freaks

Hot!CMCON0 and ANSEL registers

Author
HighTechPower
Starting Member
  • Total Posts : 46
  • Reward points : 0
  • Joined: 2021/01/27 01:35:43
  • Status: offline
2021/03/06 14:22:05 (permalink)
0

CMCON0 and ANSEL registers

Hi. Recently I designed a circuit with PIC12F683. It's pins not working properly until I declare CMCON0 register although I'm not using it's internal comparator. Is it not true that to declare pins as digital or analog I have to use either CMCON0 or ANSEL register and not both. However when I omit the CMCON0 line in code below then circuit does not work properly (e.g. POWER_GOOD pin does not go high). I'm using ADC that is why I have declared ANSEL register.
 
#define POWER_GOOD GP0
------------------------------------
void init_micro (void)
{
    OSCCON = 0b01100111;
    TRISIO = 0b00001010;
    CMCON0 = CMCON0 | 0b00000100;
    ANSEL = 0b01010010;
    GPIO = 0b00000000;
    POWER_GOOD = TRUE;
    __delay_ms(100);
}

#1

3 Replies Related Threads

    GilJ
    Super Member
    • Total Posts : 119
    • Reward points : 0
    • Joined: 2011/04/05 02:36:47
    • Location: 0
    • Status: offline
    Re: CMCON0 and ANSEL registers 2021/03/06 16:26:13 (permalink)
    0
    The datasheet does mention that you need to initialize both ANSEL and CMCON0 registers to configure an analog channel as a digital input. See GPIO chapter...
    #2
    upand_at_them
    Super Member
    • Total Posts : 788
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: offline
    Re: CMCON0 and ANSEL registers 2021/03/06 18:09:04 (permalink)
    0
    Please read the register details.  In my copy of the datasheet it's "REGISTER 8-1: CMCON0: COMPARATOR CONFIGURATION REGISTER".  It tells you what the default (reset) value of the register is.  And the "comparator mode bits" part tells you what you may want to set it to in your init() routine.
     
    #3
    1and0
    Access is Denied
    • Total Posts : 12265
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: CMCON0 and ANSEL registers 2021/03/06 21:41:12 (permalink)
    0
    HighTechPower
    Hi. Recently I designed a circuit with PIC12F683. It's pins not working properly until I declare CMCON0 register although I'm not using it's internal comparator. Is it not true that to declare pins as digital or analog I have to use either CMCON0 or ANSEL register and not both. However when I omit the CMCON0 line in code below then circuit does not work properly (e.g. POWER_GOOD pin does not go high). I'm using ADC that is why I have declared ANSEL register.

    Then use the CMCON0 register to turn off the comparator and use the ANSEL register to select analog/digital for the pins.
    #4
    Jump to:
    © 2021 APG vNext Commercial Version 4.5