Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

SAADC samples missing

Hi,

I'm implementing a hard real-time system (few us jitter) on nRF52840, SDK17.1, based on FreeRTOS project.

In the project, I need to sync GPIOs toggling with ADC sampling. There is heavy EGU-Timers-PPI-GPIOTE/SAADC work done (see attached picture)

However, I can't get the SAADC work reliably, and I get samples missed.

The setup is as follows:

I need to sample 4 adc channels (AIN4-7) at 4 specific times t1-t4 (200-250us apart)

For that I use PPI channel and tie T3_COMPARE1 event to SAADC_SAMPLE task.

I set up T3CCR1 = t1(=200us) and enable T3 interrupts

As T3 needs to run in sync with T4 (that toggles 5 GPIOTEs), both are started using another PPI channel that ties EGU1.1->T4_START and T3_START (as fork)

When T3CC1 gets to t1=200us, SAADC_SAMPLE is triggered (by the PPI) and the saadc samples 4 channels in SCAN mode

Concurrently T3 interrupt is triggered in which I set T3CC1 = t2 (& t3 & t4=850us on subsequent interrupts)

The same trick is used on T4 to generate a sequence of signals (T4CC0 used to generate interrupts).

The last T4 interrupt is triggered at t4+100us=950us, at this point I should get 4*4=16 adc samples in the buffer

(side note - converting AIn4-7 consume 35us, far less than 100us span from tast T3CC1 interrupt to T4CC0 interrupt)

For debug I use 2 counters - SamplesCounter incremented in saadc_hadler() & SequncesCounter incremented at the last interrupt of T4 (t=950us)

On each 'burst's last interrupt (t=950us) I check that these counters are identical.

Now, occasionally I find that these counters do not match and the SamplesCounter was not incremented.

Looking at SAADC.AMOUNT register shows 0 or another small number of samples actually taken (e.g. 2 samples) instead of the expected 0x10 (see image)

To debug I replaced the T3_COMPARE1 --> SAADC_SAMPLE ppi trigger with nrfx_saadc_sample() call in T3CC1 interrupt and count these invocation as well.

This way I can count the actual SAMPLE tasks triggered, which should be 4*SamplesCounter but this verification also fails.

Looked though the erratas as well. I noticed Errata 212, not sure if its relevant but I've extended acquisition times to 10us or more on all 4 channels (and pushed 200us forward the 950us interrupt just to give some room for the last conversion). Still not helping.

I know its complicated description, but it's a complicated situation ;)

Thanks for reading this far.

Any advice is appreciated as I'm scratching the bottom of the ideas bucket...

Thanks

Parents
  • Hi Eyalasko

    What Acquisition time did you set?

    I made a FW with 8 channels & 220us period scan and it works well

    But I set minimal Acquisition time

    /* Bits 18..16 : Acquisition time, the time the SAADC uses to sample the input voltage */
    #define SAADC_CH_CONFIG_TACQ_Pos (16UL) /*!< Position of TACQ field. */
    #define SAADC_CH_CONFIG_TACQ_Msk (0x7UL << SAADC_CH_CONFIG_TACQ_Pos) /*!< Bit mask of TACQ field. */
    #define SAADC_CH_CONFIG_TACQ_3us (0UL) /*!< 3 us */
    #define SAADC_CH_CONFIG_TACQ_5us (1UL) /*!< 5 us */
    #define SAADC_CH_CONFIG_TACQ_10us (2UL) /*!< 10 us */
    #define SAADC_CH_CONFIG_TACQ_15us (3UL) /*!< 15 us */
    #define SAADC_CH_CONFIG_TACQ_20us (4UL) /*!< 20 us */
    #define SAADC_CH_CONFIG_TACQ_40us (5UL) /*!< 40 us */

Reply
  • Hi Eyalasko

    What Acquisition time did you set?

    I made a FW with 8 channels & 220us period scan and it works well

    But I set minimal Acquisition time

    /* Bits 18..16 : Acquisition time, the time the SAADC uses to sample the input voltage */
    #define SAADC_CH_CONFIG_TACQ_Pos (16UL) /*!< Position of TACQ field. */
    #define SAADC_CH_CONFIG_TACQ_Msk (0x7UL << SAADC_CH_CONFIG_TACQ_Pos) /*!< Bit mask of TACQ field. */
    #define SAADC_CH_CONFIG_TACQ_3us (0UL) /*!< 3 us */
    #define SAADC_CH_CONFIG_TACQ_5us (1UL) /*!< 5 us */
    #define SAADC_CH_CONFIG_TACQ_10us (2UL) /*!< 10 us */
    #define SAADC_CH_CONFIG_TACQ_15us (3UL) /*!< 15 us */
    #define SAADC_CH_CONFIG_TACQ_20us (4UL) /*!< 20 us */
    #define SAADC_CH_CONFIG_TACQ_40us (5UL) /*!< 40 us */

Children
No Data
Related