Vault 7: Projects
This publication series is about specific projects related to the Vault 7 main publication.
PIC24F Family Reference Manual
DS39724B-page 11-20 © 2010 Microchip Technology Inc.
Example 11-6: Capacitance Calibration Routine for Devices with CTMUCON1 and
CTMUCON2 Registers
#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();
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; //wait 62.5 us
CTMUCON1bits.IDISSEN = 0; //end drain of circuit
CTMUCON2bits.EDG1STAT = 1; //Begin charging the circuit
//using the CTMU current source
DELAY; //wait for 62.5 us for circuit
//to charge
CTMUCON2bits.EDG1STAT = 0; //Stop charging circuit and begin
//A/D conversion
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
}
Protego_Release_01_05-Related-OEM-Documentation-PIC24FJ32MC10X-Reference_Manual-Section11-Charge_Time_Measurement_Unit.pdf