BLHeli RPM Measurement Output

21 Apr

I needed an RPM measurement from a helicopter motor. The ESC I use is a YEP7A from HobbyKing. Unfortunately it has no free solder-pads. The pads used for programming are also connected to the FETs, probably to save some space on this ultra-small ESC.

Pads for programming, all shared with FETs.

Pads for programming, all shared with FETs.

Pinout from HobbyKing website

Pinout from HobbyKing website.

 

I choose to remove the LED, since it is not used by the BLHeli firmware anyway. The LED is connected on PORT D, PIN 3 (PD3). Before removing the LED, lets first test if we can show the RPM measurement using a blinking LED. The LED is connected to +5V with a pull-up resistor. That means that the LED is ON when the output on PD3 is LOW and vice versa.

YEP7A LED and Pull-up resistor.

YEP7A LED and Pull-up resistor.

 

This worked, so it was time to remove the LED and replace it by a wire. I also removed the pull-up resistor, because then I could use both pads of the LED to solder the wire. This wire goes to the autopilot which processes the pulses from the ESC. A drop of hot-glue was also added to relief the solder joint.

photo_2016-04-21_22-25-18

LED replaced by a wire.

To enable the RPM output, the code has to be modified slightly. The source-code for the BLHeli firmware can be downloaded at Github. For every ESC, there is an include file (*.inc), in my case YEP_7A.inc.

First, we need to configure the LED pin (PORT D, PIN3) as an output. This part of the code was modified to accomplish this.

;*********************
; PORT D definitions *
;********************* 
;.EQU            = 7    ;i
;.EQU            = 6    ;i
;.EQU            = 5    ;i
;.EQU            = 4    ;i
.EQU    LED_Pin  = 3    ;o
.EQU    Rcp_In   = 2    ;i
;.EQU            = 1    ;i
;.EQU            = 0    ;i

.equ    INIT_PD        = 0x00
.equ    DIR_PD         = (1<<LED_Pin)

All the way at the bottom are the macro’s for the RPM measurements. They are empty by default. It is changed as follows:

.MACRO Set_RPM_Out
  sbi  PORTD, LED_Pin
.ENDMACRO
.MACRO Clear_RPM_Out
  cbi  PORTD, LED_Pin
.ENDMACRO

These macro’s will be called from the main code. The sbi and cbi commands are assembly instructions for “set bit” and “clear bit”.

After these modifications, the code needs to be compiled. This is easiest on Windows, since a batch file is provided that does it for you. Simply run MakeHexfiles.bat. The generated HEX and EEP files appear in the Output folder. This script needs the avr assembler. I got it by installing Atmel Studio. In the MakeHexfiles.bat file, I changed the AtmelPath to:

SET AtmelPath="C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avrassembler"

The generated HEX file can be uploaded with BLHeliSuite. The EEP file needs to be in the same directory.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.