Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] dsPIC33f Reading ADC buffer

Status
Not open for further replies.

STSCBE

Member level 2
Joined
Jul 9, 2016
Messages
43
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
360
Hi all,

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

ADC_before.PNG

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??
ADC_after.PNG
 

before that i was worked with dspic33fj32gs406 and can get exact ADC voltage.
But now in dspic33fj64gs606 i have some milli voltage at the point of ADC pins. which is, Pair 0's 1st pin and Pair 1's 1st pin Same voltage and Pair 0's 2nd pin and Pair 1's 2nd pin Same voltage. for example 15mV, 56mV, 15mV, 57mV.

**broken link removed**

But im not faced like this problem before. kindly help me.
I feel may be problem in software configuration....
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top