RMT IR Rx - Processing Ring buffer takes 1000ms each cycle even when empty
Posted: Sun Dec 12, 2021 5:11 pm
I am using the RMT library to process both IR Tx (Channel 0) and Rx (Channel 1). Initially on one channel each but I plan to add more channels once I am comfortable with the performance.
I am not getting any error codes on install or run. The solution seems to be working. but it is dog slow and I haven't incorporated the other receive channels and features I would like to include in this project. Before proceeding I want to make sure the performance issue is resolved with this ring buffer parsing process.
The library seems to be working and I am successfully parsing data between my ESP32 solutions. However, my routine for processing the data in the ring buffer is taking 1000ms each cycle to complete and this is when no IR data is being sent.
My RX Config:
#define HEADER_US 2400 // Header is 2400 µS
#define SPACE_US 600 // Space between bits is 600 µS
#define ONE_US 1200 // Logic 1 is 12 µS
#define ZERO_US 600 // Logic 0 is 600 µS
#define OFFSET 100
My install completes once via setup
Here is my procedure that seems to take 1000ms each cycle to process the buffer. This is called from the loop() function each cycle. My assumption is that when the ring buffer is empty this would just skip processing and move on. I based this heavily from example code found in the guidance.
I am using the default ISR with the RMT. I can't seem to figure out what is hogging all of the processing time especially since no IR is being sent and I am still seeing 1000ms processing time for this procedure.
How do I know it is taking this long to run this process? I am taking a millis() comparison before and after running the bufferpull procedure and the result is showing 1000ms at the serial terminal.
Thanks in advance for any hints as to what I might be doing wrong.
I am not getting any error codes on install or run. The solution seems to be working. but it is dog slow and I haven't incorporated the other receive channels and features I would like to include in this project. Before proceeding I want to make sure the performance issue is resolved with this ring buffer parsing process.
The library seems to be working and I am successfully parsing data between my ESP32 solutions. However, my routine for processing the data in the ring buffer is taking 1000ms each cycle to complete and this is when no IR data is being sent.
My RX Config:
#define HEADER_US 2400 // Header is 2400 µS
#define SPACE_US 600 // Space between bits is 600 µS
#define ONE_US 1200 // Logic 1 is 12 µS
#define ZERO_US 600 // Logic 0 is 600 µS
#define OFFSET 100
Code: Select all
configRx.rmt_mode = RMT_MODE_RX;
configRx.channel = RMT_CHANNEL_1;
configRx.gpio_num = REC_PIN;
configRx.mem_block_num = 1;
configRx.rx_config.filter_en = true;
configRx.rx_config.filter_ticks_thresh = 200;
configRx.rx_config.idle_threshold = HEADER_US + OFFSET;
configRx.clk_div = 80; // 80MHx / 80 = 1MHz 0r 1uS per count
Code: Select all
// install the driver
esp_err_t rmt_driver_install_result = rmt_driver_install(RMT_CHANNEL_1, 1000, 0);
log_e("rmt_driver_install_result: %s", esp_err_to_name(rmt_driver_install_result));
rmt_rx_start(RMT_CHANNEL_1, true);
Code: Select all
void MyRX::BufferPull() {
unsigned long data = 0;
RingbufHandle_t rb = NULL;
rmt_get_ringbuf_handle(RMT_CHANNEL_1, &rb);
while(rb) {
size_t rx_size = 0;
rmt_item32_t* item = (rmt_item32_t*) xRingbufferReceive(rb, &rx_size, 1000);
if (item) {
rmt_item32_t* itemproc = item;
for(size_t i=0; i < (rx_size / 4); i++) {
if(itemproc->duration0 < (HEADER_US+OFFSET) && itemproc->duration0 > (HEADER_US-OFFSET)) {
for(int i=14; i >= 1; i--) {
if (itemproc[i].duration0 < (ONE_US+OFFSET) && itemproc[i].duration0 > (ONE_US-OFFSET)) {
data = data | 1 << (14 - i);
} else if(itemproc[i].duration0 < (ZERO_US+OFFSET) && itemproc[i].duration0 > (ZERO_US-OFFSET)) {
data = data | 0 << (14 - i);
}
}
DataArray[RecordCount] = DecodeData(data);
RecordCount++;
data = 0;
}
++itemproc;
}
vRingbufferReturnItem(rb, (void*) item);
} else {
break;
}
}
}
How do I know it is taking this long to run this process? I am taking a millis() comparison before and after running the bufferpull procedure and the result is showing 1000ms at the serial terminal.
Thanks in advance for any hints as to what I might be doing wrong.