Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

DShot implementation for the RP2040 using a single PIO block, for up to 4 ESCs

License

NotificationsYou must be signed in to change notification settings

peterkrull/dshot-pio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This crate utilizes a single PIO block of the RP2040, enable it to send up to four DShot ESC commands (per PIO block, there are 2 of them) simultaneously, making it a great fit for quad-copters. The crate supports both theembassy-rp andrp2040-hal hardware abstraction layers (HAL). To use either HAL, the corresponding featuremust be enabled, using either feature below.

dshot-pio = {git ="https://github.com/peterkrull/dshot-pio",features = ["embassy-rp"] }dshot-pio = {git ="https://github.com/peterkrull/dshot-pio",features = ["rp2040-hal"] }

Creating theDshotPio struct is then a matter of passing into the constructor the PIO block to use, a single HAL-specific item, and the four pins to use as DShot ouputs. The last argument is the clock divider. In order to get reliable transmission to the ESCs, it is important to set the clock divider correctly. The formula for doing so is the following, wheredshot speed is the number indicating speed, eg 150, 300, 600 and so on. The system clock can vary from board to board, but generally 120 Mhz to 133 Mhz is common for RP2040 boards.

$$\text{clock divider} = \frac { \text{system clock} }{8 \cdot \text{dshot speed} \cdot 1000} $$

This clock divider is passed to the constructor in two parts, consisting of the integer part, and the fraction. Generally stuff after the decimal point of theclock divider can be ignored, meaning that is should be good enough to pass only the integer part. Otherwise the remainder should be passed as(remainder * 256 ) as u8


Construction

Constructing the motor struct looks slightly different, depending on whether therp2040-hal orembassy-rp HAL is used. The functionality of the resulting struct is however shared through a trait. The number of DShot drivers needed can be changed using the first number in the turbofish.

use dshot_pio::rp2040_hal::*;let dshot_rp2040_hal =DshotPio::<4,_>::new(    pac.PIO0,&mut pac.RESETS,    pins.gpio13.into_mode(),    pins.gpio7.into_mode(),    pins.gpio6.into_mode(),    pins.gpio12.into_mode(),(52,0)// clock divider);

For embassy, it is currently necessary to use a macro to correctly bind an interrupt.

bind_interrupts!(structPio0Irqs{PIO0_IRQ_0 =>InterruptHandler<PIO0>;});use dshot_pio::embassy_rp::*;let dshot_embassy =DshotPio::<4,_>::new(    p.PIO0,Pio0Irqs,    p.PIN_13,    p.PIN_7,    p.PIN_6,    p.PIN_12,(52,0)// clock divider);

About

DShot implementation for the RP2040 using a single PIO block, for up to 4 ESCs

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp