PDA

View Full Version : multiple ADC using DSpic 30f3010



angeline
- 21st February 2008, 23:50
I am trying to convert two analogue signal using pin AN2 and AN3 by the dspic30f3010. However , I dont really understand how the result is stored. Therefore, I have written a code to test on LED first . If the input voltage in AN2 is above 2.5V, the LED in port E will light up . I assume for this AN2 conversion result is stored in ADCBUF0. SAme goes to AN3 where the LED in port D will light up from the ADCBUF1. However , my code doesnt work .
I think I do not understand how the result is stored. Below is my code , I wish to get some advice . Thanks for your help .

# include <p30f3010.h>

void SETUP_ADC (void);

/******MAIN 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 starts 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*/

/*SETTING UP ADC BUFFER */
ADCBUF0=0;
ADCBUF1=0;
}

skimask
- 21st February 2008, 23:52
K,
Point 1 - PicBasicPro this code is not...
Point 2 - PicBasicPro <> C
Point 3 - PicBasicPro doesn't support ANY of the dsPIC series MCUs.
Point 4 - If you get the above code to compile with PicBasicPro, I'll give up programming altogether and take up underwater basket weaving as a career.
Any questions?

angeline
- 22nd February 2008, 01:23
K,
Point 1 - PicBasicPro this code is not...
Point 2 - PicBasicPro <> C
Point 3 - PicBasicPro doesn't support ANY of the dsPIC series MCUs.
Point 4 - If you get the above code to compile with PicBasicPro, I'll give up programming altogether and take up underwater basket weaving as a career.
Any questions?

Sorry I forgot to mention ... I am using MPLAB IDE to compile this and ICD 2 as the connector to program my dsPIC ...

skimask
- 22nd February 2008, 03:04
Sorry I forgot to mention ... I am using MPLAB IDE to compile this and ICD 2 as the connector to program my dsPIC ...

Still doesn't look like that'll compile under MeLabs PicBasic or MeLabs PicBasicPro, which only support PIC12, PIC14, PIC16, PIC18xxxx devices.

paul borgmeier
- 22nd February 2008, 05:33
>>I am trying to convert two analogue signal using pin AN2 and AN3 by the dspic30f3010

Hi Angeline,

What Ski is trying to tell you is that we mostly discuss code written in BASIC in this forum. You might want to try here
http://forum.microchip.com/
for help with your C code.

Best of Luck,

skimask
- 22nd February 2008, 06:11
What Ski is trying to tell you is that we mostly discuss code written in BASIC in this forum. You might want to try here
http://forum.microchip.com/
for help with your C code.
Best of Luck,

You'd figure some folks could figure that bit out all by themselves...

angeline
- 22nd February 2008, 10:03
>>I am trying to convert two analogue signal using pin AN2 and AN3 by the dspic30f3010

Hi Angeline,

What Ski is trying to tell you is that we mostly discuss code written in BASIC in this forum. You might want to try here
http://forum.microchip.com/
for help with your C code.

Best of Luck,

Oh, now I understand . This is my first time posting . By the way, thanks =)