Continue to Site

[PIC]problem with CTMU pic24FJ256GB106

Status
Not open for further replies.

Chester929

Newbie level 1
Checking capacity for keypad example number 1.

Code:
int immediateValue;
//  int Index;
//Index = 0;

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
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();
AD1CON1bits.DONE = 0; //Make sure A/D bits are cleared

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.

Status
Not open for further replies.