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:
Thanks in Advance!!!
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!!!