STSCBE
Member level 2
Hi all,
i'm using dsPIC33fJ64GS606 controller. I;m facing a problem in ADC. before that, my ADC code is,
where, avg and adc_buffer is long int and P0_ADC_BUF is int.
ADC_SAMPLE = 100;
ADC_REF = 2500 (mV)
MAX_ADC_COUNT = 1023;
So, apart from that early I have got output for all channels exactly, when input is maximum and minumum
but now i cant, ADC1BUF and ADCBUF3 registers initially reads some oscillations. Remaining pins are as it is depends on inputs. the oscillation even input is zero.
how to solve??
i'm using dsPIC33fJ64GS606 controller. I;m facing a problem in ADC. before that, my ADC code is,
Code:
void ADC_init()
{
ADCONbits.ADON = 0; // turn ADC OFF
ADPCFGbits.PCFG0 = 0; // AN0 is configured as analog input
ADPCFGbits.PCFG1 = 0; // AN1 is configured as analog input
ADPCFGbits.PCFG2 = 0; // AN2 is configured as analog input
ADPCFGbits.PCFG3 = 0; // AN3 is configured as analog input
ADCONbits.SLOWCLK = 1; // ADC is clocked by the auxiliary PLL (ACLK)
ADCONbits.FORM = 0; // Integer output
ADCONbits.ADCS = 0b110; // Conversion Clock Divider.. minimum TAD is 35.8 nS as per electrical characteristics.
ADCONbits.ADON = 1; // turn ADC ON
}
void Collect_ADC_Pair0()
{
// ADC Pair 0 (channel 0 and 1)
int adc_i;
adc_buffer1 = 0;
adc_buffer2 = 0;
for(adc_i=0; adc_i< ADC_SAMPLE; adc_i++)
{
ADCPC0bits.TRGSRC0 = 0b00001; //Individual software trigger is selected
ADCPC0bits.SWTRG0 = 1; //Starts conversion of AN0 and AN1
while (ADSTATbits.P0RDY == 0); //Conversion Data for Pair 0 Ready
ADSTATbits.P0RDY = 0;
ADCPC0bits.PEND0 = 0; //Conversion is complete
adc_buffer1 += ADCBUF0; //getting values from buffer
adc_buffer2 += ADCBUF1; //getting values from buffer
}
// ADC Pair 1 (Channel 1)
adc_buffer1 = (adc_buffer1/ ADC_SAMPLE);
adc_buffer2 = (adc_buffer2/ ADC_SAMPLE);
}
void Collect_ADC_Pair1()
{
int adc_i;
adc_buffer3 = 0;
adc_buffer4 = 0;
for(adc_i=0; adc_i< ADC_SAMPLE; adc_i++)
{
ADCPC0bits.TRGSRC1 = 0b00001; //Individual software trigger is selected
ADCPC0bits.SWTRG1 = 1; //Starts conversion of AN3 and AN2
while (ADSTATbits.P1RDY == 0); //Conversion Data for Pair 1 Ready
ADSTATbits.P0RDY = 0;
ADCPC0bits.PEND1 = 0; //Conversion is complete
adc_buffer3 += ADCBUF2; //getting values from buffer
adc_buffer4 += ADCBUF3; //getting values from buffer
}
adc_buffer3 = (adc_buffer3/ ADC_SAMPLE);
adc_buffer4 = (adc_buffer4/ ADC_SAMPLE);
}
void Convert_ADC()
{
avg1 = (adc_buffer1 * ADC_REF / MAX_ADC_COUNT); // Convert the Counts into mV (1023 * 2.4437927663734115 = 2.5V)
avg2 = (adc_buffer2 * ADC_REF / MAX_ADC_COUNT); // Convert the Counts into mV (1023 * 2.4437927663734115 = 2.5V)
avg3 = (adc_buffer3 * ADC_REF / MAX_ADC_COUNT); // Convert the Counts into mV (1023 * 2.4437927663734115 = 2.5V)
avg4 = (adc_buffer4 * ADC_REF / MAX_ADC_COUNT); // Convert the Counts into mV (1023 * 2.4437927663734115 = 2.5V)
P0_ADC_BUF = (unsigned int) avg1;
P1_ADC_BUF = (unsigned int) avg2;
P2_ADC_BUF = (unsigned int) avg3;
P3_ADC_BUF = (unsigned int) avg4;
}
where, avg and adc_buffer is long int and P0_ADC_BUF is int.
ADC_SAMPLE = 100;
ADC_REF = 2500 (mV)
MAX_ADC_COUNT = 1023;
So, apart from that early I have got output for all channels exactly, when input is maximum and minumum
but now i cant, ADC1BUF and ADCBUF3 registers initially reads some oscillations. Remaining pins are as it is depends on inputs. the oscillation even input is zero.
how to solve??