+ Post New Thread
Results 1 to 10 of 10
  1. #1
    Full Member level 5
    Points: 2,436, Level: 11
    Achievements:
    7 years registered

    Join Date
    May 2012
    Posts
    240
    Helped
    10 / 10
    Points
    2,436
    Level
    11

    ADC simultaneous sampling of 4 channels

    I am referring to the micro dspic33EP256MC506 and the ADC module. There is a configuration for simultaneous sampling of 4 channels that is CH0, CH1, CH2, CH3. Now my confusion is out of these 4 channels i may want only 2 channels, can i still do it? I mean to say the micro will still do it but i should not use it. Am I correct? Because my source code may change based on this. If i use channel 0 and channel 3. Please advise.

    Code:
    void __attribute__((interrupt, no_auto_psv)) _AD1Interrupt(void)
    {
        channel1 = ADC1BUF0;
        channel3 = ADC1BUF3;
    
        //Clear interrupt flag
        IFS0bits.AD1IF = 0;	
    }

    Code:
    /* a. 10 bit 
     * b. 4 channel
     * c. Simultaneous sampling
     * d. PWM trigger
     * f. Integer Format
     * g. Converts CH0, CH1. CH2, CH3 simultaneously
     * h. Does not scan inputs
     * i. ADC interrupt is generated at the completion of every sample/conversion operation  
     * j. Always uses channel input selects for sample MUXA
     * k. Clock derived from system clock
     * l. AN1 -> CH2 -> Ia, AN11 -> CH0 -> Ib
     */
        /* ADPCFG: ADC Port Configuration Register */
        // Set all ports digital
      
        TRISAbits.TRISA1 = 1;
    	ANSELAbits.ANSA1 = 1;
        
    	TRISCbits.TRISC11 = 1;
    	ANSELCbits.ANSC11 = 1;
        
    	/* Signed Fractional */
    	AD1CON1bits.FORM = 0;
    	/*  PWM Generator 1 primary trigger compare ends sampling and starts conversion */
    	AD1CON1bits.SSRC = 0;
    	AD1CON1bits.SSRCG = 1;
    	/* Sampling begins immediately after last conversion */
    	AD1CON1bits.ASAM = 1;
    	/* Select 10-bit, Multiple ADC operation */
    	AD1CON1bits.AD12B = 0;
    
    	/* No channel scan for CH0+, Use MUX A, SMPI = 1 per interrupt, Vref = AVdd/AVss */
    	AD1CON2 = 0x0000;
    	
    	/* Set Samples and bit conversion time */
    	AD1CON3 = 0x0304;   /* Need to get more clarity*/
    
    	/* Disable DMA */
    	AD1CON4 = 0x0000;
    
    	/* No Channels to Scan */
    	AD1CSSL = 0x0000;
        
        /* Negative voltage is AVDD AN1 -> CH2*/
        AD1CHS123=0x0000; 
        
        /* Channel select AN11 */
    	AD1CHS0 = 11;
    	
    	/* Reset ADC interrupt flag */
    	IFS0bits.AD1IF = 0;           
    
    	/* Enable ADC interrupts, disable this interrupt if the DMA is enabled */	  
    	IEC0bits.AD1IE = 1;       
    
    	/* Turn on ADC module */
    	AD1CON1bits.ADON = 1;

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 81,434, Level: 69
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,350
    Helped
    4456 / 4456
    Points
    81,434
    Level
    69

    Re: ADC simultaneous sampling of 4 channels

    I'm not familiar with that particular device but the data sheet says:
    The dsPIC33EPXXXGP50X, dsPIC33EPXXXMC20X/
    50X and PIC24EPXXXGP/MC20X devices have one
    ADC module. The ADC module supports up to
    16 analog input channels.
    On ADC1, the AD12B bit (AD1CON1<10>) allows the
    ADC module to be configured by the user as either a
    10-bit, 4 Sample-and-Hold (S&H) ADC (default
    configuration) or a 12-bit, 1 S&H ADC.
    which implies you cannot convert 4 channels simultaneously, the best you can do is sample four inputs simultaneously and convert them one by one.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



  3. #3
    Full Member level 5
    Points: 2,436, Level: 11
    Achievements:
    7 years registered

    Join Date
    May 2012
    Posts
    240
    Helped
    10 / 10
    Points
    2,436
    Level
    11

    Re: ADC simultaneous sampling of 4 channels

    Yes it cannot convert simultaneously but samples all the channels simultaneously.



  4. #4
    Advanced Member level 4
    Points: 7,828, Level: 21

    Join Date
    Jan 2015
    Posts
    1,097
    Helped
    346 / 346
    Points
    7,828
    Level
    21

    Re: ADC simultaneous sampling of 4 channels

    Check out the Family Reference Manual (FRM) ADC section for that device. The FRM documents often provide greater detail (and code examples) about how to use the modules than the data sheet. However the FRM documents do cover a variety of devices within the 'family' so you will still need the data sheets to determine exactly which features of the module are available in that device.
    Also the code snippet that you show only gives the setup configuration of the ADC - what is really important (given the title of this thread) is how to trigger the sampling and then the conversions.
    Susan



    •   AltAdvertisement

        
       

  5. #5
    Full Member level 5
    Points: 2,436, Level: 11
    Achievements:
    7 years registered

    Join Date
    May 2012
    Posts
    240
    Helped
    10 / 10
    Points
    2,436
    Level
    11

    Re: ADC simultaneous sampling of 4 channels

    Also the code snippet that you show only gives the setup configuration of the ADC - what is really important (given the title of this thread) is how to trigger the sampling and then the conversions.
    Code:
    void PwmInit(void)
    {
        /*Disble the pwm */
        PTCON = 0x0;
        PHASE1 = (FCY/FPWM - 1);
    	PHASE2 = (FCY/FPWM - 1);
    	PHASE3 = (FCY/FPWM - 1);
        
        /**/
        IOCON1 = 0xC000;
    	IOCON2 = 0xC000;
    	IOCON3 = 0xC000;
        
    	DTR1 = DTR2=DTR3=0x0000;
       
        ALTDTR1 = 25;	// dead time	
    	ALTDTR2 = 25;	// dead time
    	ALTDTR3 = 25;	// dead time
    	//Note: Minimum Duty cycle (ALTDTR_DIV2, used in svm.c) should be >= ALTDTRx / 2
        
        PTCON2 = 0x0000;	// Divide by 1 to generate PWM
    
    	PWMCON1 = 0x0604;	// Enable PWM output pins and configure them as 
    	PWMCON2 = 0x0204;	// complementary mode
    	PWMCON3 = 0x0204;
    
    	PDC1 = PHASE1>>1;	// Initialize as 0 voltage
    	PDC2 = PHASE2>>1;	// Initialize as 0 voltage
    	PDC3 = PHASE3>>1;	// Initialize as 0 voltage
        
        TRIG1= 100;
    	//FLT1 is the fault trigger source
    	FCLCON1 = 0x0003;
    	FCLCON2 = 0x0003;
    	FCLCON3 = 0x0003;	
        
    	PTCON = 0x8000;		// start PWM
    }
    Yes i am referring to the FRM. My main aim is to drive the motor using MCLV-2 development board using my own source code. I am trying to read the Ia and Ib currents. My general observation about ADC module is they do not give the real flexibility in configuring and reading the analog channels. There seems to be lot of restrictions.



  6. #6
    Advanced Member level 4
    Points: 7,828, Level: 21

    Join Date
    Jan 2015
    Posts
    1,097
    Helped
    346 / 346
    Points
    7,828
    Level
    21

    Re: ADC simultaneous sampling of 4 channels

    Feel free to select any other ADC (and possibly any other MCU) that meets your requirements.
    Susan



  7. #7
    Super Moderator
    Points: 77,851, Level: 68
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,777
    Helped
    3592 / 3592
    Points
    77,851
    Level
    68

    Re: ADC simultaneous sampling of 4 channels

    Hi,

    It's not clear WHY you want simultaneous sampling.
    Often this is an erroneous requirement ... and can be avoided, which eases overall design.

    Klaus
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  8. #8
    Full Member level 5
    Points: 2,436, Level: 11
    Achievements:
    7 years registered

    Join Date
    May 2012
    Posts
    240
    Helped
    10 / 10
    Points
    2,436
    Level
    11

    Re: ADC simultaneous sampling of 4 channels

    Quote Originally Posted by KlausST View Post
    Hi,

    It's not clear WHY you want simultaneous sampling.
    Often this is an erroneous requirement ... and can be avoided, which eases overall design.

    Klaus
    One of the reasons is when i am studying about Field Oriented Control in the internet they are suggesting to read the phase currents at the same time else there could be phase difference. So, i am trying to read the phase currents A,B at the same time. Am I correct in my understanding? Please advise.



    •   AltAdvertisement

        
       

  9. #9
    Advanced Member level 5
    Points: 14,971, Level: 29
    schmitt trigger's Avatar
    Join Date
    Apr 2013
    Posts
    2,488
    Helped
    805 / 805
    Points
    14,971
    Level
    29

    Re: ADC simultaneous sampling of 4 channels

    As others have mentioned, a quadruple sample and hold, followed by the sequential A/D conversion, would meet the requirement of simultaneous sampling.

    Having said this.....
    However, if the A/D conversion is much faster than the motor's rate of change, the angle difference between sequential readings may be small enough to not to be concerned about.
    My batteries are recharged by "Helpful Post" ratings.
    If you feel that I've helped you, please indicate it as a Helpful Post



  10. #10
    Super Moderator
    Points: 77,851, Level: 68
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,777
    Helped
    3592 / 3592
    Points
    77,851
    Level
    68

    Re: ADC simultaneous sampling of 4 channels

    Hi,

    One of the reasons is when i am studying about Field Oriented Control in the internet they are suggesting to read the phase currents at the same time else there could be phase difference. So, i am trying to read the phase currents A,B at the same time. Am I correct in my understanding? Please advise.
    This is correct.
    But with a known sampling frequency you have a known delay between the samples...thus it can easily compensated with software.

    Klaus
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



--[[ ]]--