CTMU Clarifications

Thread Starter

Techbee

Joined Sep 8, 2015
14
hey!!
I am currently working i CTMU for PIC24FJ64GA306. I reffered the data sheet and example codes given by microchip,
still ctmu is not working. i am getting weired result form adc, like varying a lot.

Hardware connection.

for current caliberation, i connected 4.2M ohm accros tha analog pin and ground,
for which i got,

Current=11.863800
Current=12.270011
Current=12.915173
Current=11.302270
Current=13.512544
Current=10.681003
Current=14.372759
Current=10.131422
Current=13.954599
Current=11.385901
Current=12.819593
Current=12.485065
Current=11.792114
Current=13.428912
Current=11.194742
Current=14.038231
Current=10.274791
Current=14.575865
Current=10.860215
Current=13.369175
Current=11.983274
Current=12.198328
Current=13.034647
Current=11.302270
Current=13.572281
Current=10.597371
Current=14.372759
Current=10.286738
Current=13.703702
Current=11.565114
Current=12.676225
Current=12.640382
Current=11.589008
Current=13.452806
Current=11.015531



for capacitance caliberation i connect a capacitor say value 22pf across the analog pin anf ground,where i shoild get 22 pf at result but am getting,

1.696517
1.710702
1.728041
1.725127
1.736842
1.754717
1.776042
1.788461
1.797891
1.801057
1.807421
1.807421
1.810619
1.836625
1.866788
1.866788
1.853261
1.839928
1.817052
1.797891
1.782230
1.776042


So i am confuces where i am stucked in, wheather in hardware or software,I had attached my code along with this thread,please have a look and help me...

Capcitance measurement code:
Code:
#include "main.h"

// CONFIG4
#pragma config DSWDTPS = DSWDTPS3       // Deep Sleep Watchdog Timer Postscale Select bits (1: 256 (8.3 mS))
#pragma config DSWDTOSC = LPRC          // DSWDT Reference Clock Select (DSWDT uses LPRC as reference clock)
#pragma config DSBOREN = OFF            // Deep Sleep BOR Enable bit (DSBOR Disabled)
#pragma config DSWDTEN = OFF            // Deep Sleep Watchdog Timer Enable (DSWDT Disabled)
#pragma config DSSWEN = ON              // DSEN Bit Enable (Deep Sleep is controlled by the register bit DSEN)

// CONFIG3
#pragma config WPFP = WPFP63            // Write Protection Flash Page Segment Boundary (Page 52 (0xFC00))
#pragma config VBTBOR = ON              // VBAT BOR enable bit (VBAT BOR enabled)
#pragma config SOSCSEL = ON             // SOSC Selection bits (SOSC circuit selected)
#pragma config WDTWIN = PS25_0          // Watch Dog Timer Window Width (Watch Dog Timer Window Width is 25 percent)
#pragma config BOREN = ON               // Brown-out Reset Enable (Brown-out Reset Enable)
#pragma config WPDIS = WPDIS            // Segment Write Protection Disable (Disabled)
#pragma config WPCFG = WPCFGDIS         // Write Protect Configuration Page Select (Disabled)
#pragma config WPEND = WPENDMEM         // Segment Write Protection End Page Select (Write Protect from WPFP to the last page of memory)

// CONFIG2
#pragma config POSCMD = XT              // Primary Oscillator Select (XT Oscillator Enabled)
#pragma config BOREN1 = EN              // BOR Override bit (BOR Enabled [When BOREN=1])
#pragma config IOL1WAY = OFF            // IOLOCK One-Way Set Enable bit (The IOLOCK bit can be set and cleared using the unlock sequence)
#pragma config OSCIOFCN = OFF           // OSCO Pin Configuration (OSCO/CLKO/RC15 functions as CLKO (FOSC/2))
#pragma config FCKSM = CSDCMD           // Clock Switching and Fail-Safe Clock Monitor Configuration bits (Clock switching and Fail-Safe Clock Monitor are disabled)
#pragma config FNOSC = PRI              // Initial Oscillator Select (Primary Oscillator (XT, HS, EC))
#pragma config ALTVREF = DLT_AV_DLT_CV  // Alternate VREF/CVREF Pins Selection bit (Voltage reference input, ADC =RA9/RA10 Comparator =RA9,RA10)
#pragma config IESO = OFF               // Internal External Switchover (Disabled)

// CONFIG1
#pragma config WDTPS = PS8192           // Watchdog Timer Postscaler Select (1:8,192)
#pragma config FWPSA = PR32             // WDT Prescaler Ratio Select (1:32)
#pragma config FWDTEN = WDT_DIS         // Watchdog Timer Enable (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config WINDIS = OFF             // Windowed WDT Disable (Standard Watchdog Timer)
#pragma config ICS = PGx1               // Emulator Pin Placement Select bits (Emulator functions are shared with PGEC1/PGED1)
#pragma config LPCFG = OFF              // Low power regulator control (Disabled)
#pragma config GWRP = OFF               // General Segment Write Protect (Disabled)
#pragma config GCP = OFF                // General Segment Code Protect (Code protection is disabled)
#pragma config JTAGEN = OFF             // JTAG Port Enable (Disabled)
void ADCInit();
void pps();
void init_io();
void setup();

void main()
{
    int j = 0; 
    unsigned int Vread = 0;
    float CTMUISrc, CTMUCap, Vavg, VTot, Vcal;
    setup();
    printf("CTMU MEASUREMENT ");

    while(1)
    {
        CTMUCON1bits.CTMUEN = 1; //Enable the CTMU
         
        for(j=0;j<10;j++)
        {
            AD1CON1bits.SAMP = 1; //Manual sampling start
            CTMUCON1bits.IDISSEN= 1;  //drain any charge on the circuit
            __delay_us(60);  //wait 62.5 us
            CTMUCON1bits.IDISSEN = 0;  //end drain of circuit
            CTMUCON2bits.EDG1STAT = 1; //Begin charging the circuit

            //using the CTMU current source
            __delay_us(60); //wait for 62.5 us for circuit
            //to charge
            CTMUCON2bits.EDG1STAT = 0; //Stop charging circuit and begin
           
            //Analog-to-Digital conversion
            AD1CON1bits.SAMP = 0;
            while(!IFS0bits.AD1IF);  //Wait for conversion to complete
            Vread = ADC1BUF0;  //Get the value from the ADC
//            printf("%d\t",Vread);
            IFS0bits.AD1IF = 0;  //Clear AD1IF
            VTot += Vread;  //Add the reading to the total
        }
//           printf("VTot=%f\t",VTot);
            Vavg = (VTot/10); //Average of 10 readings
//            printf("Vavg=%f\t",Vavg);
            Vcal = (Vavg/ADSCALE*ADREF);
//            printf("Vcal=%f\t",Vcal);
            CTMUISrc = 5.5; //CTMUISrc is in 1/100ths of uA
            //use the nominal value or the value
            CTMUCap = (CTMUISrc*ETIME/Vcal)/100;  //time is in us
            printf("%f\n\r",CTMUCap);
            //CTMUCap is in pF
            VTot=0,Vavg=0,Vcal=0,CTMUCap=0;
    }
}

void init_io()
{
    TRISB = 0X00;
    TRISD = 0XFF;
}

void pps()
{
    PPSUnLock;
    iPPSInput(IN_FN_PPS_U1RX, IN_PIN_PPS_RP12);
    iPPSOutput(OUT_PIN_PPS_RP11, OUT_FN_PPS_U1TX);
    //    iPPSInput(IN_FN_PPS_ADCH2, IN_PIN_PPS_RP12);
    PPSLock;
}

void setup()
{
    ADCInit();
    uart1_init();
    pps();
}

void ADCInit()
{
    ANSBbits.ANSB10=1;
    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,
    CTMUCON1 = 0x0090; //make sure CTMU is disabled
    CTMUCON2 = 0xC0C0;
    CTMUICON = 0x0100; // 0.55uA, Nominal - No Adjustment
}

Thanks in Advance!!!
 

Papabravo

Joined Feb 24, 2006
21,094
A couple of questions.
  1. What is the parallel impedance of 4.2MΩ in parallel with the input impedance of the A/D converter?
  2. Where do you think the measured current is flowing?
  3. How are you measuring capacitance with a capacitor across the A/D input?
  4. What does CTMU stand for? Top google hit is http://www.ctmu.org/
A schematic diagram of your setup would be helpful since it is not at all obvious what you are doing.
 

jayanthd

Joined Jul 4, 2015
945
for capacitance caliberation i connect a capacitor say value 22pf across the analog pin anf ground,where i shoild get 22 pf at result but am getting,

1.696517
...
How does the PIC know that you have connected 22pf Capacitor to ADC input ?

If ADC is 10 bit and 0 represent 1 pf and 5V adc input represent 1000pf (1023 raw adc value) then calculate what adc input gives 22 pf.
Without you convert the adc input voltage to capacitance how did you expect PIC24 to convert the voltage to capacitance for you ?
 

Thread Starter

Techbee

Joined Sep 8, 2015
14
hey all!!
Thanks for the reply.
1. what i have understood from ctmu datasheet is for measuring capacitance we need to calibrate current and capacitance.
For current calibration we need a RCAL, what should be the value for RCAL???

2. For capacitance calibration, we need to connect a capacitance across the analog pin and ground. I don't know whether it is right or not.
Please clarify.

3 Finally for capacitance measurement, we are using the calibrated current and voltage for the capacitance measurement.

If this is not the way,please guide the right way!! It will be a great help if someone share the code!!
@nsaspook YES!!

For capacitance measurement how should we connect the capacitor??

Thankyou
 
Last edited:

Thread Starter

Techbee

Joined Sep 8, 2015
14
How does the PIC know that you have connected 22pf Capacitor to ADC input ?

If ADC is 10 bit and 0 represent 1 pf and 5V adc input represent 1000pf (1023 raw adc value) then calculate what adc input gives 22 pf.
Without you convert the adc input voltage to capacitance how did you expect PIC24 to convert the voltage to capacitance for you ?
Code:
int main(void)
{
    __delay_ms(3000);
    setup();
   
    while(1)
    {
        printf("\n\r");
        printf("\n\r");
        CalibrateCTMU(4200000,ADC_CH0_POS_SAMPLEA_AN10);
        CAPACITOR = CapacitanceMst();        // calculate capacitance
        printf("CAPACITOR = [%g]\n\r",CAPACITOR);
    }
}

float CapacitanceMst(void)
{
    float voltage,time;
    double capacitance;

    //current = 0.000055 ; // 55uA - 100_BASE_CURR
    //current = 0.0000055 ; // 5.5uA - 10_BASE_CURR
    //current = 0.00000055 ; // 0.55uA - BASE_CURR


    /*Configure ADC to read channel 1*/
    /******************** ADC configured for:***************************************************
        * FOSC-RC as source of conversion clock
        * Auto sampling enabled
        * scanning of channels disabled
        * Result is right justified
        * Sampling time 17 TAD
        * conversion time 254 Tcy
        * AN1 for sampling
        * ADC interrupt on 16 conversions
        * ADC reference voltage from VDD & VSS
    *******************************************************************************************/

//    ANSBbits.ANSB10   = 1;
//    AD1CON1bits.ADON  = 0;
//    AD1CSSL = 0x0000;
//    AD1CHS0 = 10;
//    AD1CON1 = ADC_CLK_AUTO | ADC_AUTO_SAMPLING_ON ;
//    AD1CON2 = ADC_SCAN_OFF | ADC_INTR_16_CONV ;
//    AD1CON3 = ADC_SAMPLE_TIME_17 | ADC_CONV_CLK_254Tcy;
//    AD1CON1bits.ADON = 1;
    /*Configure the CTMU*/
    /********************** CTMU configured for:*************************************************
        * Edge 1 programmed for a positive edge response
        * Edge 2 programmed for a positive edge response
        * CTED1 is a source select for Edge
        * trigger output disabled
        * Edge sequence of CTMU disabled
        * no edge delay generation
        * CTMU edges blocked
    *******************************************************************************************/

    CTMUCON1 = CTMU_TIME_GEN_DISABLE|CTMU_EDGE_DISABLE|CTMU_EDGE_SEQUENCE_OFF|CTMU_IDLE_CONTINUE
            |CTMU_TRIG_OUTPUT_DISABLE;
    CTMUCON2 = CTMU_EDGE1_POLARITY_POS|CTMU_EDGE2_POLARITY_POS|CTMU_EDGE1_SOURCE_OC1
            |CTMU_EDGE2_SOURCE_OC1;

    CTMUICON = CTMU_NOMINAL_CURRENT | CTMU_CURR_RANGE_BASE_CURR;

    Enbl_CTMUEdge1;    //Enable current source  to charge the capacitor connected to AN1

    /*************** Wait for 10 msec ******************************************************/
    __delay_ms(10);

    time = 0.01;

    Disbl_CTMUEdge1;                        //Disable current source. stop charging the capacitor

    /* Read ADC*/

    int j;
    unsigned int Vread = 0;
    double VTot = 0;
    printf("\n\r");
    for(j=0;j<10;j++)
    {
            AD1CON1bits.SAMP = 1;           //Manual sampling start
            __delay_ms(100);
            ADC1_Clear_Intr_Status_Bit;     //make sure A/D Int not set
            AD1CON1bits.SAMP = 0;           //and begin A/D conv.
            while(!IFS0bits.AD1IF);         //Wait for A/D convert complete
            AD1CON1bits.DONE = 0;
            Vread = ADC1BUF0;               //Get the value from the A/D
            printf("Vread: %d\t",Vread);
            ADC1_Clear_Intr_Status_Bit;     //Clear A/D Interrupt Flag
            VTot += Vread;                  //Add the reading to the total
    }
    printf("VTot: %f\n\r",VTot);
    Vavg = (float)(VTot/10.000);            //Average of 10 readings
    printf("Vavg:[%f]\n\r",Vavg);

    voltage = (Vavg*3.3)/1024;            // convert ADC count into voltage
    printf("CTMUISrc: %g\n\r",CTMUISrc);

    capacitance = (CTMUISrc * time)/voltage; // calculate the Capacitance value using the current value obtained from calibration
    printf("capacitance: %g\n\r",capacitance);

    CloseADC10();                             //disable ADC
    CloseCTMU();                            //disable CTMU

    return capacitance;
}


void CalibrateCTMU(unsigned long resistance, unsigned int adcch)
{
    int i;
    int j = 0;                             //index for loop
    unsigned int Vread = 0;
    double VTot = 0;

     CTMUCON1 = CTMU_TIME_GEN_DISABLE|CTMU_EDGE_DISABLE|CTMU_EDGE_SEQUENCE_OFF|CTMU_IDLE_CONTINUE
                |CTMU_TRIG_OUTPUT_DISABLE;
     CTMUCON2 = CTMU_EDGE1_POLARITY_POS|CTMU_EDGE2_POLARITY_POS;

     CTMUICON = CTMU_NOMINAL_CURRENT | CTMU_CURR_RANGE_BASE_CURR;

    /**************************************************************************/
    //setupAD converter;
    /**************************************************************************/

    ANSBbits.ANSB10 =   1;
    AD1CHS0 = 10; //Select the analog channel(10)
    AD1CSSL = 0x0000; //
    AD1CON1 = 0x0000; //Turn On ADC, continue in Idle mode,
    AD1CON2 = 0x0000; //VR+ = AVDD, V- = AVSS, Don't scan,
    AD1CON3 = 0x0001; //ADC uses system clock,
    AD1CON1bits.ADON = 1;

    CTMUCON1bits.CTMUEN = 1;         //Enable the CTMU

    for(j=0;j<10;j++)
    {
            AD1CON1bits.SAMP = 1;           //Manual sampling start
            CTMUCON1bits.IDISSEN = 1;       //drain charge on the circuit
            for(i=0;i<500;i++);             //wait 125us
            CTMUCON1bits.IDISSEN = 0;       //end drain of circuit
            Enbl_CTMUEdge1;                 //Begin charging the circuit
                                            //using CTMU current source
            for(i=0;i<500;i++)              //wait for 125us
            Disbl_CTMUEdge1;                //Stop charging circuit
            ADC1_Clear_Intr_Status_Bit;     //make sure A/D Int not set
            AD1CON1bits.SAMP = 0;           //and begin A/D conv.
            while(!IFS0bits.AD1IF);         //Wait for A/D convert complete
            AD1CON1bits.DONE = 0;
            Vread = ADC1BUF0;               //Get the value from the A/D
            printf("Vread: %d\t",Vread);
            ADC1_Clear_Intr_Status_Bit;     //Clear A/D Interrupt Flag
            VTot += Vread;                  //Add the reading to the total
    }
    printf("VTot: %f\n\r",VTot);
    Vavg = (float)(VTot/10.000);            //Average of 10 readings
    printf("Vavg: %f\n\r",Vavg);
    Vcal = (float)((Vavg*3.3)/1024);        //  for unsigned conversion 10 sig bits * Vdd connected to A/D Vr+
    printf("Vcal: %f\n\r",Vcal);
    CTMUISrc = Vcal/resistance;             //CTMUISrc
    printf("CTMUISrc: %g\n\r",CTMUISrc);
}

void init_io()
{
    TRISB = 0X00;
    TRISD = 0XFF;
}

void pps()
{
    PPSUnLock;
    iPPSInput(IN_FN_PPS_U1RX, IN_PIN_PPS_RP12);
    iPPSOutput(OUT_PIN_PPS_RP11, OUT_FN_PPS_U1TX);
    PPSLock;
}

void setup()
{
//    ADCInit();
    uart1_init();
    pps();
}

void ADCInit()
{
    ANSBbits.ANSB10 =   1;
    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,
}
 

nsaspook

Joined Aug 27, 2009
12,998
The CTMU uses a known current source , set time and known capacitance for the calibration to find a unknown capacitance.

If you assume the ADC is correct first you calibrate the current source with a known resistance to generate a calibration voltage.

Program the current source register for a set value with a known resistance (as in the example to give 70% of full ADC value), this results in voltage drop across the resistor to ground that's measured. If the ADC result matches the calculated voltage the current source is correct. If the results don't match you can trim the current source value with the adjustment register until it does or save a software offset to what the current value actually is.

Now you know the current source value.
ctmu_cap.png
Next measure with no capacitance to be measured in the circuit to get the stray capacitance voltage level for a set time period and save this value.


Then measure with the known capacitance to get a value (with the added stray capacitance) for the slope of voltage for different capacitance values. It's all in the example code.

The theory is a current source charging a capacitor gives a linear voltage value over time. If you fix time and you know the voltage values for two known values of capacitance you can define a scale of voltages that directly relates to any value capacitor within the limits of the measurement device.
Here you can see the voltage ramp and how it varies with the addition of body capacitance (increased value and lower voltage on the measurement circuit in the same time frame) in a touch application.
https://flic.kr/p/aXvemz
https://flic.kr/p/aXvfcx


The CTMU used to measure relative capacitance in a hand or body detector to project capacitance (by altering the field configuration of the plates) up using an active ground guard configuration with several plates in a small box with a simple unity gain voltage buffer 3553AM to drive the fields up.
ctmu_cap_guard.png
https://flic.kr/p/bkLcga



Upper left ground plate, lower left sensor guard plate, lower right the sensor plate.

Buffer amp to the PIC18 CTMU sensor detector with the needed software to reduce noise and generate a bar graph of the received capacitative signal.
 
Last edited:

Thread Starter

Techbee

Joined Sep 8, 2015
14
Thank you for your reply.
As far current calibration works fine but we are stucked in capacitance calibration.
As you mentioned in the previous reply when we measured with no capacitance, voltage we are getting is zero.
When we measured with a known capacitance (33pf) we are getting 0.319677v.
We have some doubts :
1> Rcal =100kohm and is there any limitation for setting Rcal?
2> CTMUISrc = 5.5ua, time = 6us (how to set time?), Vcal = 0.319677v.
3> Capvalue = ((5.5x6)/Vcal) = 103pf
Hardware connection:
33pf cap connected across analog pin and ground.
Is our calculation right? Please give a suggestion.
Thank you.
-TechBee
 
Last edited:

nsaspook

Joined Aug 27, 2009
12,998

Get an oscilloscope and connect it to the ADC pin that's used to measure capacitance. You should see a ramp of voltage if your code and timing is correct.

You need to adjust the time with no capacitance to read ~70% of the ADC max reference voltage when you start the ADC conversion at (2).
http://www.embedded.com/print/4218309

I would also run a rough calibration check on the ADC readings to be sure that's working correctly. You won't need offset and gain correction factors for the measurement circuit to work if they are within the specified limits of the chip. If not you can adjust with something like this.
C:
#define   ADOFFSET   0.0015   // correct for zero shift
#define ADGAIN     0.983   // correct for voltage offset from calibration value 2.000 volts

Vcal0 = ((Vval / ADSCALE * ADREF) + ADOFFSET)*ADGAIN;
http://www.atmel.com/images/doc2559.pdf
 
Last edited:

Thread Starter

Techbee

Joined Sep 8, 2015
14
Thanks for the reply...

When we connect the oscilloscope, we are getting a graph with adc, a spike occurs.

plz check our code, is it right??
Code:
CTMUCON1bits.CTMUEN = 1; //Enable the CTMU
        for (j = 0; j < 10; j++)
        {
            AD1CON1bits.SAMP = 1;           //Manual sampling start
            CTMUCON1bits.IDISSEN = 1;       //drain charge on the circuit
            __delay_us(125);                //wait 125us
            CTMUCON1bits.IDISSEN = 0;       //end drain of circuit
            CTMUCON2bits.EDG1STAT = 1;      //Begin charging the circuit
            __delay_us(150);                //wait for 125 us
            CTMUCON2bits.EDG1STAT = 0;      //Stop charging circuit
            IFS0bits.AD1IF = 0;             //make sure ADC Interrupt is not set
            AD1CON1bits.SAMP = 0;           //begin Analog-to-Digital conversion
            while (!IFS0bits.AD1IF);        //Wait for conversion to complete
            AD1CON1bits.DONE = 0;


            Vread = ADC1BUF0;               //Get the value from the ADC
            IFS0bits.AD1IF = 0;             //Clear ADC Interrupt Flag
            VTot += Vread;                  //Add the reading to the total
        }
        Vavg = (float) (VTot / 10.000);     //Average of 10 readings
        printf("Vavg    =   %f\t",Vavg);
        Voltage = (double) (Vavg / ADSCALE * ADREF);
        printf("Voltage        =   %g\t",Voltage);
        printf("Resistance  =   %g\t",(Voltage/.55)*1000000);


        CTMUISrc = .55;                     //CTMUISrc is in 1/100ths of uA
                                            //use the nominal value or the value

        CTMUCap = (CTMUISrc * 7 / Voltage);  //time is in us
                                                                 //CTMUCap is in pF
        printf("Capacitor Value =   %f\n\r",CTMUCap);


    //    CTMUISrc = Vcal / RCAL; //CTMUISrc is in 1/100ths of uA
    //    printf("Current=%f\n\r",CTMUISrc);
        VTot=0,Vavg=0,Voltage=0,CTMUISrc=0;
}
Any suggestion plzz!!!!
 

Attachments

nsaspook

Joined Aug 27, 2009
12,998
The waveform is OK but looks exponential like its loaded down with resistance. You have removed the current cal resistor from the circuit while measuring capacitance?
 

Thread Starter

Techbee

Joined Sep 8, 2015
14
hi Nsaspook,
Now i can measure the capacitance ranging from 1nf tp 100nf correctly.
But how can we extend the range????
By calulation adc can give resistor value of 6Mohm ie.,(resistor=3.3/0.55ua).
But here i can ony messure upto 100K correctly.
I tried in all currrent sources,still for higher resistance values problem occurs....
Since human finger have capcitance range upto 5 to 15pf, not

Please give me suggetions!!!


Thanks
Techbee.
 

Thread Starter

Techbee

Joined Sep 8, 2015
14
yes
The waveform is OK but looks exponential like its loaded down with resistance. You have removed the current cal resistor from the circuit while measuring capacitance?

now i am connected capacitor across the analog pin and ground without resistor.
I am confused with the range, how can we measure pf range capacitor, and what value r cal should be calibrated?
 

nsaspook

Joined Aug 27, 2009
12,998
To measure smaller range capacitors you need to reduce the charge time period to less than the time constant for the selected current source and smallest capacitance in the needed range so the ADC reading will be about 70% of the full ADC range.
C:
            CTMUCON2bits.EDG1STAT = 1;      //Begin charging the circuit
            __delay_us(150);                //wait for 125 us <--- [B]reduce this time[/B]
            CTMUCON2bits.EDG1STAT = 0;      //Stop charging circuit
 

Thread Starter

Techbee

Joined Sep 8, 2015
14
To measure smaller range capacitors you need to reduce the charge time period to less than the time constant for the selected current source and smallest capacitance in the needed range so the ADC reading will be about 70% of the full ADC range.
C:
            CTMUCON2bits.EDG1STAT = 1;      //Begin charging the circuit
            __delay_us(150);                //wait for 125 us <--- [B]reduce this time[/B]
            CTMUCON2bits.EDG1STAT = 0;      //Stop charging circuit
Hi Nsaspook,
I changed my code as u referred, can u plz check my code below,is my calculation right?

voltage=(Vavg/1023*3.3);
capacitance=((ctmrsc*150u)/voltage);
 

nsaspook

Joined Aug 27, 2009
12,998
Hi Nsaspook,
I changed my code as u referred, can u plz check my code below,is my calculation right?

voltage=(Vavg/1023*3.3);
capacitance=((ctmrsc*150u)/voltage);
The best way to check your code is to see if it works. I'm glad to help you with the concept but I'm not going to fix your possible coding problems when the doc's on this are very clear.
 

Thread Starter

Techbee

Joined Sep 8, 2015
14
Hi Nsaspook,
I have doubt in range calculation. As we know we can measure the 70%of adc value.
What is the maximum resistor range we can measure with ctmu.
As I know upto 2.3v will get the accurate resistor value, ie., 2.3/0.55u=4.2Mohm
But when i set 0.55uA, i can only measure up to 330Kohm, ie., 0.18
I use the trimming process, but by setting maximum positive voltage from nominal current
I am getting only 0.1815 Voltage????


Is there anything i should consider apart from trimming process???
 
Last edited:
Top