pic18f24k20 errata

Discussion in 'Embedded Systems and Microcontrollers' started by bug13, Jun 27, 2016.

  1. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    Hi guys

    I am using this chip pic18f24k20, and I need to use RA3 as input. But if RA3 is pull low, it reset/hang my chip. My code seem to work when RA3 is pull high only.

    Unfortunately I can't use other pin as this is the only pin left.

    According the errata of this chip, I need to do something with the comparator input (which RA3 shares), I have tried a few thing but can't fix it.

    Here is the errata:
    Capture.PNG

    here is my code:
    Code (Text):
    1.     ANSEL = 0x00;          // disable digital input buffer
    2.     ANSELH = 0x00;         // disable digital input buffer
    3.  
    4.     HLVDCONbits.HLVDEN = 0;     // disable high/low-voltage detection
    5.     SSPCON1bits.SSPEN = 0;      // disable ssp
    6.     CM2CON0bits.C2ON = 0;       // disable comparator 2
    7.     CM1CON0bits.C1ON = 0;       // disable comparator 1
    8.     ADCON0bits.ADON = 0;        // disable ADC
    9.  
    10.     // these code deal with errata
    11.     // 22. Module: Comparators
    12.     TRISAbits.TRISA3 = 0;       // output
    13.     LATAbits.LATA0 = 1;         // high
    14.     __delay_ms(2);
    15.     TRISAbits.TRISA3 = 1;       // input
    16.     PIE2bits.C1IE = 0;          // diable cm1 interrupt
    17.     PIE2bits.C2IE = 0;          // idable cm2 interrupt
    18.     PIR2bits.C1IF = 0;          // clear cm1 interrupt flag
    19.     PIR2bits.C2IF = 0;          // clear cm2 interrupt flag
     
  2. AlbertHall

    Well-Known Member

    Jun 4, 2014
    1,879
    371
    It doesn't sound like your problem is anything to do with that errata. A good method to get to the bottom of this kind of thing is to create a minimal software and hardware solution just to check RA3 operation. Alternatively, can you use the simulator (perhaps again with the minimal solution) to see what is going on.

    For more help here, post schematic and full software.
     
  3. dannyf

    Well-Known Member

    Sep 13, 2015
    1,767
    356
    Disable mclr on that pin.
     
  4. AlbertHall

    Well-Known Member

    Jun 4, 2014
    1,879
    371
    mclr is on RE3, pin 1, RA3 is pin 5. Worth checking there isn't some confusion there though.
     
  5. NorthGuy

    Active Member

    Jun 28, 2014
    603
    121
    What does your code do when it detects RA3 low?
     
  6. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    You are right AlbertHall, it's something wrong with my circuit. My pic is powered from a floating ground (12V - 9V), and there are some transistors on the input to convert the logic level so the pic can take normal TTL input.

    What cause the problem is my pull low resistor on the RA3 input, instead of pull it to 9V (what is should be), I pull it to 0V.

    It working now, thank you all for your helps!
     
  7. AlbertHall

    Well-Known Member

    Jun 4, 2014
    1,879
    371
    Glad you got it sorted.
     
Loading...