Skip to content

Conversation

@pkendall64
Copy link
Collaborator

This PR is built on top of #2931 and should be merged after that.

Problem

As part of the serial framework refactor that happened some time ago... the sending of CRSF RC packets was moved to the main loop rather than after the packet was received. This move fixed an issue where ESP32 based receivers would crash because the UART was being accessed in the loop and in the interrupt handler.

The downside of moving the sending of the RC packet sending to the main loop is that it has created a bit of jitter in the timing.

Solution

  1. Allow the CRSF serial driver to tell the main code that it wants to send RC packets out the serial on each "tock" of the timer. The "tock" is aligned to a small period after the expected packet reception.
  2. Fix the issue where the UART was crashing when being sent in the interrupt code. This is done by wrapping the calls in noInterrupts()/interrupts().

Funky Images

Before

This is an ESP8285 receiver sending the RC packets to the FC in the main loop.
The scope has been set to 5-second persistence to show the jitter.
8285 master

This is an ESP32 receiver doing the same thing. The jitter is less but it's still there.
ESP32 master

After

These images are after allowing the CRSF driver to send the RC packets in the "tock" interrupt.
As can be seen in these images, the jitter is significantly reduced as shown by the "Dev:" deviation value in the result panel at around 5us.
ESP8285 after
8285 timer
ESP32 after
ESP32 timer

Bonus Images

These images show the relationship of the interrupt "DIO" to the sending of CRSF RC packets after the PR is applied.
Also, in these images the result panel to the right shows the delay from receiving the interrupt to sending the RC data which is approx. 220us and the deviation "Dev:" which is approx 3us.
ESP8285 1000Hz
8285 DIO -  CRSF (1000Hz)
ESP32 1000Hz
ESP32 DIO -  CRSF (1000Hz)
ESP8285 150Hz
8285 DIO -  CRSF (150Hz)
ESP32 150Hz
ESP32 DIO -  CRSF (150Hz)

@pkendall64 pkendall64 added enhancement 🪄 New feature or request V4.0 🍔 labels Sep 20, 2024
@pkendall64
Copy link
Collaborator Author

pkendall64 commented Sep 21, 2024

Bonus trace for D-mode users. This is D250 on an ESP32 true diversity receiver. Also done with 5-second persistence on the traces so you can see the jitter.
RigolDS2

Copy link
Member

@JyeSmith JyeSmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a BF BB log and its looking good!

@pkendall64 pkendall64 merged commit b1d028f into ExpressLRS:master Sep 29, 2024
@pkendall64 pkendall64 deleted the immediate-sends branch September 29, 2024 01:13
frank26080115 pushed a commit to frank26080115/ExpressLRS that referenced this pull request Oct 19, 2024
* Split RC data sending from polling and queued data sending

* Allow CRSF immediate sends when timer fires

Reduces jitter to <+-30us with a std.dev of 5us

* Document the new API function
wimalopaan pushed a commit to wimalopaan/ExpressLRS that referenced this pull request Oct 22, 2024
* Split RC data sending from polling and queued data sending

* Allow CRSF immediate sends when timer fires

Reduces jitter to <+-30us with a std.dev of 5us

* Document the new API function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement 🪄 New feature or request V4.0 🍔

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants