Hi,
I'm trying to use the CTMU on a PIC24F16KA302 to measure the time difference between two pulses and I can't get the second edge to register.
I have it setup so that the first edge triggers on the edge of CTED1 (pin 20 of the 28 pin pic) and the second edge should trigger on the rising edge of CTED2 (pin 23). I can see that the edges on my oscilloscope and everything is fine there, but the PIC never detects edge 2. Any suggestions?
Here is my code:
float Vread = 0, time_delay = 0, CapVoltage = 0;
//set up ctmu
CTMUCON1 = 0x0500; //make sure CTMU is disabled
CTMUCON2 = 0xCCC8;
CTMUICON = 0x8700; // 55uA, low adjustment
set up inputs and a/d
TRISAbits.TRISA6 = 1; //cted1
TRISBbits.TRISB12 = 1; //cted2
AD1CHS = 0x1111;
AD1CSSL = 0x0000;
AD1CON1 = 0x8000;
AD1CON2 = 0x0000;
AD1CON3 = 0x0000;
//start sampling
AD1CON1bits.SAMP = 1;
//enable ctmu
CTMUCON1bits.EDGEN = 1;
CTMUCON1bits.CTMUEN = 1;
// wait for the second edge to happen
while(!CTMUCON2bits.EDG2);
// stop sampling
AD1CON1bits.SAMP = 0;
//Wait for A/D conversion to complete
while(!IFS0bits.AD1IF);
Vread = ADC1BUF0;
CapVoltage = Vread*ADREF/ADSCALE;
time_delay = CapVoltage*(CTMUCap/CTMUISrc);
My program gets stuck at the line:
while(!CTMUCON2bits.EDG2);
Thanks
I'm trying to use the CTMU on a PIC24F16KA302 to measure the time difference between two pulses and I can't get the second edge to register.
I have it setup so that the first edge triggers on the edge of CTED1 (pin 20 of the 28 pin pic) and the second edge should trigger on the rising edge of CTED2 (pin 23). I can see that the edges on my oscilloscope and everything is fine there, but the PIC never detects edge 2. Any suggestions?
Here is my code:
float Vread = 0, time_delay = 0, CapVoltage = 0;
//set up ctmu
CTMUCON1 = 0x0500; //make sure CTMU is disabled
CTMUCON2 = 0xCCC8;
CTMUICON = 0x8700; // 55uA, low adjustment
set up inputs and a/d
TRISAbits.TRISA6 = 1; //cted1
TRISBbits.TRISB12 = 1; //cted2
AD1CHS = 0x1111;
AD1CSSL = 0x0000;
AD1CON1 = 0x8000;
AD1CON2 = 0x0000;
AD1CON3 = 0x0000;
//start sampling
AD1CON1bits.SAMP = 1;
//enable ctmu
CTMUCON1bits.EDGEN = 1;
CTMUCON1bits.CTMUEN = 1;
// wait for the second edge to happen
while(!CTMUCON2bits.EDG2);
// stop sampling
AD1CON1bits.SAMP = 0;
//Wait for A/D conversion to complete
while(!IFS0bits.AD1IF);
Vread = ADC1BUF0;
CapVoltage = Vread*ADREF/ADSCALE;
time_delay = CapVoltage*(CTMUCap/CTMUISrc);
My program gets stuck at the line:
while(!CTMUCON2bits.EDG2);
Thanks