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
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.
Simple answer is: Not possible because of the ADC conversion time.
Hi Randall,
Please look at the recommendations that we provide included in the NSH31xx SW AP
Please let me know your findings,
Regards,
Mario