gueei / DShot-Arduino

DShot implementation for Arduino using bit-banging method
71 stars 25 forks source link

Question about timing #9

Open finnBsch opened 1 year ago

finnBsch commented 1 year ago

Hi, Using your library, I managed to control a DSHOT ESC with an Arduino Uno. Now, I want to use a Teensy 4.1 for that. I've written a library that uses DMA and FLEXPWM timers to achieve that, though these details shouldn't matter here. The way it works is:

Now, this would lead to the program spamming these 16 bits repeatedly, leading to no pauses between each group of 16 bits. To address this issue, I made the group of bits longer and padded it with zeros that should introduce a pause between the frames. For example, if I would choose to add 2 bits, I would have a group of bits of length 18 with the first 16 bits being the DSHOT bits and the last two bits being padded zeros. This however doesn't seem to be enough for the ESC to reliably detect the DSHOT protocol. Knowing that it worked on an Arduino Uno with the code of your library, I want to model the pauses exactly as long as you did. I suspect the pause between DSHOT frames here is introduced through the interrupt timer that sends out the DSHOT 16 bits. However, not being very familiar with that topic, I am struggling to understand how long that pause is for your library. Could you help me out?

Spir0u commented 1 year ago

At https://github.com/gueei/DShot-Arduino/blob/master/src/DShot.cpp#L215 it states that the routine is called with 500 Hz, therefore only all 2 ms. I often use https://brushlesswhoop.com/dshot-and-bidirectional-dshot/ or https://www.speedgoat.com/products/dshot for DShot specifications. There it states that a 21-bit reset time is recommended, but a 2-bit reset should be enough. But I think the problem you encounter is that in the reset time you should not send bits, as by sending "0" bits the signal still rises to high for some time, what you want is that the signal is "flat" in that time (0 V for the whole reset time).