rajalakshmiA
Newbie level 6
Hi i am trying to read ADC voltage from tw0 channels AN4 and AN3.... Values are updating correctly... I want to detect which channel is using ... Can anyone help me?
Here is My code for pic32Mx795f512l with XC32 Compiler, if am using tempsensor i have to assign channel 1 in variable otherwise channel 2 in that variable..... How to do that....Pls help me it is urgent....
Here is My code for pic32Mx795f512l with XC32 Compiler, if am using tempsensor i have to assign channel 1 in variable otherwise channel 2 in that variable..... How to do that....Pls help me it is urgent....
Code:
#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1
#pragma config DEBUG = ON // Background Debugger Enable (Debugger is disabled)
#pragma config ICESEL = ICS_PGx1 // ICE/ICD Comm Channel Select (ICE EMUC1/EMUD1 pins shared with PGC1/PGD1)
#pragma config PWP = OFF // Program Flash Write Protect (Disable)
#pragma config BWP = OFF // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF // Code Protect (Protection Disabled)
#define SYS_FREQ (8000000L)
#define config1 ADC_FORMAT_INTG | ADC_CLK_AUTO | ADC_AUTO_SAMPLING_ON | ADC_CONVERSION_DONE
#define config2 ADC_VREF_AVDD_AVSS | ADC_OFFSET_CAL_DISABLE | ADC_SCAN_OFF | ADC_SAMPLES_PER_INT_2 | ADC_ALT_BUF_ON | ADC_ALT_INPUT_ON
#define config3 ADC_CONV_CLK_INTERNAL_RC | ADC_SAMPLE_TIME_15
#define configscan SKIP_SCAN_AN0 | SKIP_SCAN_AN1 | SKIP_SCAN_AN2 |SKIP_SCAN_AN5 |SKIP_SCAN_AN6 |SKIP_SCAN_AN7 | \
SKIP_SCAN_AN8 |SKIP_SCAN_AN9 |SKIP_SCAN_AN10 |SKIP_SCAN_AN11 | \
SKIP_SCAN_AN12 |SKIP_SCAN_AN13 |SKIP_SCAN_AN14 |SKIP_SCAN_AN15
// AN4 = Temperature Sensor, AN3 = POT
#define configport ENABLE_AN3_ANA | ENABLE_AN4_ANA
#define GetPeripheralClock() (SYS_FREQ/(1 << OSCCONbits.PBDIV))
void main(){
TRISB = 0b00011000;
AD1PCFG = 0xFFE7;
CloseADC10(); // Ensure the ADC is off before setting the configuration
SetChanADC10( ADC_CH0_NEG_SAMPLEA_NVREF | ADC_CH0_POS_SAMPLEA_AN4 | ADC_CH0_NEG_SAMPLEB_NVREF | ADC_CH0_POS_SAMPLEB_AN3);
OpenADC10( config1, config2, config3, configport,configscan);
EnableADC10();
while(1){
while(!mAD1GetIntFlag()){
}
offset = 8 * ((~ReadActiveBufferADC10() & 0x01));
// Read the result of temperature sensor conversion from the idle buffer
tempSensor = ReadADC10(offset);
pot1=ReadADC10(offset+1);
mAD1ClearIntFlag();
}
}
Last edited by a moderator: