1 ;======================================================================
2 ; TRACK POWER AND SHORT CIRCUIT
6 settling_timeout equ 10000 ; us
8 stop_timeout equ 500000 ; us
9 stopflash_timeout equ 50000 ; us
10 retry_timeout equ 50000 ; us
11 persist_timeout equ 90000 ; us
14 settling res 1 ; all counters are 0 if stopped
15 stop_wait res 1 ; or otherwise count down
20 ;======================================================================
22 ; POLARISING/SETTLING:
24 ; NMRA flag_p. settling Booster PWM
26 ; Normal running 0 stopped mark
27 ; Polarising paused 1 stopped space
28 ; Settling paused 1 running space
30 ; NMRA is paused by disabling timer 0 intr; when we restart,
31 ; we restart the current message.
33 ;----------------------------------------------------------------------
36 power_polarising_init @
42 power_polarising_begin @
44 bc_f INTCON, TMR0IE ; disables NMRA interrupt
45 bs_f flags, flags_polarising
50 power_polarising_nonetodo @
52 bt_f_if0 flags, flags_polarising
56 mov_lw settling_timeout / tick_us
61 power_polarising_tick @
63 dec_f_ifnz settling ; decrement if not zero
64 return ; return if not dec'd, or if decrement didn't make zero
65 ; settle timeout complete:
67 bc_f flags, flags_polarising
69 call nmra_restartmessage
70 bs_f INTCON, TMR0IE ; reenables NMRA interrupt
71 goto i2c_consider_restartread
73 ;======================================================================
77 ; Shutdown CDU Time User Fault Next states and action when
78 ; fault timeout ON OFF
80 ; Off shutdown off none off On
81 ; On power-up on none off Stopping,FAULT Off
82 ; Stopping shutdown on 500ms 50% 1/100ms Retry
83 ; Retry power-up off 50ms off Persists Off,FIXED Off
84 ; Persists shutdown off 90ms on Retry Off
86 ; (no notation: event ignored)
87 make code correspond to new
88 get rid of Clearing state.
90 ; shutdown LAT stop_wait retry_wait
92 ; Off H (shutdown) 0 0
94 ; Stopping H (shutdown) before Retry for LED flash
95 ; Retry L (power-up) 0 before Off
96 ; Persists H (shutdown) 0 before retry
98 ; (uses tickdiv) (uses tick)
100 ;--------------------
102 bs_f INTCON2, INTEDG1 ; rising edge
108 pin_h p0_booster_shutdown
109 pin_h p0_booster_userfault
113 command_power_section code 0x2080
114 ;--------------------
116 ; Off -> On; noop in other states
117 pinlat_ifl p0_booster_shutdown
119 ; might be Off, Stopping or Persists:
121 tst_f_ifnz retry_wait
122 return ; that deals with Stopping or Persists
125 pin_vl p0_booster_shutdown
131 ; On -> Off; noop in other states
132 pinlat_ifh p0_booster_shutdown
133 return ; Off, Stopping or Persists
134 ; might be On or Retry:
136 tst_f_ifnz retry_wait
137 return ; that deals with Retry
140 pin_vh p0_booster_shutdown
144 ;--------------------
146 bt_f_if0 INTCON3, INT1IF
154 bra_z power_fault_newshort ; we were Off or On
155 ; must be Stopping, Retry or Persists:
158 bra power_fault_stopmore ; we were already Stopping; restart timer
159 ; might be Retry or Persists, goto Persists (restarting any timer):
161 mov_lw persist_timeout / tick_us
163 pin_vl p0_booster_userfault
165 intrl_handled_nostack
172 mov_lw stop_timeout / tickdiv_us
174 pin_vl p0_booster_userfault
175 rcall power_stop_doflash
176 intrl_handled_nostack
178 ;--------------------
180 tst_f_ifnz retry_wait
181 dec_f_ifnz retry_wait
183 ; retry_wait was running but has just reached zero;
184 ; we were in Stopping, Retry or Persists:
187 bra power_stop_doflash ; that was Stopping, just flash the LED
188 ; must be Retry or Persists:
190 pinlat_ifh p0_booster_shutdown
191 bra power_retry ; we were in Persists, now we can try again
192 ; we were in Retry and it worked.
194 pin_vh p0_booster_shutdown
195 pin_vh p0_booster_userfault
201 pin_vhl p0_booster_userfault
202 mov_lw stopflash_timeout / tick_us
206 ;--------------------
207 power_fault_tickdiv @
211 ; stop_wait was running but has just reached zero;
212 ; we were in Stopping, now we can Retry:
214 mov_lw retry_timeout / tickdiv_us
216 pin_vl p0_booster_shutdown
217 pin_vh p0_booster_userfault
220 ;--------------------
222 pin_vh p0_booster_shutdown
223 pin_vl p0_booster_pwm
224 pin_vh p0_booster_userfault
227 ;======================================================================