Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ADC simultaneous sampling of 4 channels

Status
Not open for further replies.

electronicsman

Full Member level 5
Joined
May 4, 2012
Messages
291
Helped
11
Reputation
22
Reaction score
12
Trophy points
1,298
Activity points
3,737
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;
 

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.
 

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

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
 

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.
 

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

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
 

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.
 

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.
 

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
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top