I am running a hobby project and I encountred with a problem. I code the pic with MPLABX with XC8 compiler. I am using 3 analog inputs. They are AN0, AN1 and AN2. Timer0 interrupt is also used in the code. When I apply 5V on AN1 and AN2 it doesn't bother the PIC uC but when anything greater than 3V to the AN0, Pic resets itself and kept at reset till voltage goes under 3V.
Does anyone else encountered with such problem?
EDIT!!
I disabled timer interrupt and write the code below. It still creates the same problem whenever 5V applied to AN0.
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <p18f4520.h>
#include "my_header.h"
#define _XTAL_FREQ 20000000 // Fosc frequency for _delay() library
#define green_1 PORTCbits.RC1
#define green_2 PORTCbits.RC2
#define green_3 PORTCbits.RC3
#define green_4 PORTDbits.RD0
#define green_5 PORTDbits.RD1
#define green_6 PORTDbits.RD2
#define green_7 PORTDbits.RD3
#define green_8 PORTCbits.RC4
#define green_9 PORTCbits.RC5
#define green_10 PORTCbits.RC6
void main(){
int kg=0;
//setting the Oscillator Freq. to 125KHz for 8TAd to be 3.2 MicroSeconds
OSCCONbits.IRCF0=0;
OSCCONbits.IRCF1=0;
OSCCONbits.IRCF2=1;
//ADC Module Settings
ADCON1=0b00001100;
ADCON2=0b10010000;
TRISAbits.RA6=0;
TRISAbits.RA7=0;
TRISCbits.RC0=0;
TRISCbits.RC1=0;
TRISCbits.RC2=0;
TRISCbits.RC3=0;
TRISCbits.RC4=0;
TRISCbits.RC5=0;
TRISCbits.RC6=0;
TRISCbits.RC7=0;
TRISDbits.RD0=0;
TRISDbits.RD1=0;
TRISDbits.RD2=0;
TRISDbits.RD3=0;
TRISDbits.RD4=0;
TRISDbits.RD5=0;
TRISDbits.RD6=0;
while(1){
ADCON0=0x00;
ADCON0=0x03;
while(GODONE);
ADON=0;
kg=ADRES;
if (kg >200){
green_1=1;
green_2=0;
green_3=1;
green_4=0;
green_5=0;
green_6=1;
green_7=1;
green_8=0;
green_9=1;
green_10=1;
}
else {
green_1=0;
green_2=0;
green_3=0;
green_4=0;
green_5=0;
green_6=0;
green_7=0;
green_8=0;
green_9=0;
green_10=0;
}
}
}
Thank you all inadvance.