Multiple ADC using dspic30f3010

I have written a code to do multiple ADC conversion using dspic30f3010. I am trying to test whether it works . but it seems like not doing what want . I wonder is it I have wrote it something wrong .

I set this code to sample from AN2 and AN3 as my analogue input. And, test it on two LED's . where if it's above this voltage then the LED wil light up.

Further to this , I need to use this code to set up timer as well t detect a rising edge. Therefore, I need to have a clear understanding o reading the result in the buffer . After reading the data sheet, I a still not clear about this. I hope someone will provide someone wil provide some advice . Thank you .

# include

void SETUP_ADC (void);

/******MAI BODY********************************************************************************************/

int main (void) { int input_1,input_2; /*Declare integer input 1 and 2*/ TRISD=0; /*Setting PORT D as output bit*/ TRISE=0; /*Setting PORT E as output bit*/ SETUP_ADC(); /*Calling the function where all the ADC setup is done*/ ADCON1bits.ADON=1; /*Turn ADC on*/ while(1) /*Repeat continously*/ { ADCON1bits.SAMP=1; /*Start sampling*/ while (ADCON1bits.DONE!=1) /*Sampling is not done*/ { } ADCON1bits.SAMP=0; /*Sampling is holding*/ input_1= ADCBUF0; if (input_1>=512) { PORTDbits.RD0=1; } else { PORTDbits.RD0=0; } input_2=ADCBUF1; if (input_2>=512) { PORTEbits.RE0=1; } else { PORTEbits.RE0=0; } } return(0); }

/********************************SETUP_ADC*****************************************************/ void SETUP_ADC (void) { /*SETTING UP ADCON1*/ ADCON1bits.ADSIDL=0; /*Continue operation in idle mode*/ ADCON1bits.FORM=0; /*Data output format is in integer*/ ADCON1bits.SSRC=7; /*Internal counter ends sampling and start conversion ( Auto convert)*/ ADCON1bits.SIMSAM=1; /*Sample all channels simultanously*/ ADCON1bits.ASAM=0; /*Sampling begins when SAMP bit set*/ /*SETTING UP ADC0N2*/ ADCON2bits.VCFG=0; /*Configuring Voltage Reference where VrefH=AVdd VrefL=AVss*/ ADCON2bits.CSCNA=1; /*Scan inputs*/ ADCON2bits.SMPI=0; /*Interrupt on each sample*/ ADCON2bits.BUFM=0; /*Buffer configured as one 16-word buffer*/ ADCON2bits.ALTS=0; /*ALways use MUX A input select*/ ADCON2bits.CHPS=2; /*Scan CH0, CH1, CH2 and CH3*/

/*SETTING UP ADCON3*/ ADCON3bits.SAMC=15; /*Auto sample time = 31TAD*/ ADCON3bits.ADRC=0; /*Conversion clock=system clock*/ ADCON3bits.ADCS=10; /*TAD=10*TCY*/

/*SETTING UP ADCHS- A/D INPUT SELECT REGISTER*/ ADCHS=0; ADCHSbits.CH0NA=0; /*Channel 0 negative input is Vref-*/ ADCHSbits.CH0SA=2; /*Channel 0 positive input is AN2*/ ADCHSbits.CH123SA=1; /*Channel 1 positive input is AN3*/ ADCHSbits.CH123NA=0; /*Channel 1 negative input is Vref-*/

/*SETTING UP ADPCFG - A/D PORT CONFIGURATION REGISTER */ ADPCFG=0; /*Analog input pin is analogue mode*/


Reply to
Loading thread data ...


I'm not going to look at your code, and I suspect very few others are either. You need to remove tab chars, organize it neatly and consistently, and limit line lengths to 72 chars (although 67 is better). Then it will survive the USENET transmissions fairly well.

 [mail]: Chuck F (cbfalconer at maineline dot net) 
 Click to see the full signature
Reply to

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.