Hello Everybody,
I have read these articles on the site : article_1 & article_2
I need to do something like that, read around 8000 sample with sampling rate equals to 100khz I mean get the readout from the adc, send it to the mobile to do some statistics but I found that there is a limitation on the sampling rate.
would you mind helping me or if there is something I did is not correct, check the attached code:
//ADC_CONFIG_REFSEL_SupplyOneThirdPrescaling
// Configure ADC
NRF_ADC->CONFIG = (ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos) |
(ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) |
(ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) |
(ADC_CONFIG_PSEL_AnalogInput4 << ADC_CONFIG_PSEL_Pos) |
(ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos);
NRF_ADC->EVENTS_END = 0;
NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
NRF_ADC->EVENTS_END = 0; // Stop any running conversions.
NRF_ADC->TASKS_START = 1;
while (!NRF_ADC->EVENTS_END)
{
}
NRF_ADC->EVENTS_END = 0;
NRF_ADC->TASKS_STOP = 1;
return NRF_ADC->RESULT;
}
#define num_bit 8
#define number_samples 10
#define threshold 500
static void level_meas_timeout_handler(void * p_context)
{
UNUSED_PARAMETER(p_context);
uint32_t err_code ;
for (j = 0; j < num_bit ; j++)
{
for (k=0; k < number_samples ; k++)
{
//get the adc reading
sample_I_temp[j][k] = temp_level_get();
nrf_delay_ms(1);
//nrf_delay_us(20);
}
}
for (j = 0; j < num_bit ; j++)
{
for (k=0; k < number_samples ; k++)
{
err_code = ble_level_update(&m_temp,sample_I_temp[j][k]);
if ((err_code != NRF_SUCCESS) &&
(err_code != NRF_ERROR_INVALID_STATE) &&
(err_code != BLE_ERROR_NO_TX_BUFFERS) &&
(err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
)
{
APP_ERROR_HANDLER(err_code);
}
nrf_delay_ms(10);
}
}
}
ble level update function will send the value of the adc as a notification for the mobile.