Chester929
Newbie level 1

Checking capacity for keypad example number 1.
When im waiting for A/D conversion to finish im in deadlock
.
Please, can u check where is problem? Or check if i heve set true bits for AN8 and RB8. Thank u.
Code:
int immediateValue;
// int Index;
//Index = 0;
/*int ADSELECT[5];
ADSELECT[0] = 0x0100;
ADSELECT[1] = 0x0200;
ADSELECT[2] = 0x0400;
ADSELECT[3] = 0x0800;
ADSELECT[4] = 0x1000;*/
//Read CTMU (Get the raw sensor reading)
AD1PCFGL= 0xFFFF; //set all A/D channels to digital I/O pins
TRISB = 0x0000;
LATB = 0x0000;
PORTB = 0x0000; //set all channels to logical 0 outputs
Nop(); Nop(); Nop(); Nop();
Nop(); Nop(); Nop(); Nop();
//Wait for charge to drain
TRISB = 0x0100; //set selected channel to input - RB8
AD1PCFGL = ~0x0100; //set selected channel to analog A/D input - AN8
Nop(); Nop(); Nop(); Nop();
Nop(); Nop(); Nop(); Nop();
//wait for A/D to connect to channel
AD1CHS = 0x800; //select A/D channel - AN8
CTMUCONbits.IDISSEN = 1; //Drain any charge on the A/D circuit
Nop(); Nop(); Nop(); Nop(); Nop();
//Wait for charge to drain
CTMUCONbits.IDISSEN = 0; //Stop discharge of A/D circuit
IFS0bits.AD1IF = 0; //Make sure A/D interrupt flag = 0
AD1CON1bits.SAMP = 1; //Manually start sampling
CTMUCONbits.EDG2STAT = 0; // Make sure edge2 is 0
CTMUCONbits.EDG1STAT = 1; // Set edge1 - Start Charge
//for (count = 0; count < loopCount; count++); // Delay for CTMU charge time
delay_loop_1us(); // Delay for CTMU charge time
delay_loop_1us();
delay_loop_1us();
CTMUCONbits.EDG1STAT = 0; //Clear edge1 - Stop Charge
IFS0bits.AD1IF = 0;
AD1CON1bits.SAMP = 0; //Clear SAMP bit to begin manual A/D conversion
//disp_home();
//disp_str("waiting");
while(!IFS0bits.AD1IF); //Wait for the A/D conversion to finish - here is deadlock :(
//disp_clear();
immediateValue = ADC1BUF0; //Read the value from the A/D conversion
AD1CON1bits.SAMP = 0;
IFS0bits.AD1IF = 0;
AD1CON1bits.DONE = 0; //Make sure A/D bits are cleared
//End of CTMU read
return immediateValue;
When im waiting for A/D conversion to finish im in deadlock
Please, can u check where is problem? Or check if i heve set true bits for AN8 and RB8. Thank u.