Hi,
I'm trying to use the CTMU unit in a PIC24F16KA302 in an impedance measuring system. I'm applying a sinusoidal signal to a component and creating a voltage and current signal which I can then use to find the magnitude and phase differences of, giving me the impedance of that component. I'm using comparators to turn the sinusoidal voltage and current signals into square waves and I'm trying to measure the phase differences between these square waves with the CTMU but I'm having problems getting it to work.
I'm applying a square wave representing the voltage signal to CTED1 and the current signal to CTED2.
By following the App Notes for the CTMU, I'm able to set up the CTMU and calibrate the current and capacitance, and I'm getting reasonable values (58 uA on the 55 uA setting, 8 pF for the A/D hold capacitor).
I can't seem to use the CTMU to measure the time difference between CTED1 and CTED2 however. Also when I turn on the CTMU the voltage signal (CTED1) which should have a peak voltage of 3.3V gets dragged down to a peak of around 1.5V, which I assume means that the CTMU is drawing large amounts of current since the voltage signal comes from a low impedance output compartor. I have no idea idea why this is happening.
Any help would be greatly appreciated.
Here is my code for trying to get a reading from the CTMU:
float Vread = 0, time_delay = 0;
CTMUCON1 = 0x0500; //trigger is enabled and edge 1 must come before edge 2
CTMUCON2 = 0xCCC8; // Edge polarites are positive, CTED 1 and 2 are selected, EDG1and EDG2 set to 0
CTMUICON = 0x8700; // 55uA, current adjusted to low setting
AD1CHS = 0x1111; // Disconnect the Analog channels from ADC to minimize stray capacitance
AD1CSSL = 0x0000;
AD1CON1 = 0x8040; // Enable ADC - Sample finishing should be controlled by CTMU (but isn't because sampling doesn't finished)
AD1CON2 = 0x0000;
AD1CON3 = 0x0000;
AD1CTMUENLbits.CTMEN0 = 1; // Not sure what this does / if I need it
AD1CON1bits.SAMP = 1; // start sampling
CTMUCON1bits.EDGEN = 1; // enable edges
CTMUCON1bits.CTMUEN = 1; // enable CTMU
while(!IFS0bits.AD1IF); //Wait for A/D conversion to complete
Vread = ADC1BUF0;
time_delay = Vread*(CTMUCap/CTMUISrc) * (ADREF /ADSCALE); // Get time difference
Thank you
I'm trying to use the CTMU unit in a PIC24F16KA302 in an impedance measuring system. I'm applying a sinusoidal signal to a component and creating a voltage and current signal which I can then use to find the magnitude and phase differences of, giving me the impedance of that component. I'm using comparators to turn the sinusoidal voltage and current signals into square waves and I'm trying to measure the phase differences between these square waves with the CTMU but I'm having problems getting it to work.
I'm applying a square wave representing the voltage signal to CTED1 and the current signal to CTED2.
By following the App Notes for the CTMU, I'm able to set up the CTMU and calibrate the current and capacitance, and I'm getting reasonable values (58 uA on the 55 uA setting, 8 pF for the A/D hold capacitor).
I can't seem to use the CTMU to measure the time difference between CTED1 and CTED2 however. Also when I turn on the CTMU the voltage signal (CTED1) which should have a peak voltage of 3.3V gets dragged down to a peak of around 1.5V, which I assume means that the CTMU is drawing large amounts of current since the voltage signal comes from a low impedance output compartor. I have no idea idea why this is happening.
Any help would be greatly appreciated.
Here is my code for trying to get a reading from the CTMU:
float Vread = 0, time_delay = 0;
CTMUCON1 = 0x0500; //trigger is enabled and edge 1 must come before edge 2
CTMUCON2 = 0xCCC8; // Edge polarites are positive, CTED 1 and 2 are selected, EDG1and EDG2 set to 0
CTMUICON = 0x8700; // 55uA, current adjusted to low setting
AD1CHS = 0x1111; // Disconnect the Analog channels from ADC to minimize stray capacitance
AD1CSSL = 0x0000;
AD1CON1 = 0x8040; // Enable ADC - Sample finishing should be controlled by CTMU (but isn't because sampling doesn't finished)
AD1CON2 = 0x0000;
AD1CON3 = 0x0000;
AD1CTMUENLbits.CTMEN0 = 1; // Not sure what this does / if I need it
AD1CON1bits.SAMP = 1; // start sampling
CTMUCON1bits.EDGEN = 1; // enable edges
CTMUCON1bits.CTMUEN = 1; // enable CTMU
while(!IFS0bits.AD1IF); //Wait for A/D conversion to complete
Vread = ADC1BUF0;
time_delay = Vread*(CTMUCap/CTMUISrc) * (ADREF /ADSCALE); // Get time difference
Thank you