I'm quit new one PIC microcontroller, and i'm stuck with a new problem.
I was using the A/D converter of my PIC18F46j50 to catch 4 push buttons on 1 PIN (RB2), and it worked well. But since I soldered a 32.768kHz oscillator for Timer1, it doesn't work anymore.
unsigned int HAL_SWITCH_GetValADC(void){
ADCON0bits.VCFG0 = 0;
ADCON0bits.VCFG1 = 0;
ADCON0bits.CHS = 0b1000;
ADCON1bits.ADFM = 1; // A/D Result format select bit : right justified
ADCON1bits.ADCAL = 0; // A/D Calibration bit
ADCON1bits.ACQT = 0b111; // A/D Acquisition Time 12 Tad = 12us
ADCON1bits.ADCS = 0b001; //Tad = 1us (Fosc/8)
ADCON0bits.ADON = 0b01; // A/D enable
PIR1bits.ADIF = 0; //make sure A/D Int not set
ADCON0bits.GO=1; //and begin A/D conv.
while(!PIR1bits.ADIF);
NOP();
return (((unsigned int) ADRESH << 8) | ADRESL);
}
Using breakpoint I determined that the problem come from the while loop, when i debug step by step, it works fine, but the programm never stops if the breakpoint is on NOP();
got error like "No source code lines were found at current PC" + few adress, mostly those of the interupt instructions... I don't know if their is a link.
Also someone told me to change the clock used by the A/D convertor... How can I manage to do so ?
Ask for more code if it can help.