Hi all,
I am working on CTMU of PIC24FJ64GA306. I am stucked in time measurement of CTMU.
Here i am trying to find the time delay between two pulses.
What i am doing is giving pulses to CTED9 AND CTED8,
A resistor of 10K is connected across the analog pin 10.
Here is the step am following
1. Initialize the ADC and the CTMU.
2. Set EDG1STAT.
3. Set EDG2STAT.
4. Perform an analog-to-digital conversion.
5. Calculate the time between edges as T = (C/I) * V
CTMU Time measurement:
setup
Please give me suggetions.
Thankyou,
Techbee
I am working on CTMU of PIC24FJ64GA306. I am stucked in time measurement of CTMU.
Here i am trying to find the time delay between two pulses.
What i am doing is giving pulses to CTED9 AND CTED8,
A resistor of 10K is connected across the analog pin 10.
Here is the step am following
1. Initialize the ADC and the CTMU.
2. Set EDG1STAT.
3. Set EDG2STAT.
4. Perform an analog-to-digital conversion.
5. Calculate the time between edges as T = (C/I) * V
CTMU Time measurement:
Code:
while (1) {
//start sampling
AD1CON1bits.SAMP = 1;
//enable ctmu
CTMUCON1bits.EDGEN = 1;
CTMUCON1bits.CTMUEN = 1;
printf("TIME\t");
// wait for the second edge to happen
while (!CTMUCON2bits.EDG2STAT);
// stop sampling
AD1CON1bits.SAMP = 0;
//Wait for A/D conversion to complete
while (!IFS0bits.AD1IF);
Vread = ADC1BUF0;
printf("Vread=%f\t",Vread);
CapVoltage = Vread * ADREF / ADSCALE;
time_delay = CapVoltage * (CTMUCap / CTMUISrc);
printf("time_delay=%f\n\r",time_delay);
}
}
setup
Code:
void ADC_ctmu_Init() {
ANSBbits.ANSB10 = 1;
TRISEbits.TRISE4=1;
TRISEbits.TRISE3=1;
ANSEbits.ANSE4=0;
// ANSEbits.ANSE3=0;
AD1CHS0 = 10; //Select the analog channel(10)
AD1CSSL = 0x0000; //
AD1CON1 = 0x8000; //Turn On ADC, continue in Idle mode,
AD1CON2 = 0x0000; //VR+ = AVDD, V- = AVSS, Don't scan,
AD1CON3 = 0x0000; //ADC uses system clock,
CTMUCON1bits.TGEN = 0;
CTMUCON1 = 0x0500; //make sure CTMU is disabled
CTMUCON2 = 0xCCC8;
CTMUCON2bits.EDG1SEL=9;//CTED 8
CTMUCON2bits.EDG2SEL=4;//CTED 9
CTMUICON = 0x8700; // 55uA, low adjustment
}
Thankyou,
Techbee