Other Parts Discussed in Thread: MSP430F5636
I am using an MSP430F5636 to do some high speed sampling of 4 different ADC pins. My code is below.
void sample( void ){
unsigned int i,k;
unsigned int an[4] = {13,15,12,14};
int c[4][40];
for(k=0;k<4;k++) {
// Setup ADC12
ADC12CTL0 &= ~ADC12ENC;
ADC12CTL0 = ADC12SHT0_0+ADC12ON;
ADC12CTL1 = ADC12SHS_1+ADC12CONSEQ_2+ADC12SSEL_3+ADC12DIV_3; // Repeated single transfer, SMCLK/4 = 4MHz
ADC12MCTL0 = ADC12SREF_0+an[k];
while (ADC12CTL1 & BUSY); // Wait if ADC12 core is active
// Setup DMA0
DMACTL0 = DMA0TSEL_24; // ADC12IFGx triggered
DMACTL4 = DMARMWDIS; // Read-modify-write disable
DMA0CTL = DMADT_4+DMADSTINCR_3; // rpt single transfer, inc dst
DMA0SZ = 40;
DMA0SA = (unsigned int) &ADC12MEM0; // DMA source
DMA0DA = (unsigned int) c[k]; // DMA destination
// Timer setup for ADC sample rate
TA0CTL = 0;
TA0CTL &= ~TAIFG;
TA0CCTL1 = OUTMOD_4; // set timer A to start A to D sampling in rising edge
TA0R = 0;
TA0CCR0 = 0x10; // 16MHz/0x10 = 1MHz
TA0CCR1 = 0x08;
TA0CTL = TACLR + TASSEL_2 + MC_1; // clear, smclock, up, start
P9OUT |= BIT6; // Timing bit
// Start the conversion
DMA0CTL |= DMAEN;
ADC12CTL0 |= ADC12ENC;
while (!(DMA0CTL & DMAIFG)); // Wait for 40 samples
P9OUT &= ~BIT6; // Timing bit
DMA0CTL = 0; // Disable DMA
ADC12CTL0 &= ~ADC12ENC; // Disable ADC conversion
}
}
OUTMOD_4 should set the ADC sampling for each subsequent sample at 2us (1MHz/2 = 500KHz, 1/500KHz = 2us). This means that 40 samples should be around 40 * 2 = 80us. In reality, when monitoring P9.6 with an oscilloscope I am measuring about 21.6 ms for 40 samples. This takes a lot longer than I expect.
At this point, I'm assuming that the ADC can't sample as quickly as I want it to. Using SMCLK = 16MHz, and dividing that by 4 for the ADC gives 4MHz for the ADC clock. Using the equation shown in the datasheet for calculating ADC12 conversion time (13 × ADC12DIV × 1/fADC12CLK) and adding another 4 clock cycles to it for the sample and hold time, results in 4.25us. 4.25us*40 = 170us, which still isn't what I'm seeing but implies that I'm setting something up wrong.
My questions are these:
What is the maximum possible sample rate I can expect to see using DMA?
Am I setting something up incorrectly in my code that causes it to act differently than I want it to?
I know the code isn't setup in the most efficient manner, but I'm just trying to get something working at this point.