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.

dsPIC30f ADC problem

Status
Not open for further replies.

mshrestha789

Junior Member level 1
Junior Member level 1
Joined
Dec 29, 2010
Messages
17
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,283
Visit site
Activity points
1,392
Hello friends,

Recently I've been working on dspic30f2010. I've written a code and displayed it in Terminal. But I am not getting the correct value. Even when I give 0v at the adc input pin, I get digital value around 10 instead of 0. Please help me regarding this.

I am posting initialization code of ADC. Here I have configure ADC for 1MSPS.

Code:
void ADC_Init(void){
		unsigned char val=0;
        ADCON1bits.FORM = 0x0;//signed fractional format
        ADCON1bits.SSRC = 0x7;//enable auto convert option
        ADCON1bits.ASAM = 0x1;//enable automatic sampling
        ADCON1bits.SIMSAM = 0;//enabble sequential sampling
        ADCON2bits.SMPI = 0x01;//Interrupts at the completion of conversion for each 2nd sample/convert sequence
        ADCON2bits.CHPS = 0x01;//sample on 2 S/H channels - CH0 and CH1
	
        ADCON3bits.SAMC = 0;//no Tad between start of sampling and start of conversion
        val = (unsigned char)(ADCS_VAL + 0.5);//Here 0.5 is added to get the rounding number
        ADCON3bits.ADCS = val;//configure A/D clock period

        ADCHS = 0x0023;//Set up A/D Channel Select Register to convert AN3 on Mux A input of CH0 and CH1 S/H amplifiers
        ADCSSL = 0x0000;//Channel Scanning is disabled. All bits left to their default state

        ADPCFG = 0xFFFF;
        TRISB |= (1<<3);//To set up AN3 as input
        ADPCFGbits.PCFG3 = 0;//Set up channels AN3 as analog input and configure rest as digital

        IFS0bits.ADIF = 0;//Clear the A/D interrupt flag bit
        IEC0bits.ADIE = 1;//Set the A/D interrupt enable bit
        ADCON1bits.ADON = 1;//Turn on the A/D converter
}

Any help regarding this will be highly appreciated.
 

To start with a simple thing, read the data sheet! Tad is specified with 12 minimum at 1 MS/s.
 

Thanks for the reply.

Actually I forgot to add these lines in above code

Code:
_FOSC(CSW_FSCM_OFF & XT_PLL16);  //16x multiplier mode//XTAL = 7.3728 MHz
								//7.3728e+6*16/4 = 29.4 MIPS(Fcy)
                                
_FWDT(WDT_OFF);                 //Turn off the Watch-Dog Timer.
_FBORPOR(MCLR_EN & PWRT_OFF);   //Enable MCLR reset pin and turn off the power-up timers.
_FGS(CODE_PROT_OFF);            //Disable Code Protection

#define XTAL_OSC		7372800
#define FCY			(XTAL_OSC/4) * 16
#define TAD (float)1/((float)12 * (float)1000000)
#define ADCS_VAL		2 * TAD * FCY - 1

I have checked this in Mplab sim, it enters ADC's isr at desired time that is around 2us. It's the value of ADC (which i get in terminal) is not correct.

Please help me regarding this.
 
Last edited:

I think u select
ADCON2bits.CHPS = 0x01;//sample on 2 S/H channels - CH0 and CH1
so check setting & channel & required input for the setting is for both channel or Only for CH0 & Ch1 internally ground .....
 

Actually I am setting up ADC for interrupting after 2 samples get filled in the buffer, for that I need to set up to sample on 2 S/H amplifiers. Also in their code example (form microchip), they are using the same configuration. So, ADCON2bits.CHPS = 0x01;
shouldn't be the problem.
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top