Hi,
I'm trying to use the CTMU of a PIC24F16KA302 to measure the time difference between two pulses on CTED1 and CTED2.I've set up the CTMU to calibrate its capacitance and current and that seems to work properly.
However when I try to measure the voltage on the ADC's sampling capacitor the values that the ADC returns are garbage.
Sometimes the ADC is maxed out to 1023 (I'm using the 10 bit ADC mode) and I'll turn up the time delay between pulses and the voltage value will go down instead of up. A lot of the time the ADC return the value 127 or 512 no matter what the time delay between the pulses is. I have no idea whats going on.
Any suggestions would be greatly appreciated.
Here is my code for measuring the time difference:
float Vread = 0, time_delay = 0, CapVoltage = 0;
ctmu_setup();
ctmu_calibrate_i();
ctmu_calibrate_c();
CTMUCON1 = 0x0500;
CTMUCON2 = 0xCCC8; // sets CTED 1 and 2 as inputs
CTMUICON = 0x8700; // 55 uA range, lowest setting
TRISAbits.TRISA6 = 1;
TRISBbits.TRISB12 = 1;
ANSA = 0x0000;
ANSB = 0x0000;
AD1CHS = 0x1111; //setting up A/D
AD1CSSL = 0x0000;
AD1CON1 = 0x8000;
AD1CON2 = 0x0000;
AD1CON3 = 0x0000;
AD1CON1bits.SAMP = 1; // starts sampling
CTMUCON1bits.EDGEN = 1; // enables edges
CTMUCON1bits.CTMUEN = 1; // enables CTMU
while(!CTMUCON2bits.EDG2); // waits for second event
AD1CON1bits.SAMP = 0; //stops sampling and starts converting
while(!AD1CON1bits.DONE);
__delay_us(20);
Vread = ADC1BUF0;
CapVoltage = Vread*ADREF/ADSCALE;
time_delay = CapVoltage*(CTMUCap/CTMUISrc) * 1000;
return time_delay;
Thanks
I'm trying to use the CTMU of a PIC24F16KA302 to measure the time difference between two pulses on CTED1 and CTED2.I've set up the CTMU to calibrate its capacitance and current and that seems to work properly.
However when I try to measure the voltage on the ADC's sampling capacitor the values that the ADC returns are garbage.
Sometimes the ADC is maxed out to 1023 (I'm using the 10 bit ADC mode) and I'll turn up the time delay between pulses and the voltage value will go down instead of up. A lot of the time the ADC return the value 127 or 512 no matter what the time delay between the pulses is. I have no idea whats going on.
Any suggestions would be greatly appreciated.
Here is my code for measuring the time difference:
float Vread = 0, time_delay = 0, CapVoltage = 0;
ctmu_setup();
ctmu_calibrate_i();
ctmu_calibrate_c();
CTMUCON1 = 0x0500;
CTMUCON2 = 0xCCC8; // sets CTED 1 and 2 as inputs
CTMUICON = 0x8700; // 55 uA range, lowest setting
TRISAbits.TRISA6 = 1;
TRISBbits.TRISB12 = 1;
ANSA = 0x0000;
ANSB = 0x0000;
AD1CHS = 0x1111; //setting up A/D
AD1CSSL = 0x0000;
AD1CON1 = 0x8000;
AD1CON2 = 0x0000;
AD1CON3 = 0x0000;
AD1CON1bits.SAMP = 1; // starts sampling
CTMUCON1bits.EDGEN = 1; // enables edges
CTMUCON1bits.CTMUEN = 1; // enables CTMU
while(!CTMUCON2bits.EDG2); // waits for second event
AD1CON1bits.SAMP = 0; //stops sampling and starts converting
while(!AD1CON1bits.DONE);
__delay_us(20);
Vread = ADC1BUF0;
CapVoltage = Vread*ADREF/ADSCALE;
time_delay = CapVoltage*(CTMUCap/CTMUISrc) * 1000;
return time_delay;
Thanks