NHS3152: How can I store ADC conversions near the 12kS/s rate?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

NHS3152: How can I store ADC conversions near the 12kS/s rate?

1,233 次查看
randall_irwin
Contributor I

Hello,

I need to store ADC samples at a minimum of 2kS/s, and was expecting to reach closer to 12kS/s per the datasheet, but I am getting a rate around ~200S/s. I am not sure if this is due to the way I am retrieving the samples and storing them, or some other part of my code. I store the samples in an int array, then store the 32bit timer count in a separate int array. Here is the relevant code from my main function:

AppInit(); //This is borrowed from the ndeft2t example code
Chip_TIMER32_0_Init();
Chip_TIMER_Enable(NSS_TIMER32_0);
Chip_ADCDAC_Init(NSS_ADCDAC0);
Chip_ADCDAC_SetMuxADC(NSS_ADCDAC0, ADCDAC_IO_ANA0_0);
Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_ANA0_0, IOCON_FUNC_1);
Chip_ADCDAC_SetModeADC(NSS_ADCDAC0, ADCDAC_CONTINUOUS);
Chip_ADCDAC_SetInputRangeADC(NSS_ADCDAC0, ADCDAC_INPUTRANGE_NARROW);
Chip_ADCDAC_StartADC(NSS_ADCDAC0);


int i = 0;
int samples[5];
int time[5];


for (i;i<5;i++){
//Record ADC samples and timestamp in milliseconds
samples[i] = Chip_ADCDAC_GetValueADC(NSS_ADCDAC0);
time[i] = Chip_TIMER_ReadCount(NSS_TIMER32_0);
}

When I output the values from the two arrays, my actual sample frequency according to the 32bit timer is ~200Hz. To calculate this I convert the timer to seconds by dividing by the system clock frequency (set to 8MHz, prescaler is set to 0), then take the difference between two successive samples and invert (f = 1/(t1 - t0)) Could you please recommend an alternate method or point me in the right direction?

Thank you,

Randall Irwin

标记 (2)
0 项奖励
回复
3 回复数

697 次查看
jesmith
Contributor III

It's been many years, so I suspect this won't matter to @randall_irwin , but I'll mention this for others who stumble upon this thread: consider changing the clock division to speed things up:

Chip_Flash_SetHighPowerMode(true);
bool check_pm = Chip_Flash_GetHighPowerMode();
//Chip_Flash_SetNumWaitStates(1);
//int check_ws = Chip_Flash_GetNumWaitStates();

if (check_pm){
  Chip_Clock_System_SetClockDiv(1); // WARNING: need HPM or WS
}
else{
  Chip_Clock_System_SetClockDiv(2);
}

Note that you need to enable either the high power mode (flash) or add wait states to avoid bricking the chip. Both options are illustrated above.   

0 项奖励
回复

1,139 次查看
nicolas_woedy
Contributor II

Simple answer is: Not possible because of the ADC conversion time.

0 项奖励
回复

1,139 次查看
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi Randall,

Please look at the recommendations that we provide included in the NSH31xx SW AP

  1. Initialize the ADC/DAC driver with Chip_ADCDAC_Init.
  2. Configure the ADC/DAC driver with appropriate input connection (ADC operation) with Chip_ADCDAC_SetMuxADC or output connection (DAC operation) with Chip_ADCDAC_SetMuxDAC.
  3. If required, configure ADC threshold with Chip_ADCDAC_Int_SetThresholdLowADC and Chip_ADCDAC_Int_SetThresholdHighADC.
  4. Start an ADC conversion with Chip_ADCDAC_StartADC, or start a DAC output with Chip_ADCDAC_StartDAC.
  5. Wait for the conversion (ADC or DAC) to be ready with Chip_ADCDAC_ReadStatus.
  6. Read the ADC conversion value with Chip_ADCDAC_GetValueADC.

 

Please let me know your findings,

 

Regards,

Mario

0 项奖励
回复