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

questions regarding saadc example

Hi

 

A few questions regarding the "saadc_pca10040" example:

  1. If I read one analog pin then what is the meaning of this matrix of values :

"static nrf_saadc_value_t     m_buffer_pool[2][SAMPLES_IN_BUFFER]; "

(less important but I wonder why to use typedef for uint16_t ->  nrf_saadc_value_t )

 

  1. I could not find the link between the ppi config to the adc channel in the " saadc_sampling_event_init()".

What if I would like to work with 3 adc inputs that each of their handler awake at different time periods via timer and ppi, how would this be implemented ?

 

  1. What is the meaning of the empty "timer_handler()" do we need to have it only for the "nrf_drv_timer_init(..)"

 

  1. Last for now, it’s a bit basic maybe, but I am not clear on the terminology of task and event in hardware or embedded use.. I know when working with free RTOS or any OS there are tasks, but here I am coding bare metal so what does it mean task and event, I know hardware Interrupts, which one is which ?
Parents
  • hi Karl

    thanks for reply

    1. can i read the analog input value each time to one uint16_t parameter instead of using a buffer (its ok for me if i miss some data i don't need to be very sensitive in that measurement?

    2. how does the sample task _addr " uint32_t saadc_sample_task_addr   = nrf_drv_saadc_sample_task_get();"  related to the "saadc_init() or "saadc_callback()" its not very clear

    3. is there another way instead of instencing a timer, like use sys tick or other clock ?

    best regards

    ziv

Reply
  • hi Karl

    thanks for reply

    1. can i read the analog input value each time to one uint16_t parameter instead of using a buffer (its ok for me if i miss some data i don't need to be very sensitive in that measurement?

    2. how does the sample task _addr " uint32_t saadc_sample_task_addr   = nrf_drv_saadc_sample_task_get();"  related to the "saadc_init() or "saadc_callback()" its not very clear

    3. is there another way instead of instencing a timer, like use sys tick or other clock ?

    best regards

    ziv

Children
  • p.s. regarding section 2.. i would like to work with 3 adc inputs that each of their handler awake at different time periods via timer and ppi, how would this be implemented ? 

  • Hello Ziv,

    ziv123 said:
    thanks for reply

    No problem at all, I am happy to help!

    ziv123 said:
    1. can i read the analog input value each time to one uint16_t parameter instead of using a buffer (its ok for me if i miss some data i don't need to be very sensitive in that measurement?

     Yes, you could supply the SAADC with a buffer of size 1, which would generate the NRF_DRV_SAADC_EVT_DONE event every time a sample is retrieved.

    ziv123 said:
    2. how does the sample task _addr " uint32_t saadc_sample_task_addr   = nrf_drv_saadc_sample_task_get();"  related to the "saadc_init() or "saadc_callback()" its not very clear

    saadc_init() is the function that initializes the use of the SAADC module. It configures the SAADC (channel(s) that the SAADC should sample, and channel parameters) as well as providing the SAADC with the buffers in which to place the samples taken. All of the above must be done in order to use any of the SAADC functionality at all.
    The saadc_callback function is the function that will be called when SAADC events is generated, and is necessary for anything to actually happen with the data you are collecting.

    With the SAADC configured, it will have a sample_task address, as mentioned in the Tasks vs. event answer by my colleague. This task address must be linked to the timer event by PPI, so that the sample task triggers every time the timers compare event is generated. This connection is made in the saadc_sampling_event_init function.

        uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&m_timer,
                                                                                    NRF_TIMER_CC_CHANNEL0);
        uint32_t saadc_sample_task_addr   = nrf_drv_saadc_sample_task_get();
    
        /* setup ppi channel so that timer compare event is triggering sample task in SAADC */
        err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,
                                              timer_compare_event_addr,
                                              saadc_sample_task_addr);

    Notice how the sampling task and timer compare event addresses are retrieved, before being linked together by the PPI channel.

    To gain a better understanding of how this works, I highly recommend that you sit down with the SAADC example I mentioned, and experiment with it. Make changes to the parameters, and see the changes reflected in the output data. Modify input channels, numbers, configurations, sample task triggers, etc. to familiarize yourself with the SAADC functionality.

    ziv123 said:
    3. is there another way instead of instencing a timer, like use sys tick or other clock ?

    There are multiple timers you could use. What in particular are you looking for?
    Using PPI you could link your sample task to any peripheral event.
    I recommend using with the app_timer module if you are planning on making it a periodic sampling.

    ziv123 said:
    p.s. regarding section 2.. i would like to work with 3 adc inputs that each of their handler awake at different time periods via timer and ppi, how would this be implemented ? 

    Then you must either use the scan mode of the SAADC to perform a sampling of all enabled channels - and then just retrieve the one sample you are interested in at that time, and disregard the others.
    Or, you may enable the SAADC channel in question each time its sample task triggers, and then disable it again when the sample has been collected.
    I would recommend the latter method of enabling and disabling the channels as you need them - mind you that this will require some CPU ticks each time it is done.

    Best regards,
    Karl

     

Related