Vault 7: Projects

This publication series is about specific projects related to the Vault 7 main publication.

© 2010 Microchip Technology Inc. DS39724B-page 11-19
Section 11. CTMU
CTMU
11
Example 11-5: Capacitance Calibration Routine for Devices with the
CTMUCON Register
#include “p24Fxxxx.h
#define COUNT 25 //@ 8MHz INTFRC = 62.5 us.
#define ETIME COUNT*2.5 //time in uS
#define DELAY for(i=0;i<COUNT;i++)
#define ADSCALE 1023 //for unsigned conversion 10 sig bits
#define ADREF 3.3 //Vdd connected to A/D Vr+
int main(void)
{
int i;
int j = 0; //index for loop
unsigned int Vread = 0;
float CTMUISrc, CTMUCap, Vavg, VTot, Vcal;
//assume CTMU and A/D have been setup correctly
//see Example 11-1 for CTMU & A/D setup
setup();
CTMUCONbits.CTMUEN = 1;//Enable the CTMU
for(j=0;j<10;j++)
{
AD1CON1bits.SAMP = 1; //Manual sampling start
CTMUCONbits.IDISSEN= 1; //drain any charge on the circuit
DELAY; //wait 62.5 us
CTMUCONbits.IDISSEN = 0; //end drain of circuit
CTMUCONbits.EDG1STAT = 1; //Begin charging the circuit
//using the CTMU current source
DELAY; //wait for 62.5 us for circuit to charge
CTMUCONbits.EDG1STAT = 0; //Stop charging circuit and begin A/D conv.
AD1CON1bits.SAMP = 0;
while(!IFS0bits.AD1IF); //Wait for A/D conversion to complete
Vread = ADC1BUF0; //Get the value from the A/D converter
IFS0bits.AD1IF = 0; //Clear AD1IF
VTot += Vread; //Add the reading to the total
}
Vavg = (VTot/10); //Average of 10 readings
Vcal = (Vavg/ADSCALE*ADREF);
CTMUCap = (CTMUISrc*ETIME/Vcal)/100;
//CTMUISrc is in 1/100ths of uA,
//calculated in Example 1-2
//time is in us
//CTMUCap is in pF
}

e-Highlighter

Click to send permalink to address bar, or right-click to copy permalink.

Un-highlight all Un-highlight selectionu Highlight selectionh