This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf52 SAADC manually starting/stopping scan mode

Hi, 

I need the SAADC of the nRF52840 to do the following: 

It should sample two channels as fast as possible for a certain time (or for a certain amount of samples). 

The sampling should be started manually (not by an external timer). 

After the sampling (after enough samples are taken or after a certain time has passed), the sampling shall be stopped and low power mode should be entered. 

I managed to get several SAADC examples running, however, all of them work with external timers and the sampling rate is just too slow (because the sampling is triggered by the timer and the triggering time is always a feq ms in all examples...) and i cant start and stop the sampling manually. 

I dont get the documentation, it confuses me and I really don't know how to implement the solution... 

Can you provide me an example for my problem?

Parents
  • Hi,

    You can start with one of the SAADC examples in the SDK and modify it to your liking. For starting the sample manually you can use nrf_drv_saadc_sample() function.

    Best regards,

    Marjeris

  • Hi

    Thank you for your answer. 

    A call to nrf_drv_saadc_sample will trigge one sample per channel, you will need to call it 10 times to generate 20 results in the buffer if you have 2 channel actives. If you call it in a while loop then the next sample will be trigger as soon as the previous one is done.

    As mentioned before, I want to collect as many samples as possible within a certain period of time (within two signal triggers), where the time between each sample should be constant for further signal processing.
    I could measure the n samples by simply calling the function nrfx_saadc_sample() n times in a row, e.g:

    void measure_samples(n)
    {
      uint16_t i = 0; 
      for(i=0;i<n;i++)
      {
        nrf_drv_saadc_sample();
      }
    }

    I find it hard to believe that with such a solution the maximum sampling rate (in my case 100kHz) can be reached, since the for-loop needs execution time as well. Even if the execution time is certainly very fast, I have no more control over how fast the individual samples are actually sampled. 

    Another solution would be to call the function nrfx_saadc_sample() via a timer (e.g. with PPI Channel as in the peripheral/saadc example). With this approach the samples would be measured within a well defined time intervall. 

    In the peripheral/saadc/ example, the timing interval is set in the saadc_sampling_event_init() function using the nrf_drv_timer_ms_to_ticks() function. But I want to set a timing interval which is faster than 1ms to get the desired 100kHz sampling rate. Can you tell me, how to achieve a faster timing intervall? 

    Or would you suggest to implement the solution with the for-loop?

    Thanks a lot for your answer. 

    Kind Regards

  • Hi,

    Sorry for the late reply. I wasn't aware that you needed a sample rate of 100kHz. In that case I agree it would be difficult to achieve without the use of TIMER.

     You can use nrf_drv_us_to_ticks() or you can set the ticks manually to have full control. For example 160 ticks will give you 100kHz if the timer runs on 16MHz, or 10 ticks if the timer runs on 1MHz.

    Best regards,

    Marjeris

Reply Children
No Data
Related