GPIO input detection via M7-core

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GPIO input detection via M7-core

1,323 Views
pratham_malaviya
Contributor III

Hi there, 

We are implementing a system in which we are detecting up to 1 MHz of PWM signal on the input GPIO pin. 

Now the issue we are facing is high read latencies.

Here are test cases with the approaches I used:

First, we took a pair of input and output GPIOs. 

Approach-1: Polling

  • Keep reading the state of the input GPIO and copy it to the output GPIO.
  • Tested Frequencies: 100 kHz, 500 kHz, and 1 MHz. 
  • Fast slew rate of output GPIO.
  • Tried implementing bare metal instead of wrapper functions.

Conclusion:

  • Till 100 kHz it works fine, but on higher frequencies there are hard delays of around ~1.5. us.

Approach-2: Using Interrupt

  • Configure the input pin as an IRQ source, and when the rising edge is detected, toggle the output GPIO from ISR.

Conclusion:

  • Same as the polling approach when the PWM frequency was at 500 kHz. The interrupts were missed.

So, my queries are as below:

  1. What are the causes of these hard delays?
  2. Is it theoretically possible to do what we are trying?
  3. Any other possible approach you can suggest>

Thanks and regards,

Pratham.

0 Kudos
Reply
3 Replies

1,233 Views
pratham_malaviya
Contributor III

Hi @Manuel_Salas ,
Any update on above issue? 

Regards,

Pratham

0 Kudos
Reply

1,305 Views
Manuel_Salas
NXP TechSupport
NXP TechSupport

Hello @pratham_malaviya 

I hope you are doing very well.

 

Theoretically, It should be possible, but accessing GPIOs through the general-purpose I/O registers (even when using bare metal) has inherent latencies due to memory access overhead.

You can try to use RTOS and use the taskENTER_CRITICAL() function and measure if there is an improvement.

 

I hope this can helps to you.

 

Best regards,

Salas.

0 Kudos
Reply

1,284 Views
pratham_malaviya
Contributor III

Hi @Manuel_Salas ,

Thank you for your support!

 

As per your suggestion, I implemented it using RTOS, but some hard delays still remain.

I am attaching a code snippet and a logic analyzer capture for your reference.

Channel-1: Output GPIO 
Channel-2: PWM signal fed to input GPIO.

I am still confused about these hard delays. The clock root for the GPIO is around 133 MHz, yet register access still takes a significant amount of time.

 

static void hello_task(void *pvParameters)
{   
    for (;;)
    {
    //    PRINTF("Hello world.\r\n");
        taskENTER_CRITICAL();
        state = GPIO_PinRead(INPUT_GPIO,INPUT_GPIO_PIN);
        GPIO_PinWrite(EXAMPLE_LED_GPIO,EXAMPLE_LED_GPIO_PIN,state);
        taskEXIT_CRITICAL();
       // vTaskSuspend(NULL);
    }  
}   

 

 

0 Kudos
Reply