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

Capturing GPIO transitions of a 4kHz signal with BLE enabled

I need to capture the time between rising transition of a GPIO pin in order to integrate a Manchester decoder of an RFID reader chip. In my particular case, the reader chip emits a waveform where the minimum time between the rising edges is ~256uS. The device I'm working on is a BLE peripheral and ideally, I'd like to run both interfaces concurrently.

This is all running on an nRF52840-DK board with FreeRTOS.

I hacked together an initial prototype where

  1. I linked a PPI with GPIOE and TIMER1 where the rising edge causes the timer count to be captured
  2. An IRQ on the GPIO rising edge to cache the last capture (thus getting a very accurate measurement)

This all works fine when BLE is disabled, however as soon as enable it (the device starts advertising), I appear to be missing transitions.

I'm yet to really drill down to identify how/when the transitions are missed, however I thought I might check to see if anyone can suggest a better scheme to capture the timing.

Thanks.

DJ

  • dj1234 said:
    The STARTED event is generated when SAADC starts filling in the supplied buffer.
    dj1234 said:
    An Interrupt is generated where I'm free to update the RESULT.PTR register.

    The STARTED event is generated after the RESULT.PTR and RESULT.MAXCNT registers have been read and loaded by the SAADC peripheral. At which point it is safe to update the .PTR and .MAXCNT registers again by the application. When the END event is fired a START task can be immediately triggered to load the next .PTR and .MAXCNT values into the SAADC. 

    You can, for instance, connect the START task to the END event via PPI, given that the .PTR and .MAXCNT registers have been updated since the last STARTED event fired. 

    static void ppi_saadc_init()
    {
    	NRF_PPI->CH[0].EEP = (uint32_t)&NRF_SAADC->EVENTS_END;
    	// NRF_PPI->CH[0].TEP = (uint32_t)&NRF_SAADC->TASKS_SAMPLE; Undefined operation, STARTED event must fire before sampling can continue.
    	NRF_PPI->FORK[0].TEP = (uint32_t)&NRF_SAADC->TASKS_START;
        nrf_ppi_channel_enable(NRF_PPI_CHANNEL0);
    }


    It seems that you trigger the sample task via CPU at regular intervals, I recommend that you instead employ a TIMER's COMPARE event to trigger the SAMPLE task, trigger the TIMER's START task from the SAADC's STARTED event, and trigger the TIMER's STOP task from the SAADC's END event.

    This will set up a continuous cycle of sampling with a fixed delay between the END event and until the first sample is taken.
    You can even refreign from stopping the TIMER at the END event and let it run to get a truly jitter-free sample rate across all buffers, but only if the SAADC's STARTED event has fired before the first SAMPLE task is triggered by the TIMER. I don't know the exact time from the SAADC's started task until it fires the STARTED event btw.

    Also, by enabling the shortcut between a TIMER's COMPARE event and it's CLEAR task you create a free-running timer. See SHORTS


  • Ok got it working! Here's my flow 

    1. SAADC points to a sample buffer to capture 512us worth of samples
    2. Start SAADC (loads the contents RESULT.PTR registers and generates a STARTED event)
    3. PPI initiates Sampling of the SAADC on the STARTED event
    4. STARTED event generates an interrupt. Prepare the RESULT.PTR register with the next buffer
    5. SAADC generates an END event when sampling buffer is full
    6. PPI Starts the SAADC on the END event (outcome same as step 2)
    7. END event generates an interrupt. Notify the thread that sampling is complete.
    8. Thread processes the buffer with the sampling data that was complete

    I measured a 4kHz input signal and the period measurement was spot on. Thanks a lot for your help haakonsh.

  • hi dj1234

    i have the same question about capture gpio to read manchester code. do you solve the problem and it is possible to get the code from you?

Related