diff --git a/src/Bluejay.asm b/src/Bluejay.asm index f606bc7..29cfa79 100644 --- a/src/Bluejay.asm +++ b/src/Bluejay.asm @@ -539,9 +539,10 @@ setup_dshot: ; Route RCP according to detected DShot signal (normal or inverted) mov IT01CF, #(80h + (RTX_PIN SHL 4) + RTX_PIN) ; Route RCP input to Int0/1,with Int1 inverted - jnb Flag_Rcp_DShot_Inverted, ($+6) + jnb Flag_Rcp_DShot_Inverted, setup_dshot_clear_flags mov IT01CF, #(08h + (RTX_PIN SHL 4) + RTX_PIN) ; Route RCP input to Int0/1,with Int0 inverted +setup_dshot_clear_flags: clr Flag_Demag_Notify ; Clear motor events clr Flag_Desync_Notify clr Flag_Stall_Notify @@ -1043,9 +1044,10 @@ exit_run_mode_stall_done: ; Extended telemetry flag is important because it is involved in ; EDT safety feature. We don't want to disable EDT arming during ; turtle mode. - jb Flag_User_Reverse_Requested, ($+5) + jb Flag_User_Reverse_Requested, exit_run_mode_stall_done_beep clr Flag_Ext_Tele +exit_run_mode_stall_done_beep: ; Stalled too many times clr IE_EA call beep_motor_stalled @@ -1060,9 +1062,10 @@ exit_run_mode_no_stall: ; Extended telemetry flag is important because it is involved in ; EDT safety feature. We don't want to disable EDT arming during ; turtle mode. - jb Flag_User_Reverse_Requested, ($+5) + jb Flag_User_Reverse_Requested, exit_run_mode_no_stall_beep clr Flag_Ext_Tele +exit_run_mode_no_stall_beep: ; Clear stall counter mov Startup_Stall_Cnt, #0 diff --git a/src/Modules/DShot.asm b/src/Modules/DShot.asm index fd48b85..2b116bf 100644 --- a/src/Modules/DShot.asm +++ b/src/Modules/DShot.asm @@ -39,10 +39,14 @@ detect_rcp_level: mov C, RTX_BIT detect_rcp_level_read: - jc ($+5) + jc detect_rcp_level_read_check_high_to_low jb RTX_BIT, detect_rcp_level ; Level changed from low to high - start over - jnc ($+5) + +detect_rcp_level_read_check_high_to_low: + jnc detect_rcp_level_check_loop jnb RTX_BIT, detect_rcp_level ; Level changed from high to low - start over + +detect_rcp_level_check_loop: djnz ACC, detect_rcp_level_read mov Flag_Rcp_DShot_Inverted, C diff --git a/src/Modules/Eeprom.asm b/src/Modules/Eeprom.asm index fc85245..36a2671 100644 --- a/src/Modules/Eeprom.asm +++ b/src/Modules/Eeprom.asm @@ -169,10 +169,10 @@ write_eeprom_byte_from_acc: clr C mov A, DPH ; Check that address is not in bootloader area subb A, #BOOTLOADER_OFFSET - jc ($+3) - + jc write_eeprom_byte_write ret +write_eeprom_byte_write: mov A, Temp8 mov FLKEY, Flash_Key_1 ; First key code mov FLKEY, Flash_Key_2 ; Second key code diff --git a/src/Modules/Isrs.asm b/src/Modules/Isrs.asm index de8b787..cd43664 100644 --- a/src/Modules/Isrs.asm +++ b/src/Modules/Isrs.asm @@ -150,9 +150,10 @@ t1_int_decode_lsb: t1_int_outside_range: inc Rcp_Outside_Range_Cnt mov A, Rcp_Outside_Range_Cnt - jnz ($+4) + jnz t1_int_outside_range_check_limit dec Rcp_Outside_Range_Cnt +t1_int_outside_range_check_limit: clr C mov A, Rcp_Outside_Range_Cnt subb A, #50 ; Allow a given number of outside pulses @@ -180,8 +181,10 @@ t1_int_decode_checksum: xrl A, Temp4 xrl A, Temp5 xrl A, Temp3 - jnb Flag_Rcp_DShot_Inverted, ($+4) + jnb Flag_Rcp_DShot_Inverted, t1_int_decode_checksum_xor_check cpl A ; Invert checksum if using inverted DShot + +t1_int_decode_checksum_xor_check: anl A, #0Fh jnz t1_int_outside_range ; XOR check @@ -236,8 +239,10 @@ t1_int_normal_range: mov Temp5, A t1_int_bidir_set: - jnb Flag_Pgm_Dir_Rev, ($+4) ; Check programmed direction + jnb Flag_Pgm_Dir_Rev, t1_int_bidir_set_dir ; Check programmed direction cpl C ; Reverse direction + +t1_int_bidir_set_dir: mov Flag_Rcp_Dir_Rev, C ; Set rcp direction clr C ; Multiply throttle value by 2 @@ -255,7 +260,7 @@ t1_int_not_bidir: mov Temp3, A ; Align to 11 bits - ;clr C ; Note: Cleared by div + ;clr C ; Note: Cleared by div rrca Temp5 mov A, Temp4 rrc A @@ -267,10 +272,11 @@ t1_int_not_bidir: mov A, Temp5 addc A, #0 mov Temp5, A - jnb ACC.3, ($+7) ; Limit to 11-bit maximum + jnb ACC.3, t1_int_not_bidir_do_not_boost ; Limit to 11-bit maximum mov Temp4, #0FFh mov Temp5, #07h +t1_int_not_bidir_do_not_boost: ; Do not boost when changing direction in bidirectional mode jb Flag_Motor_Started, t1_int_startup_boosted @@ -300,7 +306,7 @@ t1_int_stall_boost: mov A, Temp5 addc A, #0 mov Temp5, A - jnb ACC.3, ($+7) ; Limit to 11-bit maximum + jnb ACC.3, t1_int_startup_boosted ; Limit to 11-bit maximum mov Temp4, #0FFh mov Temp5, #07h @@ -328,17 +334,19 @@ t1_int_rcp_not_zero: t1_int_zero_rcp_checked: ; Decrement outside range counter mov A, Rcp_Outside_Range_Cnt - jz ($+4) + jz t1_int_zero_rcp_checked_set_limit dec Rcp_Outside_Range_Cnt +t1_int_zero_rcp_checked_set_limit: ; Set pwm limit clr C mov A, Pwm_Limit ; Limit to the smallest mov Temp6, A ; Store limit in Temp6 subb A, Pwm_Limit_By_Rpm - jc ($+4) + jc t1_int_zero_rcp_checked_check_limit mov Temp6, Pwm_Limit_By_Rpm +t1_int_zero_rcp_checked_check_limit: ; Check against limit clr C mov A, Temp6 @@ -552,7 +560,7 @@ t2_int_flag_rcp_stop_check: ; Increment Rcp_Stop_Cnt clipping it to 255 mov A, Rcp_Stop_Cnt inc A - jz ($+4) + jz t2_int_exit inc Rcp_Stop_Cnt ;**** **** **** **** **** **** **** **** **** **** **** **** **** diff --git a/src/Modules/Macros.asm b/src/Modules/Macros.asm index 22d3d50..8a1a602 100644 --- a/src/Modules/Macros.asm +++ b/src/Modules/Macros.asm @@ -57,10 +57,12 @@ ENDM ; DShot GCR encoding, adjust time by adding to previous item GCR_Add_Time MACRO reg + LOCAL gcr_add_time_set mov B, @reg mov A, DShot_GCR_Pulse_Time_2 - cjne A, B, ($+5) + cjne A, B, gcr_add_time_set mov A, DShot_GCR_Pulse_Time_3 +gcr_add_time_set: mov @reg, A ENDM diff --git a/src/Modules/Power.asm b/src/Modules/Power.asm index 3dbfed5..59808aa 100644 --- a/src/Modules/Power.asm +++ b/src/Modules/Power.asm @@ -62,18 +62,21 @@ set_pwm_limit: jz set_pwm_limit_low_rpm_exit ; Avoid divide by zero mov A, #255 ; Divide 255 by Comm_Period4x_H - jnb Flag_Initial_Run_Phase, ($+5) ; More protection for initial run phase + jnb Flag_Initial_Run_Phase, set_pwm_limit_calculate ; More protection for initial run phase mov A, #127 + +set_pwm_limit_calculate: mov B, Comm_Period4x_H div AB mov B, Low_Rpm_Pwr_Slope ; Multiply by slope mul AB mov Temp1, A ; Set new limit xch A, B - jz ($+4) ; Limit to max + jz set_pwm_limit_check_limit_to_min ; Limit to max mov Temp1, #0FFh +set_pwm_limit_check_limit_to_min: clr C mov A, Temp1 ; Limit to min subb A, Pwm_Limit_Beg @@ -113,7 +116,8 @@ set_pwm_limit_high_rpm_inc_limit: inc A set_pwm_limit_high_rpm_store: - jz ($+4) + jz set_pwm_limit_high_rpm_end mov Pwm_Limit_By_Rpm, A +set_pwm_limit_high_rpm_end: ret diff --git a/src/Modules/Settings.asm b/src/Modules/Settings.asm index 5e5fd11..fd585ef 100644 --- a/src/Modules/Settings.asm +++ b/src/Modules/Settings.asm @@ -101,16 +101,18 @@ decode_settings: mov Temp1, #Pgm_Startup_Power_Max mov A, #80 ; Limit to at most 80 subb A, @Temp1 - jnc ($+4) + jnc decode_settings_check_low_rpm mov @Temp1, #80 +decode_settings_check_low_rpm: ; Check low rpm power slope mov Temp1, #Pgm_Rpm_Power_Slope mov A, #13 ; Limit to at most 13 subb A, @Temp1 - jnc ($+4) + jnc decode_settings_set_low_rpm mov @Temp1, #13 +decode_settings_set_low_rpm: mov Low_Rpm_Pwr_Slope, @Temp1 ; Decode demag compensation diff --git a/src/Modules/Timing.asm b/src/Modules/Timing.asm index fcec7eb..86769a5 100644 --- a/src/Modules/Timing.asm +++ b/src/Modules/Timing.asm @@ -57,8 +57,10 @@ calc_next_comm_period: mov Temp1, TMR2L ; Load Timer2 value mov Temp2, TMR2H mov Temp3, Timer2_X - jnb TMR2CN0_TF2H, ($+4) ; Check if interrupt is pending + jnb TMR2CN0_TF2H,calc_next_comm_period_enable_timer2 ; Check if interrupt is pending inc Temp3 ; If it is pending,then timer has already wrapped + +calc_next_comm_period_enable_timer2: setb TMR2CN0_TR2 ; Timer2 enabled setb IE_EA @@ -220,7 +222,7 @@ calc_next_comm_done: clr C mov A, Comm_Period4x_H subb A, #2 ; Is Comm_Period4x_H below 2? (above ~160k erpm) - jnc ($+4) + jnc calc_next_comm_15deg setb Flag_High_Rpm ; Yes - Set high rpm flag calc_next_comm_15deg: @@ -290,9 +292,10 @@ calc_next_comm_period_fast: clr C subb A, #2 ; Is Comm_Period4x_H 2 or more? (below ~160k erpm) - jc ($+4) + jc calc_next_comm_period_fast_div_comm_perio4x_by_16 clr Flag_High_Rpm ; Yes - Clear high rpm bit +calc_next_comm_period_fast_div_comm_perio4x_by_16: mov A, Temp4 ; Divide Comm_Period4x by 16 and store in Temp4/3 swap A mov Temp7, A @@ -373,14 +376,15 @@ adjust_comm_timing: inc Temp8 ; Increase timing (if metric 130 or above) subb A, #30 - jc ($+3) + jc adjust_comm_timing_limit_to_max inc Temp8 ; Increase timing again (if metric 160 or above) +adjust_comm_timing_limit_to_max: clr C mov A, Temp8 ; Limit timing to max subb A, #6 - jc ($+4) + jc load_comm_timing_done mov Temp8, #5 ; Set timing to max (if timing 6 or above) @@ -603,9 +607,10 @@ comp_start: mov Temp4, #(1 SHL IS_MCU_48MHZ) ; Max number of readings required jb Flag_High_Rpm, comp_check_timeout ; Branch if high rpm - jnb Flag_Initial_Run_Phase, ($+5) + jnb Flag_Initial_Run_Phase, comp_start_check_startup_phase clr Flag_Demag_Detected ; Clear demag detected flag if start phases +comp_start_check_startup_phase: jnb Flag_Startup_Phase, comp_not_startup mov Temp3, #(27 SHL IS_MCU_48MHZ) ; Set many samples during startup,approximately one pwm period mov Temp4, #(27 SHL IS_MCU_48MHZ) @@ -620,12 +625,14 @@ IF MCU_TYPE == MCU_BB1 clr C rrc A ENDIF - jnz ($+3) + jnz comp_not_startup_check_ok_readings inc A ; Minimum 1 + +comp_not_startup_check_ok_readings: mov Temp3, A clr C subb A, #(20 SHL IS_MCU_48MHZ) - jc ($+4) + jc comp_check_timeout mov Temp3, #(20 SHL IS_MCU_48MHZ) ; Maximum 20 comp_check_timeout: @@ -679,9 +686,10 @@ comp_read_wrong_startup: clr C mov A, Temp3 subb A, Temp4 ; If above initial requirement - do not increment further - jc ($+3) + jc comp_read_wrong_startup_jump ; TODO: Skip this jump to optimize dec Temp3 +comp_read_wrong_startup_jump: sjmp comp_check_timeout ; Continue to look for good ones comp_read_wrong_extend_timeout: @@ -809,9 +817,10 @@ wait_for_comm_demag_event_added: mov Demag_Detected_Metric, A clr C subb A, #120 ; Limit to minimum 120 - jnc ($+5) + jnc wait_for_comm_update_demag_metric_max mov Demag_Detected_Metric, #120 +wait_for_comm_update_demag_metric_max: ; Update demag metric max clr C mov A, Demag_Detected_Metric