multiple ADC using DSpic 30f3010


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2008
    Posts
    3

    Default multiple ADC using DSpic 30f3010

    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;
    }

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    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?

  3. #3
    Join Date
    Feb 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    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 ...

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by angeline View Post
    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.

  5. #5
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    >>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,
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Cool

    Quote Originally Posted by paul borgmeier View Post
    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...

  7. #7
    Join Date
    Feb 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by paul borgmeier View Post
    >>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 =)

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. multiple switches~one ADC
    By naga in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 18th August 2009, 10:20
  3. 18F1320 ADC multiple channel select
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th November 2005, 21:40
  4. Problem reading multiple ADC ports
    By jswayze in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 4th November 2004, 16:46
  5. Reading multiple ADC channels FAST
    By lwindridge in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st April 2004, 22:37

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts