Coder Social home page Coder Social logo

stm32_hal_dshot's Introduction

stm32_hal_dshot

Brief

Dshot is drone ESC digital protocol

You need STM32 MCU, BLHeli_32 ESC, BLDC
STM32 MCU makes Dshot signal using PWM and DMA

KEYWORD - DSHOT BLHeli_32 ESC BLDC STM32 HAL TIMER PWM DMA

dshot

Dev Environment

  • STM32CubeIDE
  • STM32 HAL driver
  • STM32F411
  • BLHeli_32 ESC
  • Drone BLDC

Library Features

  • Change motor throttle
    • Throttle range : 2000 steps (0% - 100%)
  • Choose Dshot 150/300/600
  • Other command : no
  • Telemetry : no

ESC Firmware and Protocol

ESC Firmware

1st 2nd 3rd
ESC Firmware BLHeli BLHeli_S BLHeli_32

ESC Protocol

Analogue signal Digital signal
ESC Protocol PWM
Oneshot125
Oneshot42
Multishot
Dshot150
Dshot300
Dshot600
Proshot1000

Dshot

image

1. Data Frame

  • 11bits : 0 - 47 command, 48 - 2047 throttle
  • 1bit : telemetry request
  • 4bits : checksum

2. Bit 0 / 1

image

bit 0 bit 1
duty cycle 37.425% 74.850%

3. Transmission Time

bits / sec sec / bit sec / frame
Dshot150 150,000 bits/s 6.67us 106.7us
Dshot300 300,000 bits/s 3.33us 53.3us
Dshot600 600,000 bits/s 1.67us 26.7us

4. Signal Example

  • throttle value : 11 / telemetry request : 0 (no) / checksum 4 bits
  • 0 0 0 0 0 0 0 1 0 1 1 / 0 / 0 1 1 1

5. Arming sequence

  • After power on, Send zero throttle for a while until 1 high beep is ended.
  • 7p of BLHeli_32 manual ARM Rev32.x.pdf

STM32CubeMX

  • Project Manager image

  • TIM image image

  • DMA image

Example

dshot.h

  • TIM5, TIM2 is 100MHz
  • MOTOR 1 - PA3
  • MOTOR 2 - PA2
  • MOTOR 3 - PA0
  • MOTOR 4 - PA1
  • Some instance are not pre-defined, so need to change in person...
    • like TIM_DMA_ID_CC4, TIM_DMA_CC4, CCR4...
/* User Configuration */
// Timer Clock
#define TIMER_CLOCK				100000000	// 100MHz

// MOTOR 1 (PA3) - TIM5 Channel 4, DMA1 Stream 3
#define MOTOR_1_TIM             (&htim5)
#define MOTOR_1_TIM_CHANNEL     TIM_CHANNEL_4

// MOTOR 2 (PA2) - TIM2 Channel 3, DMA1 Stream 1
#define MOTOR_2_TIM             (&htim2)
#define MOTOR_2_TIM_CHANNEL     TIM_CHANNEL_3

// MOTOR 3 (PA0) - TIM2 Channel 1, DMA1 Stream 5
#define MOTOR_3_TIM             (&htim2)
#define MOTOR_3_TIM_CHANNEL     TIM_CHANNEL_1

// MOTOR 4 (PA1) - TIM5 Channel 2, DMA1 Stream 4
#define MOTOR_4_TIM             (&htim5)
#define MOTOR_4_TIM_CHANNEL     TIM_CHANNEL_2

main.c

  • only contain dshot things
#include "dshot.h"

// 4 motor value
uint16_t my_motor_value[4] = {0, 0, 0, 0};

int main (void)
{
    // initialize
    dshot_init(DSHOT600);

    while (1)
    {
        // transmit new dshot signals
        dshot_write(my_motor_value);
        HAL_Delay(1);
    }
}

stm32_hal_dshot's People

Contributors

mokhwasomssi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

stm32_hal_dshot's Issues

License?

It would be great if you could add a License file (preferably MIT or Apache 2.0)

Without a license, this code is all-rights-reserved: no one may use your work unless they obtain your permission.

https://choosealicense.com/

Refactoring : need to increase portability

there are user configurations in header file.
but it doesn't connected all function.
that means if there is a change of user configuration as using different pin, we have to revise the inside of some functions in person.

Throttle connection

Hi @mokhwasomssi ,
Can you please explain, where is the code that reads the throttle value? And how to connect RC receiver with STM32 that is being used by you?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.