From 4db92a9b31de65c52fbc13635fb5b47a8878e006 Mon Sep 17 00:00:00 2001 From: Wastl Kraus Date: Fri, 25 Jul 2025 12:15:52 +0200 Subject: [PATCH] ...non-blocking interval ...not using "delay" anymore --- DShotRMT.cpp | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/DShotRMT.cpp b/DShotRMT.cpp index 5b7056a..2f8579a 100644 --- a/DShotRMT.cpp +++ b/DShotRMT.cpp @@ -84,25 +84,31 @@ void DShotRMT::begin() // Encodes and transmits a valid DShot throttle value (48 - 2047) void DShotRMT::setThrottle(uint16_t throttle) { - // Clamp input range for packet - _dshot_packet.throttle_value = constrain(throttle, DSHOT_THROTTLE_MIN, DSHOT_THROTTLE_MAX) & 0b0000011111111111; + // Simple timer + static long last_time = 0; - // Calculate CRC for every throttle value - calculateCRC(&_dshot_packet); - - // Encode RMT symbols - size_t count = 0; - encodeDShotTX(&_dshot_packet, _tx_symbols, count); - - // Transmit the packet - if (rmt_transmit(_rmt_tx_channel, _dshot_encoder, _tx_symbols, count * sizeof(rmt_symbol_word_t), &_transmit_config) != 0) + // Keep a pause between the frames + if (micros() - last_time >= _pauseDuration) { - Serial.println("Failed to transmit DShot packet"); - return; - } + last_time = micros(); - // Pause between frames - esp_rom_delay_us(_pauseDuration); + // Clamp input range for throttle value + _dshot_packet.throttle_value = constrain(throttle, DSHOT_THROTTLE_MIN, DSHOT_THROTTLE_MAX) & 0b0000011111111111; + + // Calculate CRC for every throttle value + calculateCRC(&_dshot_packet); + + // Encode RMT symbols + size_t count = 0; + encodeDShotTX(&_dshot_packet, _tx_symbols, count); + + // Transmit the packet + if (rmt_transmit(_rmt_tx_channel, _dshot_encoder, _tx_symbols, count * sizeof(rmt_symbol_word_t), &_transmit_config) != 0) + { + Serial.println("Failed to transmit DShot packet"); + return; + } + } } // Receives and decodes a response frame from ESC containing eRPM info