RMT callback delay

Nikd00
Posts: 1
Joined: Wed Mar 06, 2024 5:07 pm

RMT callback delay

Postby Nikd00 » Wed Mar 06, 2024 5:23 pm

Hi,

for my project I need to set 4 gpio outputs based on signal in form of very short pulses (tens of ns) and speed is crucial. I think RMT is great for reading the pulses, however, the callback seems to have a high latency. The code below is simplified ir_nec_transceiver example. So far it only toggles the output pin 32 when pulses are received. It takes roughly 7 us from receiving the last pulse to modifying the output. Is there any way to reduce the delay?
  1. #include "freertos/FreeRTOS.h"
  2. #include "freertos/task.h"
  3. #include "freertos/queue.h"
  4. #include "esp_log.h"
  5. #include "driver/rmt_rx.h"
  6. #include "soc/soc.h"
  7. #include "soc/gpio_reg.h"
  8.  
  9. #define OUTPUT_PINS_START 32
  10. #define OUTPUT_PINS 1111 << (OUTPUT_PINS_START-32)
  11.  
  12. #define RMT_RESOLUTION_HZ     80000000
  13. #define RMT_RX_GPIO_NUM       19
  14. #define RMT_MIN_DURATION      25
  15. #define RMT_MAX_DURATION      400
  16. #define RMT_BUFFER_SIZE       64
  17.  
  18. static const char *TAG = "mux";
  19.  
  20. uint32_t output_value = 0;
  21.  
  22. rmt_channel_handle_t rx_channel = NULL;
  23. rmt_receive_config_t receive_config = {
  24.     .signal_range_min_ns = RMT_MIN_DURATION, // A pulse whose width is smaller than this threshold will be treated as glitch and ignored
  25.     .signal_range_max_ns = RMT_MAX_DURATION, //RMT will stop receiving if one symbol level has kept more than
  26. };
  27. // save the received RMT symbols
  28. rmt_symbol_word_t raw_symbols[RMT_BUFFER_SIZE];
  29. rmt_rx_done_event_data_t rx_data;
  30.  
  31. static bool example_rmt_rx_done_callback(rmt_channel_handle_t channel, const rmt_rx_done_event_data_t *edata, void *user_data)
  32. {
  33.    
  34.     output_value++;
  35.     output_value &= OUTPUT_PINS;
  36.     REG_WRITE(GPIO_OUT1_REG, output_value);
  37.  
  38.     ESP_ERROR_CHECK(rmt_receive(rx_channel, raw_symbols, sizeof(raw_symbols), &receive_config));
  39.     return false;
  40. }
  41.  
  42. void app_main(void)
  43. {
  44.  
  45.     ESP_LOGI(TAG, "create output channels");
  46.     REG_WRITE(GPIO_ENABLE1_W1TS_REG, OUTPUT_PINS);
  47.  
  48.     ESP_LOGI(TAG, "create RMT RX channel");
  49.     rmt_rx_channel_config_t rx_channel_cfg = {
  50.         .clk_src = RMT_CLK_SRC_DEFAULT,
  51.         .resolution_hz = RMT_RESOLUTION_HZ,
  52.         .mem_block_symbols = RMT_BUFFER_SIZE,
  53.         .gpio_num = RMT_RX_GPIO_NUM,
  54.     };
  55.     ESP_ERROR_CHECK(rmt_new_rx_channel(&rx_channel_cfg, &rx_channel));
  56.  
  57.     ESP_LOGI(TAG, "register RX done callback");
  58.     QueueHandle_t receive_queue = xQueueCreate(1, sizeof(rmt_rx_done_event_data_t));
  59.     assert(receive_queue);
  60.     rmt_rx_event_callbacks_t cbs = {
  61.         .on_recv_done = example_rmt_rx_done_callback,
  62.     };
  63.     ESP_ERROR_CHECK(rmt_rx_register_event_callbacks(rx_channel, &cbs, receive_queue));
  64.  
  65.     ESP_LOGI(TAG, "enable RMT RX channel");
  66.     ESP_ERROR_CHECK(rmt_enable(rx_channel));
  67.  
  68.     // ready to receive
  69.     ESP_ERROR_CHECK(rmt_receive(rx_channel, raw_symbols, sizeof(raw_symbols), &receive_config));
  70. }

Who is online

Users browsing this forum: No registered users and 90 guests