From 01642d718a83105b1fb22a8b12fdf5a125f5c110 Mon Sep 17 00:00:00 2001 From: Mathias Rasmussen Date: Thu, 29 Oct 2020 01:53:11 +0100 Subject: [PATCH] feat: Add 48kHz pwm option --- Bluejay.asm | 38 +++++++++++++++++++++++++------------- Common.inc | 7 ++++--- Makefile | 15 ++++++++++----- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/Bluejay.asm b/Bluejay.asm index 7518a78..14cf7e3 100644 --- a/Bluejay.asm +++ b/Bluejay.asm @@ -108,6 +108,9 @@ W_ EQU 23 ; RC MC MB X CC MA X X X Ap Bp Cp X X X X Tristate gate driver ; Select the fet deadtime (or unselect for use with external batch compile file) ;FETON_DELAY EQU 15 ; 20.4ns per step +;**** **** **** **** **** +; Select the pwm frequency (or unselect for use with external batch compile file) +;PWM_48KHZ EQU 0 $include (Common.inc) ; Include common source code for EFM8BBx based ESCs @@ -394,18 +397,15 @@ DShot_GCR_Get_Time MACRO mov A, DShot_GCR_Pulse_Time_3 ENDM -IF FETON_DELAY != 0 - IF MCU_48MHZ == 0 - PWM_BITS_H EQU 1 - ELSE - PWM_BITS_H EQU 2 - ENDIF +IF FETON_DELAY == 0 + PWM_CENTERED EQU 0 ELSE - IF MCU_48MHZ == 0 - PWM_BITS_H EQU 2 - ELSE - PWM_BITS_H EQU 3 - ENDIF + PWM_CENTERED EQU 1 +ENDIF + +IF MCU_48MHZ < 2 AND PWM_48KHZ < 2 + ; Number of bits in pwm high byte + PWM_BITS_H EQU (2 + MCU_48MHZ - PWM_CENTERED - PWM_48KHZ) ENDIF ;**** **** **** **** **** @@ -775,13 +775,25 @@ ENDIF mov Temp5, B t1_int_set_pwm_registers: +IF PWM_48KHZ != 0 + ; Scale down pwm resolution + clr C + mov A, Temp5 + rrc A + mov Temp5, A + mov A, Temp4 + rrc A + mov Temp4, A +ENDIF + + IF FETON_DELAY != 0 clr C ENDIF mov A, Temp5 IF FETON_DELAY != 0 - rrc A ; Scale to 10/9 bit pwm + rrc A ; Scale down pwm resolution ENDIF cpl A anl A, #((1 SHL PWM_BITS_H) - 1) @@ -789,7 +801,7 @@ ENDIF mov A, Temp4 IF FETON_DELAY != 0 - rrc A ; Scale to 10/9 bit pwm + rrc A ; Scale down pwm resolution ENDIF cpl A mov Temp2, A diff --git a/Common.inc b/Common.inc index 881c38f..b53070d 100644 --- a/Common.inc +++ b/Common.inc @@ -189,10 +189,11 @@ Initialize_PCA MACRO mov PCA0MD, #08h ; PCA clock is system clock mov PCA0PWM, #(80h + PWM_BITS_H) ; PCA ARSEL set and 8/9/10/11 bits pwm -IF FETON_DELAY == 0 - mov PCA0CENT, #00h ; Edge aligned pwm -ELSE + +IF PWM_CENTERED == 1 mov PCA0CENT, #03h ; Center aligned pwm +ELSE + mov PCA0CENT, #00h ; Edge aligned pwm ENDIF ENDM diff --git a/Makefile b/Makefile index 94c3d6b..a32d7aa 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,13 @@ REVISION ?= v0.2.1 TARGETS = A B C D E F G H I J K L M N O P Q R S T U V W MCUS = H L FETON_DELAYS = 0 5 10 15 20 25 30 40 50 70 90 +PWM_FREQUENCIES = 24 48 # example single target TARGET ?= F MCU ?= H FETON_DELAY ?= 40 +PWM_FREQUENCY ?= 24 WINE_BIN ?= /usr/local/bin/wine @@ -49,13 +51,14 @@ DUMMYVAR := $(foreach exec, $(EXECUTABLES), \ OBJS = define MAKE_OBJ -OBJS += $(1)_$(2)_$(3)_$(REVISION).OBJ -$(OUTPUT_DIR)/$(1)_$(2)_$(3)_$(REVISION).OBJ : $(ASM_SRC) $(ASM_INC) +OBJS += $(1)_$(2)_$(3)_$(4)_$(REVISION).OBJ +$(OUTPUT_DIR)/$(1)_$(2)_$(3)_$(4)_$(REVISION).OBJ : $(ASM_SRC) $(ASM_INC) $(eval _ESC := $(1)) $(eval _ESC_INT := $(shell printf "%d" "'${_ESC}")) $(eval _ESCNO := $(shell echo $$(( $(_ESC_INT) - 65 + 1)))) $(eval _MCU_48MHZ := $(subst L,0,$(subst H,1,$(2)))) $(eval _FETON_DELAY := $(3)) + $(eval _PWM_48KHZ := $(subst 24,0,$(subst 48,1,$(4)))) $(eval _LOG := $(LOG_DIR)/$(1)_$(2)_$(3)_$(REVISION).log) @mkdir -p $(OUTPUT_DIR) @mkdir -p $(LOG_DIR) @@ -64,6 +67,7 @@ $(OUTPUT_DIR)/$(1)_$(2)_$(3)_$(REVISION).OBJ : $(ASM_SRC) $(ASM_INC) "DEFINE(ESCNO=$(_ESCNO)) " \ "DEFINE(MCU_48MHZ=$(_MCU_48MHZ)) "\ "DEFINE(FETON_DELAY=$(_FETON_DELAY)) "\ + "DEFINE(PWM_48KHZ=$(_PWM_48KHZ)) "\ "OBJECT($$@) "\ "$(AX51_FLAGS)" > $(_LOG) 2>&1; test $$$$? -lt 2 || (mv ./Bluejay.LST $(OUTPUT_DIR)/; tail $(_LOG); exit 1) @mv ./Bluejay.LST $(OUTPUT_DIR)/ @@ -76,7 +80,7 @@ EFM8_LOAD_BIN ?= efm8load.py EFM8_LOAD_PORT ?= /dev/ttyUSB0 EFM8_LOAD_BAUD ?= 57600 -SINGLE_TARGET_HEX = $(OUTPUT_DIR_HEX)/$(TARGET)_$(MCU)_$(FETON_DELAY)_$(REVISION).hex +SINGLE_TARGET_HEX = $(OUTPUT_DIR_HEX)/$(TARGET)_$(MCU)_$(FETON_DELAY)_$(PWM_FREQUENCY)_$(REVISION).hex single_target : $(SINGLE_TARGET_HEX) @@ -84,10 +88,11 @@ all : $$(HEX_TARGETS) @echo "\nbuild finished. built $(shell ls -l $(OUTPUT_DIR_HEX) | wc -l) hex targets\n" # create all obj targets using macro expansion -$(foreach _e,$(TARGETS), \ +$(foreach _t,$(TARGETS), \ $(foreach _m, $(MCUS), \ $(foreach _f, $(FETON_DELAYS), \ - $(eval $(call MAKE_OBJ,$(_e),$(_m),$(_f)))))) + $(foreach _p, $(PWM_FREQUENCIES), \ + $(eval $(call MAKE_OBJ,$(_t),$(_m),$(_f),$(_p))))))) $(OUTPUT_DIR)/%.OMF : $(OUTPUT_DIR)/%.OBJ