From 788338e8d957ffe5e41adbddc68c9bf3d4723856 Mon Sep 17 00:00:00 2001 From: Mathias Rasmussen Date: Wed, 9 Jun 2021 01:43:34 +0200 Subject: [PATCH] perf: Remove PCA interrupt Update PWM auto-reload registers directly --- Bluejay.asm | 93 +++++++++++------------------------------------------ Common.inc | 43 ------------------------- 2 files changed, 19 insertions(+), 117 deletions(-) diff --git a/Bluejay.asm b/Bluejay.asm index 9754be4..5b2a477 100644 --- a/Bluejay.asm +++ b/Bluejay.asm @@ -167,7 +167,6 @@ Flag_Motor_Running BIT Flags1.3 Flag_Motor_Started BIT Flags1.4 ; Set when motor is started Flag_Dir_Change_Brake BIT Flags1.5 ; Set when braking before direction change Flag_High_Rpm BIT Flags1.6 ; Set when motor rpm is high (Comm_Period4x_H less than 2) -Flag_Low_Pwm_Power BIT Flags1.7 ; Set when pwm duty cycle is below 50% Flags2: DS 1 ; State flags. NOT reset upon motor_start ; BIT Flags2.0 @@ -584,7 +583,6 @@ t0_int_dshot_tlm_finish: mov TL0, #0 ; Reset timer 0 count setb IE_EX0 ; Enable int0 interrupts setb IE_EX1 ; Enable int1 interrupts - Enable_PCA_Interrupt ; Enable pca interrupts clr Flag_Telemetry_Pending ; Mark that new telemetry packet may be created @@ -970,6 +968,24 @@ IF DEADTIME != 0 mov Damp_Pwm_Reg_H, Temp5 ENDIF +; Set power pwm auto-reload registers +IF PWM_BITS_H != 0 + Set_Power_Pwm_Reg_L Power_Pwm_Reg_L + Set_Power_Pwm_Reg_H Power_Pwm_Reg_H +ELSE + Set_Power_Pwm_Reg_H Power_Pwm_Reg_L +ENDIF + +IF DEADTIME != 0 + ; Set damp pwm auto-reload registers + IF PWM_BITS_H != 0 + Set_Damp_Pwm_Reg_L Damp_Pwm_Reg_L + Set_Damp_Pwm_Reg_H Damp_Pwm_Reg_H + ELSE + Set_Damp_Pwm_Reg_H Damp_Pwm_Reg_L + ENDIF +ENDIF + mov Rcp_Timeout_Cntd, #10 ; Set timeout count ; Prepare DShot telemetry @@ -998,7 +1014,6 @@ t1_int_exit_no_tlm: mov TL0, #0 ; Reset timer 0 setb IE_EX0 ; Enable int0 interrupts setb IE_EX1 ; Enable int1 interrupts - Enable_PCA_Interrupt ; Enable pca interrupts t1_int_exit_no_int: pop B ; Restore preserved registers @@ -1129,76 +1144,6 @@ reti ; ;**** **** **** **** **** **** **** **** **** **** **** **** **** pca_int: - clr IE_EA ; Disable all interrupts - push ACC - -IF DEADTIME != 0 ; HI/LO enable style drivers - mov A, PCA0L ; Read low byte first, to transfer high byte to holding register - mov A, PCA0H - - jnb Flag_Low_Pwm_Power, pca_int_hi_pwm - - ; Power below 50%, update pca in the 0x00-0x0F range - jb ACC.PWM_BITS_H, pca_int_exit ; PWM edge selection bit (continue if up edge) - - sjmp pca_int_set_pwm - -pca_int_hi_pwm: - ; Power above 50%, update pca in the 0x20-0x2F range - jnb ACC.PWM_BITS_H, pca_int_exit ; PWM edge selection bit (continue if down edge) - -pca_int_set_pwm: - IF PWM_BITS_H != 0 - jb ACC.(PWM_BITS_H-1), pca_int_exit - ELSE - mov A, PCA0L - jb ACC.7, pca_int_exit - ENDIF -ENDIF - -; Set power pwm auto-reload registers -IF PWM_BITS_H != 0 - Set_Power_Pwm_Reg_L Power_Pwm_Reg_L - Set_Power_Pwm_Reg_H Power_Pwm_Reg_H -ELSE - Set_Power_Pwm_Reg_H Power_Pwm_Reg_L -ENDIF - -IF DEADTIME != 0 - ; Set damp pwm auto-reload registers - IF PWM_BITS_H != 0 - Set_Damp_Pwm_Reg_L Damp_Pwm_Reg_L - Set_Damp_Pwm_Reg_H Damp_Pwm_Reg_H - ELSE - Set_Damp_Pwm_Reg_H Damp_Pwm_Reg_L - ENDIF -ENDIF - - setb Flag_Low_Pwm_Power -IF PWM_BITS_H != 0 - mov A, Power_Pwm_Reg_H - jb ACC.(PWM_BITS_H - 1), ($+5) -ELSE - mov A, Power_Pwm_Reg_L - jb ACC.7, ($+5) -ENDIF - clr Flag_Low_Pwm_Power - - Disable_COVF_Interrupt -IF DEADTIME == 0 ; EN/PWM style drivers - Disable_CCF_Interrupt -ENDIF - - anl EIE1, #0EFh ; Pwm updated, disable pca interrupts - -pca_int_exit: - Clear_COVF_Interrupt -IF DEADTIME == 0 - Clear_CCF_Interrupt -ENDIF - - pop ACC ; Restore preserved registers - setb IE_EA ; Enable all interrupts reti @@ -3719,7 +3664,7 @@ setup_dshot: ; Setup interrupts for DShot clr Flag_Telemetry_Pending ; Clear DShot telemetry flag mov IE, #2Dh ; Enable timer 1/2 interrupts and INT0/1 interrupts - mov EIE1, #90h ; Enable timer 3 and PCA0 interrupts + mov EIE1, #80h ; Enable timer 3 interrupts mov IP, #03h ; High priority to timer 0 and INT0 interrupts setb IE_EA ; Enable all interrupts diff --git a/Common.inc b/Common.inc index 7e7c4d7..36a690f 100644 --- a/Common.inc +++ b/Common.inc @@ -165,49 +165,6 @@ ELSE ENDIF ENDM -Clear_COVF_Interrupt MACRO - anl PCA0PWM, #0DFh ;; Clear PCA cycle overflow flag -ENDM - -Enable_COVF_Interrupt MACRO - orl PCA0PWM, #40h ;; Enable PCA interrupt on cycle overflow -ENDM - -Disable_COVF_Interrupt MACRO - anl PCA0PWM, #0BFh ;; Disable PCA interrupt on cycle overflow -ENDM - -IF DEADTIME == 0 ; CCF interrupt is only used for DEADTIME == 0 -Clear_CCF_Interrupt MACRO - anl PCA0CN0, #0FEh ;; Clear PCA capture/compare flag -ENDM - -Enable_CCF_Interrupt MACRO - orl PCA0CPM0, #01h ;; Enable PCA interrupt on capture/compare -ENDM - -Disable_CCF_Interrupt MACRO - anl PCA0CPM0, #0FEh ;; Disable PCA interrupt on capture/compare -ENDM -ENDIF - -Enable_PCA_Interrupt MACRO -LOCAL pca_enabled set_pca_int_hi_pwm -IF DEADTIME != 0 - Enable_COVF_Interrupt -ELSE - jnb Flag_Low_Pwm_Power, set_pca_int_hi_pwm - - Enable_COVF_Interrupt - sjmp pca_enabled - -set_pca_int_hi_pwm: - Enable_CCF_Interrupt -pca_enabled: -ENDIF - orl EIE1, #10h ;; Enable pca interrupts -ENDM - Set_MCU_Clk_24MHz MACRO mov CLKSEL, #13h ;; Set clock to 24MHz (Oscillator 1 divided by 2)