Skip to content

Commit

Permalink
Reduced Timer3 handling critical sections length to avoid communicati…
Browse files Browse the repository at this point in the history
…ons problems because not processing interrups on time
  • Loading branch information
damosvil committed Jul 21, 2023
1 parent d15e5b0 commit debeb7b
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions src/Modules/Timing.asm
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,13 @@ wait_advance_timing:
; If it has not already, we wait here for the Wt_Adv_Start_ delay to elapse.
Wait_For_Timer3

; Disable interrupts
clr IE_EA

; Setup next wait time
mov TMR3RLL, Wt_ZC_Tout_Start_L
mov TMR3RLH, Wt_ZC_Tout_Start_H

; Disable interrupts
clr IE_EA

; Setup wait time
mov TMR3CN0, #00h ; Stop Timer 3
mov TMR3L, Wt_ZC_Tout_Start_L
Expand Down Expand Up @@ -565,11 +565,12 @@ ENDIF
mov Temp2, A

setup_zc_scan_timeout_startup_done:
clr IE_EA
mov TMR3CN0, #00h ; Timer3 disabled and interrupt flag cleared
clr C
clr A
subb A, Temp1 ; Set timeout

clr IE_EA
mov TMR3CN0, #00h ; Timer3 disabled and interrupt flag cleared
mov TMR3L, A
clr A
subb A, Temp2
Expand Down Expand Up @@ -694,17 +695,16 @@ comp_read_wrong_startup:
sjmp comp_check_timeout ; Continue to look for good ones

comp_read_wrong_extend_timeout:
clr IE_EA
mov TMR3CN0, #00h ; Timer3 disabled and interrupt flag cleared
jnb Flag_High_Rpm, comp_read_wrong_low_rpm ; Branch if not high rpm

clr IE_EA
mov TMR3CN0, #00h ; Timer3 disabled and interrupt flag cleared
mov TMR3L, #0 ; Set timeout to ~1ms
mov TMR3H, #-(8 SHL IS_MCU_48MHZ)

comp_read_wrong_timeout_set:
clr Flag_Demag_Detected ; Clear demag detected flag
mov TMR3CN0, #04h ; Timer3 enabled and interrupt flag cleared
setb IE_EA

clr Flag_Demag_Detected ; Clear demag detected flag
ljmp comp_start ; If comparator output is not correct - go back and restart

comp_read_wrong_low_rpm:
Expand All @@ -731,9 +731,16 @@ comp_read_wrong_load_timeout:
clr C
clr A
subb A, Temp7

clr IE_EA
mov TMR3CN0, #00h ; Timer3 disabled and interrupt flag cleared
mov TMR3L, #0
mov TMR3H, A
sjmp comp_read_wrong_timeout_set
mov TMR3CN0, #04h ; Timer3 enabled and interrupt flag cleared
setb IE_EA

clr Flag_Demag_Detected ; Clear demag detected flag
ljmp comp_start ; If comparator output is not correct - go back and restart

comp_exit:

Expand All @@ -748,14 +755,14 @@ setup_comm_wait:
; It is necessary to update the timer reload registers before the timer registers,
; to avoid a reload of the previous values in case of a short Wt_Comm_Start delay.

; Disable interrupts
clr IE_EA

; Advance wait time will be loaded by Timer3 immediately after the commutation wait elapses
; Setup next wait time
mov TMR3RLL, Wt_Adv_Start_L
mov TMR3RLH, Wt_Adv_Start_H

; Disable interrupts
clr IE_EA

; Setup wait time
mov TMR3CN0, #00h ; Timer3 disabled and interrupt flag cleared
mov TMR3L, Wt_Comm_Start_L
Expand Down Expand Up @@ -852,13 +859,13 @@ wait_for_comm_wait:
; At this point Timer3 has (already) wrapped and been reloaded with
; the Wt_Adv_Start_ delay.

; Disable interrupts
clr IE_EA

; Setup next wait time
mov TMR3RLL, Wt_Zc_Scan_Start_L
mov TMR3RLH, Wt_Zc_Scan_Start_H

; Disable interrupts
clr IE_EA

; Setup wait time
mov TMR3CN0, #00h ; Stop Timer 3
mov TMR3L, Wt_Zc_Scan_Start_L
Expand Down

0 comments on commit debeb7b

Please sign in to comment.