From 461824d4641cf54eaf404175b8258ef676a79e64 Mon Sep 17 00:00:00 2001 From: iso9660 Date: Mon, 9 Oct 2023 19:52:32 +0200 Subject: [PATCH 1/6] This is a proof of concept to implement an algorithm to detect jammings and cut power ASAP Optimized: --- src/Bluejay.asm | 4 +++- src/Modules/Isrs.asm | 1 + src/Modules/Timing.asm | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/Bluejay.asm b/src/Bluejay.asm index 4916179..8064d00 100644 --- a/src/Bluejay.asm +++ b/src/Bluejay.asm @@ -203,6 +203,7 @@ Flags0: DS 1 ; State flags. Reset upon motor_start Flag_Demag_Notify BIT Flags0.3 ; Set when motor demag has been detected but still not notified Flag_Desync_Notify BIT Flags0.4 ; Set when motor desync has been detected but still not notified Flag_Stall_Notify BIT Flags0.5 ; Set when motor stall detected but still not notified + Flag_Active_Jamming_Protection BIT Flags0.6 ; When 1 then jamming protection is active Flags1: DS 1 ; State flags. Reset upon motor_start Flag_Timer3_Pending BIT Flags1.0 ; Timer3 pending flag @@ -239,6 +240,7 @@ DSEG AT 30h Rcp_Outside_Range_Cnt: DS 1 ; RC pulse outside range counter (incrementing) Rcp_Timeout_Cntd: DS 1 ; RC pulse timeout counter (decrementing) Rcp_Stop_Cnt: DS 1 ; Counter for RC pulses below stop value +Rcp_Throttle: DS 1 ; Throttle in 8bit Beacon_Delay_Cnt: DS 1 ; Counter to trigger beacon during wait for start Startup_Cnt: DS 1 ; Startup phase commutations counter (incrementing) @@ -924,7 +926,7 @@ run6: sjmp exit_run_mode startup_phase_done: - ; Clear startup phase flag & remove pwm limits + ; Clear startup phase flag clr Flag_Startup_Phase initial_run_phase: diff --git a/src/Modules/Isrs.asm b/src/Modules/Isrs.asm index e1ad05a..75ee030 100644 --- a/src/Modules/Isrs.asm +++ b/src/Modules/Isrs.asm @@ -325,6 +325,7 @@ t1_int_startup_boosted: swap A rl A mov Temp2, A + mov Rcp_Throttle, A jnz t1_int_rcp_not_zero diff --git a/src/Modules/Timing.asm b/src/Modules/Timing.asm index 19eba76..dfcdf41 100644 --- a/src/Modules/Timing.asm +++ b/src/Modules/Timing.asm @@ -761,6 +761,47 @@ setup_comm_wait: orl EIE1, #80h ; Enable Timer3 interrupts setb IE_EA ; Enable interrupts again +;**** **** **** **** **** **** **** **** **** **** **** **** **** +; +; Check jamming +; +; Checks speed in case a jamming has happened +; +;**** **** **** **** **** **** **** **** **** **** **** **** **** +check_jamming: + ; Jamming detection: throttle has to be > 25% + ; Check Throttle + mov A, Rcp_Throttle + add A, #(255 - 64) + jnc check_jamming_clear + + ; Avoid check if jamming protection is not engaged + jnb Flag_Active_Jamming_Protection, check_jamming_engage + + ; If below speed threshold (period is bigger) do full resync + mov A, Comm_Period4x_H + add A, #(255 - 10) ; Period 10 is ~28000erpm (about 2000rpm at 14 poles) + jc eval_comp_full_resync + + jmp check_jamming_done + +check_jamming_engage: + ; If below speed threshold (period is bigger) do not enable + mov A, Comm_Period4x_H + add A, #(255 - 9) ; Period 9 is ~28000erpm (about 2000rpm at 14 poles) + jc check_jamming_done + + ; Speed is enough to enable jamming protection + setb Flag_Active_Jamming_Protection + jmp check_jamming_done + +check_jamming_clear: + ; Throttle < 25 + clr Flag_Active_Jamming_Protection + +check_jamming_done: + + ;**** **** **** **** **** **** **** **** **** **** **** **** **** ; ; Evaluate comparator integrity @@ -776,6 +817,7 @@ evaluate_comparator_integrity: jb Flag_Dir_Change_Brake, eval_comp_exit ; Do not exit run mode if braking jb Flag_Demag_Detected, eval_comp_exit ; Do not exit run mode if it is a demag situation +eval_comp_full_resync: ; Disable all interrupts and cut power ASAP. They will be enabled in exit_run_mode_on_timeout clr IE_EA call switch_power_off From a1aef75c28188352c938062ebe34dd76bc9dbd8d Mon Sep 17 00:00:00 2001 From: iso9660 Date: Wed, 11 Oct 2023 19:33:16 +0200 Subject: [PATCH 2/6] To disable jamming protection as soon as throttle < JAMMING_PROTECTION_THROTTLE_THRESHOLD in t1 int Otherwise enable it if period <= JAMMING_PROTECTION_PERIOD_HI_ENGAGE If enabled force a full resync if period <= JAMMING_PROTECTION_PERIOD_LO_RESYNC JAMMING_PROTECTION_THROTTLE_THRESHOLD EQU 55h ; 33% throttle JAMMING_PROTECTION_PERIOD_LO_RESYNC EQU 8h ; 2857rpm disable esc if protection is enabled JAMMING_PROTECTION_PERIOD_HI_ENGAGE EQU 7h ; 3500rpm engage jamming protection --- src/Bluejay.asm | 16 +++++++++++++++ src/Modules/Isrs.asm | 11 ++++++++++- src/Modules/Timing.asm | 44 ++++++++++++++++++++++-------------------- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/Bluejay.asm b/src/Bluejay.asm index 8064d00..f3ffe8e 100644 --- a/src/Bluejay.asm +++ b/src/Bluejay.asm @@ -132,6 +132,22 @@ ENDIF ; Select the pwm frequency (or unselect for use with external batch compile file) ;PWM_FREQ EQU 0 ; 0=24, 1=48, 2=96 kHz +; Throttle threshold for jamming protection [0 - 255] +JAMMING_PROTECTION_THROTTLE_THRESHOLD EQU 55h ; 33% throttle + +; Period 40h is ~5000erpm (about 257rpm at 14 poles) +; Period 20h is ~10000erpm (about 714rpm at 14 poles) +; Period 10h is ~20000erpm (about 1428rpm at 14 poles) +; Period 8h is ~40000erpm (about 2857rpm at 14 poles) +; Period 4h is ~80000erpm (about 5717rpm at 14 poles) +; Period 2h is ~160000erpm (about 11428rpm at 14 poles) +; Period 1h is ~320000erpm (about 22857rpm at 14 poles) +; Period over which ESC will resync under jamming suspection +JAMMING_PROTECTION_PERIOD_LO_RESYNC EQU 8h ; 2857rpm disable esc if protection is enabled +; Period over which ESC will enable jamming protection +JAMMING_PROTECTION_PERIOD_HI_ENGAGE EQU 7h ; 3500rpm engage jamming protection + + PWM_CENTERED EQU DEADTIME > 0 ; Use center aligned pwm on ESCs with dead time IF MCU_TYPE == MCU_BB1 diff --git a/src/Modules/Isrs.asm b/src/Modules/Isrs.asm index 75ee030..03cca08 100644 --- a/src/Modules/Isrs.asm +++ b/src/Modules/Isrs.asm @@ -325,6 +325,8 @@ t1_int_startup_boosted: swap A rl A mov Temp2, A + + ; Store throttle mov Rcp_Throttle, A jnz t1_int_rcp_not_zero @@ -340,6 +342,13 @@ t1_int_rcp_not_zero: clr Flag_Rcp_Stop ; Pulse ready t1_int_zero_rcp_checked: + ; Flag_Active_Jamming_Protection = Flag_Active_Jamming_Protection && (throttle > JAMMING_PROTECTION_THROTTLE_THRESHOLD) + mov A, Temp2 + add A, #(255 - JAMMING_PROTECTION_THROTTLE_THRESHOLD) + anl C, Flag_Active_Jamming_Protection + mov Flag_Active_Jamming_Protection, C + +t1_int_dec_outside_range_counter: ; Decrement outside range counter mov A, Rcp_Outside_Range_Cnt jz t1_int_zero_rcp_checked_set_limit @@ -409,7 +418,7 @@ ELSEIF PWM_BITS_H == PWM_9_BIT anl A, #1 mov Temp3, A ELSEIF PWM_BITS_H == PWM_8_BIT - mov A, Temp2 ; Temp2 already 8-bit + mov A, Temp2 ; Rcp_Throttle already 8-bit cpl A mov Temp2, A mov Temp3, #0 diff --git a/src/Modules/Timing.asm b/src/Modules/Timing.asm index dfcdf41..390e206 100644 --- a/src/Modules/Timing.asm +++ b/src/Modules/Timing.asm @@ -769,35 +769,37 @@ setup_comm_wait: ; ;**** **** **** **** **** **** **** **** **** **** **** **** **** check_jamming: - ; Jamming detection: throttle has to be > 25% - ; Check Throttle - mov A, Rcp_Throttle - add A, #(255 - 64) - jnc check_jamming_clear - ; Avoid check if jamming protection is not engaged jnb Flag_Active_Jamming_Protection, check_jamming_engage - ; If below speed threshold (period is bigger) do full resync + ; If speed above resync threshold (period is lower) do nothing mov A, Comm_Period4x_H - add A, #(255 - 10) ; Period 10 is ~28000erpm (about 2000rpm at 14 poles) - jc eval_comp_full_resync + add A, #(255 - JAMMING_PROTECTION_PERIOD_LO_RESYNC) + jnc check_jamming_done - jmp check_jamming_done +check_jamming_full_resync: + ; Disable all interrupts and cut power ASAP. They will be enabled in exit_run_mode_on_timeout + clr IE_EA + call switch_power_off -check_jamming_engage: - ; If below speed threshold (period is bigger) do not enable - mov A, Comm_Period4x_H - add A, #(255 - 9) ; Period 9 is ~28000erpm (about 2000rpm at 14 poles) - jc check_jamming_done + ; Routine exit without "ret" command + dec SP + dec SP + + ; Go to exit run mode if timeout has elapsed + ljmp exit_run_mode_on_timeout - ; Speed is enough to enable jamming protection - setb Flag_Active_Jamming_Protection - jmp check_jamming_done +check_jamming_engage: + ; If throttle <= JAMMING_PROTECTION_THROTTLE_THRESHOLD do not engage jamming protection + mov A, Rcp_Throttle + add A, #(255 - JAMMING_PROTECTION_THROTTLE_THRESHOLD) + jnc check_jamming_done -check_jamming_clear: - ; Throttle < 25 - clr Flag_Active_Jamming_Protection + ; Flag_Active_Jamming_Protection = (throttle >= JAMMING_PROTECTION_PERIOD_HI_ENGAGE) + mov A, Comm_Period4x_H + add A, #(255 - JAMMING_PROTECTION_PERIOD_HI_ENGAGE) + cpl C + mov Flag_Active_Jamming_Protection, C check_jamming_done: From 5986291c2b12f5204a79ed2c132542437d2927c6 Mon Sep 17 00:00:00 2001 From: damosvil Date: Thu, 5 Oct 2023 17:57:49 +0200 Subject: [PATCH 3/6] Flag_Ext_Tele can only be cleared in exit_run_mode when motors are not being reversed (turtle mode) Restored default DEFAULT_PGM_SAFETY_ARM setting --- src/Bluejay.asm | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Bluejay.asm b/src/Bluejay.asm index f3ffe8e..d10b928 100644 --- a/src/Bluejay.asm +++ b/src/Bluejay.asm @@ -1064,7 +1064,6 @@ exit_run_mode: call switch_power_off mov Flags0, #0 ; Clear run time flags (in case they are used in interrupts) mov Flags1, #0 - clr Flag_Ext_Tele ; Clear extended DSHOT telemetry flag IF MCU_TYPE == MCU_BB2 or MCU_TYPE == MCU_BB51 Set_MCU_Clk_24MHz From 273799393910f10a9074334e7fd11ddf78405971 Mon Sep 17 00:00:00 2001 From: iso9660 Date: Fri, 13 Oct 2023 10:31:37 +0200 Subject: [PATCH 4/6] Changed subrevision and tag to name it to 0.20.1 IR1 (internal release 1) --- src/Bluejay.asm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bluejay.asm b/src/Bluejay.asm index d10b928..aa482ad 100644 --- a/src/Bluejay.asm +++ b/src/Bluejay.asm @@ -373,7 +373,7 @@ Temp_Storage: DS 48 ; Temporary storage (internal memory) ;**** **** **** **** **** **** **** **** **** **** **** **** **** CSEG AT CSEG_EEPROM EEPROM_FW_MAIN_REVISION EQU 0 ; Main revision of the firmware -EEPROM_FW_SUB_REVISION EQU 21 ; Sub revision of the firmware +EEPROM_FW_SUB_REVISION EQU 20 ; Sub revision of the firmware EEPROM_LAYOUT_REVISION EQU 207 ; Revision of the EEPROM layout EEPROM_B2_PARAMETERS_COUNT EQU 28 ; Number of parameters @@ -424,7 +424,7 @@ Eep_Pgm_Safety_Arm: DB DEFAULT_PGM_SAFETY_ARM ; Various flag settings: bit 0 is Eep_Dummy: DB 0FFh ; EEPROM address for safety reason CSEG AT CSEG_NAME -Eep_Name: DB "Bluejay (.1 RC2)" ; Name tag (16 Bytes) +Eep_Name: DB "Bluejay (.1 IR1)" ; Name tag (16 Bytes) CSEG AT CSEG_MELODY Eep_Pgm_Beep_Melody: DB 2,58,4,32,52,66,13,0,69,45,13,0,52,66,13,0,78,39,211,0,69,45,208,25,52,25,0 From 35e2b6e08702d1d0d3d9cc9f9a36106056e683c6 Mon Sep 17 00:00:00 2001 From: iso9660 Date: Sun, 15 Oct 2023 11:38:49 +0200 Subject: [PATCH 5/6] Updated jamming protection to be enabled when: - Throttle > 33% - RPM > 4000 - 24 consecutive eturns --- src/Bluejay.asm | 9 ++++++--- src/Modules/Isrs.asm | 10 ++++------ src/Modules/Timing.asm | 37 +++++++++++++++++++++++++------------ 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/Bluejay.asm b/src/Bluejay.asm index aa482ad..0e73f6c 100644 --- a/src/Bluejay.asm +++ b/src/Bluejay.asm @@ -145,8 +145,9 @@ JAMMING_PROTECTION_THROTTLE_THRESHOLD EQU 55h ; 33% throttle ; Period over which ESC will resync under jamming suspection JAMMING_PROTECTION_PERIOD_LO_RESYNC EQU 8h ; 2857rpm disable esc if protection is enabled ; Period over which ESC will enable jamming protection -JAMMING_PROTECTION_PERIOD_HI_ENGAGE EQU 7h ; 3500rpm engage jamming protection - +JAMMING_PROTECTION_PERIOD_HI_ENGAGE EQU 6h ; 4000rpm engage jamming protection +; Number of turns conditions are valid to enable jamming protection to avoid chaotic events +JAMMING_PROTECTION_ETURN_CNT_ENGAGE EQU 24 PWM_CENTERED EQU DEADTIME > 0 ; Use center aligned pwm on ESCs with dead time @@ -219,7 +220,7 @@ Flags0: DS 1 ; State flags. Reset upon motor_start Flag_Demag_Notify BIT Flags0.3 ; Set when motor demag has been detected but still not notified Flag_Desync_Notify BIT Flags0.4 ; Set when motor desync has been detected but still not notified Flag_Stall_Notify BIT Flags0.5 ; Set when motor stall detected but still not notified - Flag_Active_Jamming_Protection BIT Flags0.6 ; When 1 then jamming protection is active + Flag_Jamming_Protection_Active BIT Flags0.6 ; Set when jamming protection is active Flags1: DS 1 ; State flags. Reset upon motor_start Flag_Timer3_Pending BIT Flags1.0 ; Timer3 pending flag @@ -313,6 +314,8 @@ DShot_GCR_Start_Delay: DS 1 Ext_Telemetry_L: DS 1 ; Extended telemetry data to be sent Ext_Telemetry_H: DS 1 Scheduler_Counter: DS 1 ; Scheduler Heartbeat +Jamm_Prot_ETurn_Cnt: DS 1 ; Jamming protection electronic turn counter + ;**** **** **** **** **** **** **** **** **** **** **** **** **** ; Indirect addressing data segments ;**** **** **** **** **** **** **** **** **** **** **** **** **** diff --git a/src/Modules/Isrs.asm b/src/Modules/Isrs.asm index 03cca08..f304211 100644 --- a/src/Modules/Isrs.asm +++ b/src/Modules/Isrs.asm @@ -326,9 +326,6 @@ t1_int_startup_boosted: rl A mov Temp2, A - ; Store throttle - mov Rcp_Throttle, A - jnz t1_int_rcp_not_zero mov A, Temp4 ; Only set Rcp_Stop if all all 11 bits are zero @@ -342,11 +339,12 @@ t1_int_rcp_not_zero: clr Flag_Rcp_Stop ; Pulse ready t1_int_zero_rcp_checked: - ; Flag_Active_Jamming_Protection = Flag_Active_Jamming_Protection && (throttle > JAMMING_PROTECTION_THROTTLE_THRESHOLD) + ; Flag_Jamming_Protection_Active = Flag_Jamming_Protection_Active && (throttle > JAMMING_PROTECTION_THROTTLE_THRESHOLD) mov A, Temp2 + mov Rcp_Throttle, A ; Store throttle to be used in timing module add A, #(255 - JAMMING_PROTECTION_THROTTLE_THRESHOLD) - anl C, Flag_Active_Jamming_Protection - mov Flag_Active_Jamming_Protection, C + anl C, Flag_Jamming_Protection_Active + mov Flag_Jamming_Protection_Active, C t1_int_dec_outside_range_counter: ; Decrement outside range counter diff --git a/src/Modules/Timing.asm b/src/Modules/Timing.asm index 390e206..c42925a 100644 --- a/src/Modules/Timing.asm +++ b/src/Modules/Timing.asm @@ -763,21 +763,21 @@ setup_comm_wait: ;**** **** **** **** **** **** **** **** **** **** **** **** **** ; -; Check jamming +; Jamming protection ; ; Checks speed in case a jamming has happened ; ;**** **** **** **** **** **** **** **** **** **** **** **** **** -check_jamming: +jamming_protection: ; Avoid check if jamming protection is not engaged - jnb Flag_Active_Jamming_Protection, check_jamming_engage + jnb Flag_Jamming_Protection_Active, jamming_protection_engage ; If speed above resync threshold (period is lower) do nothing mov A, Comm_Period4x_H add A, #(255 - JAMMING_PROTECTION_PERIOD_LO_RESYNC) - jnc check_jamming_done + jnc jamming_protection_done -check_jamming_full_resync: +jamming_protection_full_resync: ; Disable all interrupts and cut power ASAP. They will be enabled in exit_run_mode_on_timeout clr IE_EA call switch_power_off @@ -789,19 +789,32 @@ check_jamming_full_resync: ; Go to exit run mode if timeout has elapsed ljmp exit_run_mode_on_timeout -check_jamming_engage: - ; If throttle <= JAMMING_PROTECTION_THROTTLE_THRESHOLD do not engage jamming protection +jamming_protection_engage: + ; If throttle <= JAMMING_PROTECTION_THROTTLE_THRESHOLD then clear jamming protection mov A, Rcp_Throttle add A, #(255 - JAMMING_PROTECTION_THROTTLE_THRESHOLD) - jnc check_jamming_done + jnc jamming_protection_clear - ; Flag_Active_Jamming_Protection = (throttle >= JAMMING_PROTECTION_PERIOD_HI_ENGAGE) + ; If period of eturn is over threshold then clear jamming protection mov A, Comm_Period4x_H add A, #(255 - JAMMING_PROTECTION_PERIOD_HI_ENGAGE) - cpl C - mov Flag_Active_Jamming_Protection, C + jc jamming_protection_clear -check_jamming_done: + ; Flag_Jamming_Protection_Active = (Jamm_Prot_ETurn_Cnt > JAMMING_PROTECTION_ETURN_CNT_ENGAGE) + inc Jamm_Prot_ETurn_Cnt + mov A, Jamm_Prot_ETurn_Cnt + add A, #(255 - JAMMING_PROTECTION_ETURN_CNT_ENGAGE) + mov Flag_Jamming_Protection_Active, C + + jmp jamming_protection_done + + +jamming_protection_clear: + ; Disable jamming protection + clr Flag_Jamming_Protection_Active + mov Jamm_Prot_ETurn_Cnt, #0 + +jamming_protection_done: ;**** **** **** **** **** **** **** **** **** **** **** **** **** From e168e2e8d4e12e95d0aab756815e50755563fc0b Mon Sep 17 00:00:00 2001 From: iso9660 Date: Mon, 16 Oct 2023 18:28:02 +0200 Subject: [PATCH 6/6] Subversion bumped to XR2 --- src/Bluejay.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bluejay.asm b/src/Bluejay.asm index 0e73f6c..e502ae9 100644 --- a/src/Bluejay.asm +++ b/src/Bluejay.asm @@ -427,7 +427,7 @@ Eep_Pgm_Safety_Arm: DB DEFAULT_PGM_SAFETY_ARM ; Various flag settings: bit 0 is Eep_Dummy: DB 0FFh ; EEPROM address for safety reason CSEG AT CSEG_NAME -Eep_Name: DB "Bluejay (.1 IR1)" ; Name tag (16 Bytes) +Eep_Name: DB "Bluejay (.1 XR2)" ; Name tag (16 Bytes) CSEG AT CSEG_MELODY Eep_Pgm_Beep_Melody: DB 2,58,4,32,52,66,13,0,69,45,13,0,52,66,13,0,78,39,211,0,69,45,208,25,52,25,0