• AVR Freaks

Electrical interference between analog inputs, dsPIC30F3012

Author
G2daG
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2009/06/26 11:46:14
  • Location: San Diego, CA
  • Status: offline
2009/06/26 11:58:01 (permalink)
0

Electrical interference between analog inputs, dsPIC30F3012

Hi,
 
I am having a strange problem with the analog input module on a dsPIC30F3012. I am trying to sample analog inputs on AN2, AN3, and AN6. The problem is that the voltages seem to be coupled between pins. For instance when I connect AN3 to VSS, the voltage on AN2 drops slightly. When I connect AN3 to VDD, it raises slightly. I am using an oscilloscope.
 
I think it has something to do with the ANCON3 register, because when I slowed everything down the problem is minimal. However it is still there. I am pretty new to all this. Is there something obvious I am doing wrong? Here is the code to set up the ADC:

void ADC_Init(void)
{
//ADCON1 setup
ADCON1bits.ASAM = 1; //continuous sampling
ADCON1bits.SSRC = 0b111; //auto conversion
//ADCON2 setup
ADCON2bits.VCFG = 0; //voltage reference from AVDD and AVSS pins
ADCON2bits.CSCNA = 1; //scan multiple analog inputs in channel 0
ADCON2bits.SMPI = 2; //scan three inputs
ADCSSL = 0b0000000001001100; //scan AN2, AN3 and AN6
ADPCFG = !ADCSSL; //enable only scanned pins as analog, all others are digital
//ADCON3 setup
ADCON3=0xFF7F;
//ADCHSbits.CH0NA=1; //use AN1 as analog (-) reference
ADCON1bits.ADON= 1; //turn on module
}

 
Thanks in advance!
#1

14 Replies Related Threads

    barum
    Super Member
    • Total Posts : 548
    • Reward points : 0
    • Joined: 2007/01/30 16:28:00
    • Location: Varvarin, Serbia
    • Status: offline
    RE: Electrical interference between analog inputs, dsPIC30F3012 2009/06/26 15:21:33 (permalink)
    0
    Welcome to forum,
    First, you will use code tags (icon: ) next time you post code and we would be glad to take a look. Without code tags source is unreadable to others. Here how your code looks better with tags


    void ADC_Init( void )
    {
                                      //ADCON1 setup
        ADCON1bits.ASAM = 1;          //continuous sampling
        ADCON1bits.SSRC = 0b111;     //auto conversion
       
                                      //ADCON2 setup
        ADCON2bits.VCFG = 0;          //voltage reference from AVDD and AVSS pins
        ADCON2bits.CSCNA = 1;         //scan multiple analog inputs in channel 0
        ADCON2bits.SMPI = 2;          //scan three inputs
        ADCSSL = 0b0000000001001100; //scan AN2, AN3 and AN6
        ADPCFG = !ADCSSL;             //enable only scanned pins as analog, all others are digital
       
                                      //ADCON3 setup
        ADCON3 = 0xFF7F;
       
        //ADCHSbits.CH0NA=1;          //use AN1 as analog (-) reference
        ADCON1bits.ADON = 1;          //turn on module
    }



    Now Ill try to help you, See document http://ww1.microchip.com/downloads/en/DeviceDoc/70065D.pdf
    You'll find steps that should be followed for performing an A/D conversion. Also you can ensure that ADC module is turned off by inserting

    ADCON1bits.ADON = 0;

    before other initialization is performed. Finaly you can try code code examples from this document that all contain ADC module configuration before used:
    Example 18-1: Converting 1 Channel, Manual Sample Start, Manual Conversion Start Code Example
    Example 18-2: Converting 1 Channel, Manual Sample Start, TAD Based Conversion Start Code Example
    Example 18-3: Sampling and Converting a Single Channel Multiple Times Code Example
    Example 18-4: A/D Initialization Code Example
    Example 18-1: Converting at 200 ksps, Auto-Sample Start, 1 TAD Sampling Time Code Example

    Regards
    #2
    G2daG
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2009/06/26 11:46:14
    • Location: San Diego, CA
    • Status: offline
    RE: Electrical interference between analog inputs, dsPIC30F3012 2009/06/26 16:31:40 (permalink)
    0
    Thanks for the warm welcome.

    I'll take a look at the examples you mentioned. I've been playing with it more since I posted the first time, and it definitely has something to do with how I am setting up the ADC. In anyone does see a blatant error in my above code it would be great to know - I'll try and figure out what I can on my own.
    #3
    flubydust
    Super Member
    • Total Posts : 1286
    • Reward points : 0
    • Joined: 2005/05/19 13:44:42
    • Status: offline
    RE: Electrical interference between analog inputs, dsPIC30F3012 2009/06/26 16:41:17 (permalink)
    0

    ADC conversion values being affected by the value of a previous conversion are generally the result of insufficient sample time for the source impedance of the converted voltage.


    #4
    barum
    Super Member
    • Total Posts : 548
    • Reward points : 0
    • Joined: 2007/01/30 16:28:00
    • Location: Varvarin, Serbia
    • Status: offline
    RE: Electrical interference between analog inputs, dsPIC30F3012 2009/06/26 16:58:02 (permalink)
    0
    Maybe holding time is too long, selected AD clock is slow with maximal post-scaler used.

    I found sample with ADC channel scanning here http://ww1.microchip.com/downloads/en/AppNotes/AN901_v_510.zip

    ADCSSL = 0x7020; //AN5, AN12-14 selected for scan


    see "setup.c" for complete setup_adc function.
    #5
    barum
    Super Member
    • Total Posts : 548
    • Reward points : 0
    • Joined: 2007/01/30 16:28:00
    • Location: Varvarin, Serbia
    • Status: offline
    RE: Electrical interference between analog inputs, dsPIC30F3012 2009/06/26 17:38:42 (permalink)
    0
    Also, you can try to set all bits at once to avoid potential read-modify-write issues.




    void initADC()                  // scans AN2,AN3 and AN6,
    {                               // puts the readings into ADCBUF0..ADCBUF2,
                                    // then generates an interrupt.
        ADPCFG = 0b1111111110110011;
                                   
        ADCON1 = 0b0000000011100100;// turns the ADC subsystem off,
                                    // continuous operation if the PIC goes into idle mode,
                                    // the readings will be formatted as unsigned integers,
                                    // automatic conversion following the sampling period.
                               
        ADCON2 = 0b0000010000000000;// sampling on channel 0 only,
                                    // scan inputs specified by ADCSSL,
                                    // interrupt after converting each convert sequence.
                                   
        ADCON3 = 0b0001111100111111;// sample duration = 31 x tAD,
                                    // conversion clock = 32 x Tcy.
                                   
        ADCHS  = 0b0000000100000001;// CH0 negative input will be Vref-
                                    // CH0 positive input will be AN1.

                                  
        ADCSSL = 0b0000000001001100;// AN2, AN3 and AN6 will be scanned.
       
        ADCON1bits.ADON = 1;        // turns the ADC subsystem on.
    }



    #6
    OccamMD
    Super Member
    • Total Posts : 1692
    • Reward points : 0
    • Joined: 2005/06/17 08:41:06
    • Location: Tampa, FL
    • Status: offline
    RE: Electrical interference between analog inputs, dsPIC30F3012 2009/06/27 05:31:50 (permalink)
    0
    Normally yes, but I believe these converters shunt the sampling cap to ground between each conversion.
    #7
    leon_heller
    Super Member
    • Total Posts : 6411
    • Reward points : 0
    • Joined: 2004/08/17 13:19:45
    • Location: St. Leonards-on-Sea, E. Sussex, UK.
    • Status: offline
    RE: Electrical interference between analog inputs, dsPIC30F3012 2009/06/27 05:49:18 (permalink)
    0
    He won't get R-M-W problems with internal registers.

    Leon

    Leon Heller
    G1HSM

    #8
    barum
    Super Member
    • Total Posts : 548
    • Reward points : 0
    • Joined: 2007/01/30 16:28:00
    • Location: Varvarin, Serbia
    • Status: offline
    RE: Electrical interference between analog inputs, dsPIC30F3012 2009/06/27 07:48:44 (permalink)
    0
    ORIGINAL: leon_heller

    He won't get R-M-W problems with internal registers.

    Leon


    Yes, but I have seen that "bit reads always as zero" caused unwonted read-modify-write problems even with internal registers.
    #9
    G2daG
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2009/06/26 11:46:14
    • Location: San Diego, CA
    • Status: offline
    RE: Electrical interference between analog inputs, dsPIC30F3012 2009/06/28 13:53:14 (permalink)
    0
    @flubydust:

    I think you hit the nail on the head

    ADC conversion values being affected by the value of a previous conversion are generally the result of insufficient sample time for the source impedance of the converted voltage.


    When I made the sample time maximum the effect was minimal - but it is still there :(. I see maybe a 1% change in the AN2 input when I vary either AN3 or AN6 from 0 to 3.3V (this is my full scale range).

    Is there an equation for how long the sample time needs to be for a given source impedance? I am using a PLL of 16 so potentially I could get a little longer sample time if I decreased it. I read that the conversion time needs to be at least 333 ns but I don't know how that relates to impedance. I think the source impedance is high ~ 32k ohms.

    In general is it best to have the sample time as long as possible? What about conversion time? Is there a "sweet spot" for the sample time, for minimal errors?

    again, I really appreciate the help.



    #10
    leon_heller
    Super Member
    • Total Posts : 6411
    • Reward points : 0
    • Joined: 2004/08/17 13:19:45
    • Location: St. Leonards-on-Sea, E. Sussex, UK.
    • Status: offline
    RE: Electrical interference between analog inputs, dsPIC30F3012 2009/06/28 14:02:14 (permalink)
    0
    ORIGINAL: barum

    ORIGINAL: leon_heller

    He won't get R-M-W problems with internal registers.

    Leon


    Yes, but I have seen that "bit reads always as zero" caused unwonted read-modify-write problems even with internal registers.


    That's not a read-modify-write problem, though.

    Leon

    Leon Heller
    G1HSM

    #11
    flubydust
    Super Member
    • Total Posts : 1286
    • Reward points : 0
    • Joined: 2005/05/19 13:44:42
    • Status: offline
    RE: Electrical interference between analog inputs, dsPIC30F3012 2009/06/28 16:52:25 (permalink)
    0
    ORIGINAL: G2daG
    Is there an equation for how long the sample time needs to be for a given source impedance?


    If you look in the data sheet there is a model of the ADC analog input which shows a sampling capacitor of about 18pF. This capacitor is charged (or discharged) to the source voltage via the source output impedance and about 3k internal resistance. It is just an RC network so you can work out the time it takes to get to within 1/4096 of its final value. A quick calculation (which I might have got wrong) says the minimum sample time is about 8.3RC, about 6us in your case.

    The maximum recommended source impedance is 2.5k but it can be higher as long as you understand the effect of input leakage and required sampling time. You can add some capacitance at the pin to reduce the effective source impedance for charging the sampling capacitor but that also adds a low pass RC filter to your signal.

    I don't think conversion time is that critical, it should work anywhere within the data sheet limits.
    #12
    flubydust
    Super Member
    • Total Posts : 1286
    • Reward points : 0
    • Joined: 2005/05/19 13:44:42
    • Status: offline
    RE: Electrical interference between analog inputs, dsPIC30F3012 2009/06/29 20:33:23 (permalink)
    0
    ORIGINAL: OccamMD
    Normally yes, but I believe these converters shunt the sampling cap to ground between each conversion.


    I have since noticed comment in the datasheet that the holding capacitor will be in a discharged state prior to each sample operation.

    I'm not inclined to believe it because I don't see any point, unless it is something to do with autozeroing the converter comparator and would you short out the sampling capacitor to do that? If you had a really long (software controlled) sample time would you let the zero drift because you can't short out the sampling capacitor?


    The 24F family reference contains the same 'in a discharged state' comment but also has a note for the Acquisition time specification saying

    "The time for the holding capacitor to acquire the “New” input voltage when the voltage changes full scale after the conversion (VDD to VSS or VSS to VDD)."

    Which implies the sample capacitor does retain the voltage from a previous conversion.


    #13
    lbodnar
    Super Member
    • Total Posts : 1148
    • Reward points : 0
    • Joined: 2005/12/18 06:06:09
    • Location: UK
    • Status: offline
    RE: Electrical interference between analog inputs, dsPIC30F3012 2009/06/30 06:03:38 (permalink)
    0
    ORIGINAL: flubydust
    I have since noticed comment in the datasheet that the holding capacitor will be in a discharged state prior to each sample operation.

    I'm not inclined to believe it because I don't see any point, unless it is something to do with autozeroing the converter comparator and would you short out the sampling capacitor to do that?

    This might have something to do with the design of input multiplexor.
    If you look at the input ADC pin on the scope trace you can see the dip in input voltage when sampling starts and the capacitor accumulates the charge.
    You will never see a spike though, so the datasheet seems to be right.
    post edited by lbodnar - 2009/06/30 06:08:18

    Leo
    #14
    G2daG
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2009/06/26 11:46:14
    • Location: San Diego, CA
    • Status: offline
    RE: Electrical interference between analog inputs, dsPIC30F3012 2009/07/01 10:13:26 (permalink)
    5 (1)
    It is fixed! Adding 0.1 uF caps to the input pins did the trick. I needed a little filtering anyway. Thanks for the help guys!

    although nobody noticed that I accidentally used "!" instead of "~" for NOT, but I won't hold it against you :)
    #15
    Jump to:
    © 2019 APG vNext Commercial Version 4.5