Skip to content

Remove DSHOT_PAUSE_BIT to fix DSHOT outputting 18 bits - #3417

Closed
CapnBry wants to merge 7 commits into
ExpressLRS:masterfrom
CapnBry:dshot-nopause
Closed

CapnBry wants to merge 7 commits into
ExpressLRS:masterfrom
CapnBry:dshot-nopause

Conversation

@CapnBry

@CapnBry CapnBry commented Nov 24, 2025 •

Copy link
Copy Markdown
Member

Removes the extra 2 bits appearing in the DSHOT output after #3140. Also adjusts DSHOT 300 timing:

Name DSHOT 300 Was Now
Bit Period 3.33us 3.20us 3.30us
1 High Time 2.50us 2.40us 2.50us
0 High Time 1.25us 1.20us 1.30us

Bad DSHOT data

In addition to the bit timing being too short, there were extra bits appearing in the output of each frame. There should be 16 "high" sections in a DSHOT packet

image

The timing was also a little short, with each bit period being 0.13us too short and each "high" period being 0.10-0.15us too short. I don't believe this is an issue for ESCs but the decoder I downloaded for Logic didn't appreciate it so I've increased the all high bits and the bit period by 0.1us.

image

To fix the output, I just removed the DSHOT_PAUSE_BIT, which was supposed to be a blank RMT item that assured there was a delay between each DSHOT packet when sent in hardware RMT looping mode. As the looping is now handled in software, the delay isn't needed as we can adjust the timing as we see fit. I have no idea what the original author of DShotRMT was smoking when they set the delay to 10000 - (16*ticks_per_bit) - 1. The desired amount is 21 bit periods or 69.93us. That formula gives 9487 ticks or 948.7us or 0.9487ms. It should be just DSHOT_PAUSE * ticks_per_bit, which also fixed the bad DSHOT data, but again, we don't need the pause at this time. EDIT: Oh I figured it out. They were setting a 1ms looping period.

RMT Busy Time

The RMT stays "busy" for 240us to 460us as measured by using another pin to flag the start of output_rmt_data() to the time where rmt_wait_tx_done() doesn't return TIMEOUT any more. It is usually in the 240-250us range but there are some anomalies, possibly due to our giant packet-receiving ISR blocking the measurement code from executing. I swapped out all the existing 500us fixed delay and rmt_get_channel_status() for just querying the single channel's TX status since it seemed more direct. I did not test this on a C3-based RX though.

DSHOT Packet Interleaving

The behavior of the old DSHOT use all the RMT units and just loop sending the output every 1ms. Now only one RMT is used and each channel is sent out every 2ms, or if it has been updated since the last send. This may present a logic analyzer trace that looks broken compared to the old behavior, but this should be fine for ESCs. Betaflight outputs DSHOT anywhere from 0.125us (8KHz) to 2ms (500Hz). This code operates up to 1KHz per ExpressLRS output and can probably do 4000 updates per second total (250Hz x 16 channels) but we might need to optimize a little to hit that.

Refactoring

This code needs some cleanup but in the interest of just trying to fix the bad output, I've only modified what was needed.

@CapnBry CapnBry changed the title Remove DSHOT PAUSE_BIT to fix DSHOT outputting 18 bits Remove DSHOT_PAUSE_BIT to fix DSHOT outputting 18 bits Nov 24, 2025
@pitts-mo

Copy link
Copy Markdown
Contributor

Thank you CapnBry, :-) Pulseview appears to see constant signal output now. But now the Dshot decoder shows notable gaps between valid Dshot commands. AM32 must be seeing these gaps as well because my AM32 stopped a few times and then allowed me to re-init on center throttle. (dshot3d).

4ec72de-2pwm_dshot_dshot3d

@CapnBry

CapnBry commented Nov 25, 2025

Copy link
Copy Markdown
Member Author

Huh I didn't see that in my testing but I didn't do very long tests.

Can you tell me exactly what hardware you're running again and which output channels you have set to dshot? I would like to try to reproduce it. No rush though because I will be gone for the rest of the week!

@pitts-mo

pitts-mo commented Nov 25, 2025 via email

Copy link
Copy Markdown
Contributor

@CapnBry

CapnBry commented Nov 25, 2025

Copy link
Copy Markdown
Member Author

Thanks for the details, I'll be able to test it when I get back on Sunday.

Flipping this to DRAFT PR since this needs to be resolved before merging.

@CapnBry
CapnBry marked this pull request as draft November 25, 2025 12:20
@CapnBry

CapnBry commented Nov 25, 2025

Copy link
Copy Markdown
Member Author

Looking at your capture though, I still see D3 and D4 showing activity even when the decoder shows no activity. Your sample rate is only 1MS though and I can't get any clean decodes at that rate, since the bit period would be 3.33 samples and it is likely it can't reliably pick up the bits in the packet at that rate (which have 1.25us 2.5us 0.83us and 2.08us pulses). I have to sample at 4MS at least before I start seeing valid CRCs all the time, and 8MS is closer to what is actually needed.

That you said the ESC stopped seems to indicate there might be more to what you're saying, but on the SuperP I was testing with, I could run for minutes and not see any gap at all (although I didn't check all the CRCs), and again your D3/D4 area on the top shows things are still transmitting, so it seems like the PulseView decodes might not be a great indicator of if it is working. I do not know what AM32's requirements are for DSHOT packet frequency but less than 2ms would be ridiculously low.

@pitts-mo

pitts-mo commented Nov 25, 2025 •

Copy link
Copy Markdown
Contributor

Sampling @ 4Mhz allows the pulseview decoder to read all DSHOT packets. Thank you @CapnBry !

I will try to do more testing over the next few days but here is what I have so far:

I observe CRC errors only when throttle value is transitioning (ch4 Dshot3D) but I do not see any errors while throttle value remains constant.
4ec72de-4Mhz-CRC-errors
4ec72de-bad-packet

4Mhz also makes the noise I see on ch1 more interesting:
4ec72de-4Mhz-ch1-noise

@mha1

mha1 commented Nov 26, 2025 •

Copy link
Copy Markdown
Contributor

The end marker is causing the problem as it sporadically adds a brief HIGH which is interpreted as fifth CRC bit. This fails the CRC check. Changing DShotRMT.cpp line 114 fixes the CRC errors. I have updated this PR, please retest if you can.
image
image

@pitts-mo

Copy link
Copy Markdown
Contributor

Confirmed. 9c33c60 did not have a single CRC error in 5 second sample. Thank you @mha1

@pitts-mo

Copy link
Copy Markdown
Contributor

This does seem more reliable. However, AM32 (dshot3d) may re-arm several times after link is established in about 1 of 5 power ups. And I had one instance where am32 stopped during test and had to re-arm.

Gaps in dshot packets every 128ms.
9c33c60-missing-packets-and-decordes

Even @ 8MHz PulseView is still failing to decode some dshot packets.
9c33c60-dshot-decode-fail

@mha1

mha1 commented Nov 27, 2025

Copy link
Copy Markdown
Contributor

Which packet rate, switch mode, tlm ratio are you running?

PWM spikes: this looks very much like crosstalk. Can you show a picture of how the logic analyzer is wired to the receiver.

@pitts-mo

Copy link
Copy Markdown
Contributor

Very good points to question :-) Since mid October I have been using F1000, Wide, Std on my test hardware to help understand #2882 and #3248. Crosstalk was definitely an issue for spurious noise. The samples below were after some wiring clean up. Tests at 150Hz have made me more curios if we are able to get Dshot packets to send more regularly.

F1000, Wide, Std :
9c33c60-F1000

150Hz, Wide, Std:
9c33c60-150Hz

And now for you validation and my embarrassment :-)
Before:
P1010001

After:
P1010002

@mha1

mha1 commented Nov 27, 2025

Copy link
Copy Markdown
Contributor

I have pushed another commit to have accurate DShot300 1.25us/2.5us timing. I doubt it'll make a difference for your setup. But what the heck, why not have accurate timing.

Here's 10s of trace data with properly shielded wires at 150Hz/Wide/Std. As far as I can see everything works great, all data frames decoded, no gaps, no errors:
150Hz-Wide-Std.sr.log (remove the .log extension)

@pitts-mo

pitts-mo commented Nov 28, 2025 •

Copy link
Copy Markdown
Contributor

Thank you @mha1 ,
Yeah, the dshot packet timing in your sample are rather consistent with only minor timing shifts between packets and zero decode/CRC error. What RX was used for your Dshot sample? ch1-4 = D1-4?

With 1820803 I see zero CRC error. However, still find sporadic dshot decode failures on my samples. All decode failures appear to have consistent packets of 14 bits instead of 16.

My RP4TD PWM pins are 1,3,18,5 and I find incomplete packets...
when ch3 Dshot and ch4 Dshot3D :
Dshot = 00000110000000
Dshot3D = 00000000000000

when ch3 Dshot and ch4 Dshot :
Dshot = 00000110000001
Dshot3D = 10000011000010

In the next few days I will try another full erase and alternate RX configurations to see if I can get consistent complete dshot packets.

@mha1

mha1 commented Nov 28, 2025

Copy link
Copy Markdown
Contributor

What RX was used for your Dshot sample? ch1-4 = D1-4?

It's a BetaFPV SuperP 14ch. rows 0-3 are channels 4-7

image

@mha1

mha1 commented Nov 28, 2025 •

Copy link
Copy Markdown
Contributor

This is reproducing Dshot = 00000110000000, Dshot3D = 00000000000000:
000001100000.sr.log
00000110000000.pvs.log

No incomplete packets, no errors. Unfortunately I don't have a RP4-TD. @CapnBry has one and if he finds time he'll test this PR. Please attach your hardware.json file. Start WiFi and enter 10.0.0.1/hardware.json.

image

@pitts-mo

Copy link
Copy Markdown
Contributor

Removing the primary RX and TX pin assignments was triggering my sporadic 14bit Dshot packets. I see 100% 16 bit Dshot packets as long as RX and/or TX have pin assigned.

example hardware.json that produces sporadic 14bit packets:
RP4TD_null-RX1-TX1-pins_14bit-dshot-packets_hardware.json

I no longer suspect any problems with Dshot packets under this PR.
Thank you both for your help.

@CapnBry

CapnBry commented Dec 1, 2025

Copy link
Copy Markdown
Member Author

Strangely, rmt_wait_tx_done() can return that the transmission was completed a few bits before the RMT is done sending, around 46us from the start of the packet (the transmission takes ~55us). For some reason, if Serial1's RX/TX pins are not defined, this happens more frequently than if they are not. I've moved some code around such that it seems to not get cut off in my short testing.

This round-robin code is way too fragile and not in obvious ways. The polling method also will make bidirectional dshot difficult to pull off, because the pin needs to switch to receive in under 26us from the last bit leaving the RMT and there's no guarantee of that given the polling loop system. That means we'll have to throw out a lot of this code for the next version, and there is no benefit to using this round-robin setup at this time (no hardware needs it) so I'm going to move to just revert #3140 and take another shot at this for 4.1.

@pitts-mo I know that having the CRSF RX/TX pins filled in were the only way you were able to get reliable DSHOT, but that is for sure undefined behavior for our code. If the pins are used in the PWM pins list, then they must not appear as serial pins as well. Both sections of code will attempt to drive the pins and can result in sketchy behavior. If they are in the PWM list, then they can only be used as serial by setting their PWM function to serial. In your future hardware mods, make sure to not use the pins in both places, although I am kinda glad you tried that because this is certainly some weird behavior you've uncovered!

@CapnBry CapnBry added the closing 🚪 Will close if no new information is reported label Dec 1, 2025
@CapnBry CapnBry closed this Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfixes 🐞 closing 🚪 Will close if no new information is reported V4.0 🍔

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants