ADC sampling rate improvement

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ADC sampling rate improvement

400 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ranaya on Thu Jul 26 01:17:56 MST 2012
Hi all.....

   I need help from u to improve my adc sampling rate of lpc1769 (xpresso board). I'm expecting to have up to 100k sampling rate for my application. It's a data logger which required logging data to an SD card. I use adc polling method. Use CMSIS libraries with little modifications. 

These are my peripheral settings :

System runs at 100MHz
ADC clock set to 8MHz
SSP clock rate is 10MHz


My logging code :

    while(1){
    
    ADCVal = ADCRead(0);
    sprintf(Float_STR,"%3.3u\r\n",ADCVal);
    res = f_write(&File,Float_STR,(BYTE)strlen(Float_STR),&btw);
    if (alarm_on!= 0){
    if(del>1)
       break;

    del++;
    alarm_on = 0;

    }
    }


Adc Read code:
uint32_t ADCRead( uint8_t channelNum ){
#if !ADC_INTERRUPT_FLAG
  uint32_t regVal, ADC_Data;
#endif
  /* channel number is 0 through 7
  if ( channelNum >= ADC_NUM )
  {
channelNum = 0;
  }*/
  LPC_ADC->CR &= 0xFFFFFF00;
  LPC_ADC->CR |= (1 << 24) | (1 << channelNum);// switch channel,start A/D convert

#if !ADC_INTERRUPT_FLAG
  while ( 1 ){/* wait until end of A/D convert */
regVal = LPC_ADC->DR[channelNum];
if ( regVal & ADC_DONE ){
   break;
}
  }
  LPC_ADC->CR &= 0xF8FFFFFF;/* stop ADC now */    
  if ( regVal & ADC_OVERRUN ){/* save data when it's not overrun, otherwise, return zero */
  return ( 0 );
  }
  ADC_Data = ( regVal >> 4 ) & 0xFFF;
  return ( ADC_Data );/* return A/D conversion value */
#else
  return ( channelNum );/* if it's interrupt driven, the ADC reading is 
done inside the handler. so, return channel number */
#endif
}


Use RTC interrupt for 1 sec, record adc for 2 seconds. For file handling Elm fatfs is used. According to the UM, adc takes 65 cycles from the adc clock. Here ignoring the delays occur from fatfs, adc sample rate should be = adc clk/65 = 123 KHz ! I sampled a 1kz signal, and found that from log data, actual adc sampling rate is around 40Kz. Can any 1 suggest me a method to improve this ?

And is it ok to run both adc and ssp clocks in this way (clock speed?) ?

Many Thankx
0 Kudos
Reply
3 Replies

359 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_Europe on Mon Jul 30 12:20:31 MST 2012
Hi ranaya,

did you try the 'burst mode'?
0 Kudos
Reply

359 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ranaya on Thu Jul 26 10:52:01 MST 2012
Hi gbm, thanx for the quick response...

Here i'm using poling method. AdcRead() waits until conversion's done inside it. Then returns the adcvalue. So the best way is without waiting inside this function, (without calling) execute the same lines in main function, process previous value until the current reading is done am I right ??  

What abut the execution time of f_write ? Is there a way to measure it in xpresso platform ? What if f_write() takes longer time than the time for next adc reading execution ?
Thanx
0 Kudos
Reply

359 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Thu Jul 26 03:03:47 MST 2012
Basic improvement -> change your algorithm to:
while (1)
{
read previous ADC measure
start next ADC measure
process the value read
}
0 Kudos
Reply