I need to measure with SAADC two channels in the same time (NRF_SAADC_INPUT_AIN6 and NRF_SAADC_INPUT_AIN4).
Is possible ?
Have you an code example?
Thanks
Marco
I need to measure with SAADC two channels in the same time (NRF_SAADC_INPUT_AIN6 and NRF_SAADC_INPUT_AIN4).
Is possible ?
Have you an code example?
Thanks
Marco
There is only one ADC - so you can only measure 1 input at any one time.
But the ADC can "scan" through each configured input
Have you an code example
Yes, there is an SAADC example in the SDK.
IIRC, it scans three inputs.
As awneil says, there is an example in the SDK which you can find in SDK\examples\peripheral\saadc.
This example only uses one pin, and one channel, but if you initialize another channel on a different pin, it will do sampling on both channels.
Dear, all.
I have activated the second channel:
#define NRFX_SAADC_PULSE_CHANNEL_CONFIG_SE(PIN_P) \ { \ .resistor_p = NRF_SAADC_RESISTOR_DISABLED, \ .resistor_n = NRF_SAADC_RESISTOR_DISABLED, \ .gain = NRF_SAADC_GAIN1_6, \ .reference = NRF_SAADC_REFERENCE_INTERNAL, \ .acq_time = NRF_SAADC_ACQTIME_3US, \ .mode = NRF_SAADC_MODE_SINGLE_ENDED, \ .burst = NRF_SAADC_BURST_DISABLED, \ .pin_p = (nrf_saadc_input_t)(PIN_P), \ .pin_n = NRF_SAADC_INPUT_DISABLED \ } #define NRFX_SAADC_INEX_CHANNEL_CONFIG_SE(PIN_P) \ { \ .resistor_p = NRF_SAADC_RESISTOR_DISABLED, \ .resistor_n = NRF_SAADC_RESISTOR_DISABLED, \ .gain = NRF_SAADC_GAIN1_6, \ .reference = NRF_SAADC_REFERENCE_INTERNAL, \ .acq_time = NRF_SAADC_ACQTIME_3US, \ .mode = NRF_SAADC_MODE_SINGLE_ENDED, \ .burst = NRF_SAADC_BURST_DISABLED, \ .pin_p = (nrf_saadc_input_t)(PIN_P), \ .pin_n = NRF_SAADC_INPUT_DISABLED \ } nrf_saadc_channel_config_t channel_config_INEX = NRFX_SAADC_INEX_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN6); nrf_saadc_channel_config_t channel_config_PULSE = NRFX_SAADC_PULSE_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN4); void saadc_init(unsigned char type) { ret_code_t err_code; err_code = nrf_drv_saadc_init(NULL, saadc_PULSE_INEX_callback); APP_ERROR_CHECK(err_code); err_code = nrf_drv_saadc_channel_init(0, &channel_config_INEX); APP_ERROR_CHECK(err_code); err_code = nrf_drv_saadc_channel_init(1, &channel_config_PULSE); APP_ERROR_CHECK(err_code); err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool_scann[0], SAMPLES_IN_BUFFER_SCANN); APP_ERROR_CHECK(err_code); err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool_scann[1], SAMPLES_IN_BUFFER_SCANN); APP_ERROR_CHECK(err_code); }
seem work but sametime in the buffer I find the values exchanged between channels. WHY ?
this is my callback function:
void saadc_PULSE_INEX_callback(nrf_drv_saadc_evt_t const * p_event) { nrf_saadc_value_t adc_result; uint16_t value_mV_local; uint16_t value_mV_acc; int i; if (p_event->type == NRF_DRV_SAADC_EVT_DONE) { ret_code_t err_code; err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER_SCANN); APP_ERROR_CHECK(err_code); adc_result = p_event->data.done.p_buffer[0]; adc_value_inex = ADC_RESULT_IN_MILLI_VOLTS(adc_result);//+ DIODE_FWD_VOLT_DROP_MILLIVOLTS; adc_result = p_event->data.done.p_buffer[1]; adc_value_pulse = ADC_RESULT_IN_MILLI_VOLTS(adc_result);//+ DIODE_FWD_VOLT_DROP_MILLIVOLTS; } }
with this code I ask a start of new conversion
nrf_drv_saadc_sample();
while(!u_STATO10.STATO10_bit.mm_EOC);
the bit mm_EOC is for waiting the end of conversion. This is set in the callback with the event DONE.
Marco
I had forgotten to say:
#define SAMPLES_IN_BUFFER_SCANN 2
static nrf_saadc_value_t m_buffer_pool_scann[2][SAMPLES_IN_BUFFER_SCANN];
Marco
Yes. The buffer isn't aware of how many channels you use, so you should set the buffer equal to N * number of channels, N=0,1,2,3,... in order to always have the same channel on the same place in your buffer.