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

NRF52840 SAADC configuration with easyDMA interrupt after x samplings

hello Nordic

i am using nrf 52840 dev kit, sdk 16.0

i want to make a sampling of 2 channels at 32MHz rate. the data shell be passed to RAM via easyDMA, after every 4 samplings i whish to raise an interrupt so i can average the readings from each channel. 

(as i understand if i do oversampling and burst then it reads one channel several time and averaging and then do the same for the other channel, this solution is not good for me because i need to compare the reading of the 2 channels with each other so the data needs to be collected as simultaneously as possible) 

what the optimal way to achieve the above ?

also, if i use app_timer as the RTC timer for the saadc, does it involves the CPU ?, can it use ppi? (the name "app" makes me suspicious :) ) and is it a good solution for 32MHz sampling rate or is it to fit ?

best regards

Ziv

Parents
  • Do you mean kHz or MHz?
    I ask because the SAADC has a max sample rate of 200ksps.

  • hi haakonsh 

    so i found out that instead of using the "nrf_drv_timer_us_to_ticks()" , i can just put the value 500 assuming the default prescalar is 16MHz. pleas correct me if i am wrong .

    how ever, i want to check 2 channels every 31.25 microsec (which is 32KHz) with the saadc and i see that the 

    nrf_drv_timer_extended_compare(&m_timer, NRF_TIMER_CC_CHANNEL0, TICS_FOR_32KHZ, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); //false);

    is defined for one channel, so how can i set that both channels will be sampled one after the other each timer event ? 

    also, in the saadc event handler where is the attention to which sample is read and where is the value saved ?

    void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
    {
        if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
        {...

    p.s. i am referring to the sdk example 

    last question for now is that in the future a ble will be implemented to the system, it will not work at the same time with the saadc but is there some timers issue i need to consider when adding softdevice ?

    best regards

    Ziv

  • What I'm trying to say is that if you process your samples every 50ms you will have more than enough time to service the BLE stack at the same time, instead of every 125µs (4 samples @ 32kHz).

  • hi Haakonsh

    i don't need to service the BLE at the same time. i sample for a few minutes and then i send, via BLE, all the sampled data (not just those 2 adc channels) and then go to sleep, that is the sequence. however, the adc sampling on both channels needs to be very accurate and continues as possible, if i calculate every 50ms then i have 6.4Kbyte of data to average, then process and then send to the sRAM via QSPI, i am afraid i might loos/overwrite sampled data if i can not complete all the mentioned procedure before the buffer is filled again

    so i can't see how that approach is better

    could you replay to the questions i raised in the message you replied to ?

    best regards

    Ziv

  • ziv123 said:
    so if i put the "SAMPLES_IN_BUFFER = 4 " this means i will get the "NRFX_SAADC_EVT_DONE" only after 4 sampling of the 2 channels ? or maybe i need to define one buffer with 8 bytes in it instead of 2 buffers of 4 ? pretty sure the issue is not clear for me as you can see by my questions i don't really get how this works yet, sorry for that .. hope you help me with that

     Yes you need a buffer size of 8 samples for 2 channels. 

    ziv123 said:
    also, what does the following function do in the nrf event handler when receiving an "NRFX_SAADC_EVT_DONE"  even

     It prepares the current buffer to be used again for the next iteration. The driver alternates 2 buffers. 

    I suggest you read both the prod spec and the driver implementations if you want to understand how the saadc works. 

  • It prepares the current buffer to be used again for the next iteration. The driver alternates 2 buffers. 

    so in the saadc_init function do i really need to prepper both elements of the buffer like this:

        err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0], SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1], SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);

    or is it enough to call the first convert only (with the m_buff_pool[0]) and the second element of the buff will be prepared within the NRFX_SAADC_EVT_DONE ?

    I suggest you read both the prod spec and the driver implementations if you want to understand how the saadc works.

    I have read it but not all of it and it does not make me an expert yet, there is still much clarifications to be given even after reading data sheet cause there is not enough guidance regarding programing and working with the SDK to my humble opinion, this is why i also seek for help in the forum

  • ziv123 said:
    or is it enough to call the first convert only (with the m_buff_pool[0]) and the second element of the buff will be prepared within the NRFX_SAADC_EVT_DONE ?

     No, the first time you need to call it twice with the two buffers.  

    ziv123 said:
    I have read it but not all of it and it does not make me an expert yet, there is still much clarifications to be given even after reading data sheet cause there is not enough guidance regarding programing and working with the SDK to my humble opinion, this is why i also seek for help in the forum

     I suggest you read the driver implementation as it show how to interpret the spec, also, the HAL might be easier to understand than the driver.

Reply
  • ziv123 said:
    or is it enough to call the first convert only (with the m_buff_pool[0]) and the second element of the buff will be prepared within the NRFX_SAADC_EVT_DONE ?

     No, the first time you need to call it twice with the two buffers.  

    ziv123 said:
    I have read it but not all of it and it does not make me an expert yet, there is still much clarifications to be given even after reading data sheet cause there is not enough guidance regarding programing and working with the SDK to my humble opinion, this is why i also seek for help in the forum

     I suggest you read the driver implementation as it show how to interpret the spec, also, the HAL might be easier to understand than the driver.

Children
No Data
Related