Skip to content

Commit

Permalink
Merge pull request #173 from bird-sanctuary/refactoring/exit_startup_…
Browse files Browse the repository at this point in the history
…power

Refactoring: exit startup power
  • Loading branch information
stylesuxx authored Oct 5, 2023
2 parents 3647418 + 303f638 commit de87570
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
22 changes: 9 additions & 13 deletions src/Bluejay.asm
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ Wt_Zc_Tout_Start_L: DS 1 ; Timer3 start point for zero cross scan
Wt_Zc_Tout_Start_H: DS 1 ; Timer3 start point for zero cross scan timeout (hi byte)
Wt_Comm_Start_L: DS 1 ; Timer3 start point from zero cross to commutation (lo byte)
Wt_Comm_Start_H: DS 1 ; Timer3 start point from zero cross to commutation (hi byte)
Pwm_Limit: DS 1 ; Maximum allowed pwm (8-bit)
Pwm_Limit_Startup_n_Temp: DS 1 ; Maximum allowed pwm (8-bit) - Used for startup power limit and temperature limit after startup
Pwm_Limit_By_Rpm: DS 1 ; Maximum allowed pwm for low or high rpm (8-bit)
Pwm_Limit_Beg: DS 1 ; Initial pwm limit (8-bit)
Pwm_Braking24_L: DS 1 ; Max Braking @24khz pwm (lo byte)
Expand Down Expand Up @@ -745,7 +745,7 @@ motor_start:
mov Pwm_Limit_By_Rpm, Pwm_Limit_Beg

; Set temperature PWM limit and setpoint to the maximum value
mov Pwm_Limit, Pwm_Limit_Beg
mov Pwm_Limit_Startup_n_Temp, Pwm_Limit_Beg
mov Temp_Pwm_Level_Setpoint, Pwm_Limit_Beg

; Begin startup sequence
Expand Down Expand Up @@ -789,7 +789,7 @@ motor_start_bidir_done:
mov Initial_Run_Rot_Cntd, #12 ; Set initial run rotation countdown

; Initialize commutation
call comm5_comm6 ; Initialize commutation
call comm5_comm6 ; Enable MOSFET commutation
call comm6_comm1
call initialize_timing ; Initialize timing
call calc_next_comm_period ; Set virtual commutation point
Expand Down Expand Up @@ -889,7 +889,7 @@ run6:
jnb Flag_Startup_Phase, initial_run_phase

; Startup phase
mov Pwm_Limit, Pwm_Limit_Beg ; Set initial max power
mov Pwm_Limit_Startup_n_Temp, Pwm_Limit_Beg ; Set initial max power
mov Pwm_Limit_By_Rpm, Pwm_Limit_Beg; Set initial max power
clr C
mov A, Startup_Cnt ; Load startup counter
Expand Down Expand Up @@ -929,7 +929,7 @@ initial_run_phase_done:
; This plus the power limits applied in set_pwm_limit function
; act as a startup power limiter to protect the esc and the motor
; during startup, jams produced after crashes and desyncs recovery
mov Pwm_Limit, #255 ; Reset temperature level pwm limit
mov Pwm_Limit_Startup_n_Temp, #255 ; Reset temperature level pwm limit
mov Temp_Pwm_Level_Setpoint, #255 ; Reset temperature level setpoint

setb Flag_Motor_Started ; Set motor started
Expand Down Expand Up @@ -1068,9 +1068,6 @@ ENDIF
ljmp motor_start ; Go back and try starting motors again

exit_run_mode_is_stall:
; Enable all interrupts (disabled above, in exit_run_mode)
setb IE_EA

; Clear extended DSHOT telemetry flag if turtle mode is not active
; This flag is also used for EDT safety arm flag
; We don't want to deactivate extended telemetry during turtle mode
Expand All @@ -1082,16 +1079,13 @@ exit_run_mode_is_stall:

exit_run_mode_is_stall_beep:
; Stalled too many times
clr IE_EA
call beep_motor_stalled
setb IE_EA

; Enable all interrupts before jump (disabled above, in exit_run_mode)
setb IE_EA
ljmp arming_begin ; Go back and wait for arming

exit_run_mode_no_stall:
; Enable all interrupts (disabled above, in exit_run_mode)
setb IE_EA

; Clear extended DSHOT telemetry flag if turtle mode is not active
; This flag is also used for EDT safety arm flag
; We don't want to deactivate extended telemetry during turtle mode
Expand All @@ -1114,6 +1108,8 @@ exit_run_mode_no_stall_no_beep:
C_Com_Fet_On

exit_run_mode_brake_done:
; Enable all interrupts before jump (disabled above, in exit_run_mode)
setb IE_EA
ljmp wait_for_start ; Go back to wait for power on

;**** **** **** **** **** **** **** **** **** **** **** **** ****
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/Isrs.asm
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ t1_int_zero_rcp_checked:
t1_int_zero_rcp_checked_set_limit:
; Set pwm limit
clr C
mov A, Pwm_Limit ; Limit to the smallest
mov A, Pwm_Limit_Startup_n_Temp ; Limit to the smallest
mov Temp6, A ; Store limit in Temp6
subb A, Pwm_Limit_By_Rpm
jc t1_int_zero_rcp_checked_check_limit
Expand Down
7 changes: 7 additions & 0 deletions src/Modules/Power.asm
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@
;
;**** **** **** **** **** **** **** **** **** **** **** **** ****
switch_power_off:
; This three macros disable MOSFET communtation.
; Dshot frames will have no effect after disabling MOSFET communtation.
; Commutation is started again at motor_start_bidir_done.
All_Pwm_Fets_Off ; Turn off all pwm FETs
All_Com_Fets_Off ; Turn off all commutation FETs
Set_All_Pwm_Phases_Off

; Enforce all PWM limits to zero to disable dshot frame rcpulses
mov Pwm_Limit_By_Rpm, #0
mov Pwm_Limit_Startup_n_Temp, #0
ret

;**** **** **** **** **** **** **** **** **** **** **** **** ****
Expand Down
6 changes: 3 additions & 3 deletions src/Modules/Scheduler.asm
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,21 @@ scheduler_steps_odd:
; resulting in current spikes, that may damage motor/ESC.
; Compare pwm limit to setpoint
clr C
mov A, Pwm_Limit
mov A, Pwm_Limit_Startup_n_Temp
subb A, Temp_Pwm_Level_Setpoint
jz scheduler_steps_odd_choose_step ; pwm limit == setpoint -> next
jc scheduler_steps_odd_temp_pwm_limit_inc ; pwm limit < setpoint -> increase pwm limit

scheduler_steps_odd_temp_pwm_limit_dec:
; Decrease pwm limit
dec Pwm_Limit
dec Pwm_Limit_Startup_n_Temp

; Continue with odd scheduler step selection
sjmp scheduler_steps_odd_choose_step

scheduler_steps_odd_temp_pwm_limit_inc:
; Increase pwm limit
inc Pwm_Limit
inc Pwm_Limit_Startup_n_Temp

; Run speciffic odd scheduler step
scheduler_steps_odd_choose_step:
Expand Down

0 comments on commit de87570

Please sign in to comment.