BLHeli
BLHeli copied to clipboard
bug with demag process
when Flags0.DEMAG_DETECTED is set,if a wrong comparator value is get,the timeout timer delay value of Wt_Zc_Tout_Start is reset. So the Wt_Zc_Tout_Start delay value is not of meanning,because when a new zero cross point is check,the Flags0.DEMAG_DETECTED is set.
wait_for_comp_out_low:
setb Flags0.DEMAG_DETECTED ; Set demag detected flag as default
mov Comparator_Read_Cnt, #0 ; Reset number of comparator reads
mov Bit_Access, #00h ; Desired comparator output
jnb Flags1.DIR_CHANGE_BRAKE, ($+6)
mov Bit_Access, #40h
ajmp wait_for_comp_out_start
wait_for_comp_out_high:
setb Flags0.DEMAG_DETECTED ; Set demag detected flag as default
mov Comparator_Read_Cnt, #0 ; Reset number of comparator reads
mov Bit_Access, #40h ; Desired comparator output
jnb Flags1.DIR_CHANGE_BRAKE, ($+6)
mov Bit_Access, #00h
comp_read_wrong_not_startup:
jb Flags0.DEMAG_DETECTED, comp_read_wrong_extend_timeout
inc Temp1 ; Increment number of OK readings required
clr C
mov A, Temp1
subb A, Temp2
jc ($+4)
ajmp wait_for_comp_out_start ; If above initial requirement - go back and restart
ajmp comp_check_timeout ; Otherwise - take another reading
comp_read_wrong_extend_timeout:
clr Flags0.DEMAG_DETECTED ; Clear demag detected flag
anl EIE1, #7Fh ; Disable timer 3 interrupts
mov TMR3CN0, #00h ; Timer 3 disabled and interrupt flag cleared
jnb Flags1.HIGH_RPM, comp_read_wrong_low_rpm ; Branch if not high rpm
mov TMR3L, #00h ; Set timeout to ~1ms
IF MCU_48MHZ == 1
mov TMR3H, #0F0h
ELSE
mov TMR3H, #0F8h
ENDIF
comp_read_wrong_timeout_set:
mov TMR3CN0, #04h ; Timer 3 enabled and interrupt flag cleared
setb Flags0.T3_PENDING
orl EIE1, #80h ; Enable timer 3 interrupts
ljmp wait_for_comp_out_start ; If comparator output is not correct - go back and restart
comp_read_wrong_low_rpm:
mov A, Comm_Period4x_H ; Set timeout to ~4x comm period 4x value
mov Temp7, #0FFh ; Default to long
IF MCU_48MHZ == 1
clr C
rlc A
jc comp_read_wrong_load_timeout
ENDIF
clr C
rlc A
jc comp_read_wrong_load_timeout
clr C
rlc A
jc comp_read_wrong_load_timeout
mov Temp7, A
comp_read_wrong_load_timeout:
clr C
clr A
subb A, Temp7
mov TMR3L, #0
mov TMR3H, A
ajmp comp_read_wrong_timeout_set