📄 timer.asm
字号:
;*************************************************************
timer_check:
;*************************************************************
call buzonce_check ;
call wait_check ;
call pwm_process ;make P (V*I) stable by adjust PWM output.
call temp_check ;
call fan_check ;fan control.
call voltage_process ;
snz power_f ;
jmp TimerChkEnd ;
call force_change ;
call current_process ;
call IGBT_volt_check ;
call jianxie_pre ;the nexe 3 subroutine must keep the sequence
call pot_check ;
call PotChkPre ;place next to pot_check, so PWM on first, next 2.5ms check the current.
call TimeOff_check ;timer auto OFF.
call M120Off_check ;no operation for 120 minutes, OFF.
call error_process ;
jmp TimerChkEnd ;
;************************************
wait_check:
sz power_f ;
ret ;
snz ms100_f ;
ret ;
snz wait_f ;
ret ;
sdz timer_wait ;
ret ;
clr wait_f ;
ret ;
;********************************************************************
force_change:
snz pot_f ;
ret ;
snz ms100_f ;
ret ;
inc timer_ForceChange ;
mov a, timer_ForceChange ;
add a, 256-TIME_FORCECHANGE ;
snz c ;
ret ;
clr timer_ForceChange ;
mov a, force_now ;
sub a, force_preset; ;
sz c ;
ret ;c=1; force_now >= force_preset, no need to change now.
inc force_now ;
mov a, force_now ;
add a, 255-MAX_FORCE ;
snz c ;
ret ;
mov a, MAX_FORCE ;
mov force_now, a ;
ret ;
;***********************************
jianxie_pre:
snz s3_f ;
ret ;
sz force_preset ;
ret ;force_value!=0, not jianxie heating.
snz pwm_on_f ;
jmp jx_on ;
jx_off:
clr pwm_on_f ;
clr _switch ;
clr _pwm ;
ret ;
jx_on:
sdz timer_jianxie ;
ret ;
mov a, 1 ;
mov timer_jianxie, a ;
set pwm_on_f ;
clr pot_f ;attention, assume no pot here.
ret ;
;**********************************************************************
PotChkPre:
snz power_f ;
ret ;
snz s3_f ;
ret ;
sz pot_f ;
ret ;
sz force_preset ;if it's jianxie heating, don't check pot untill time up.
jmp pcp_go ;
snz pwm_on_f ;
ret ;
pcp_go:
sz error_flag ;
ret ;
set pot_check_f ;
clr pot_counter ;
clr ad_h ;
clr ad_l ;
mov a, PWM_POTCHECK ;
mov pwm, a ;
set _switch ;
set _pwm ;
ret ;
;**********************************************************************
; check pot every 3s.
pot_check:
sz error_flag ;
ret ;
sz pot_f ;
ret ;
snz pot_check_f ;
ret ;
;get current value.
mov a, AN_CURRENT ;select AN channel.
call ad_com ;return acc.
addm a, ad_l ;
sz c ;
inc ad_h ;
inc pot_counter ;
mov a, (256-32) ;
add a, pot_counter ;
snz c ;
ret ;
mov a, 5 ;(adh,adl)/32
rrc ad_h ;
rrc ad_l ;
sdz acc ;
jmp $-3 ;
clr pot_check_f ;32 sample taken, stop pot check.
mov a, ad_l ;ad_l is the result.
add a, (256-CURR_POTCHK) ;pot check current value.
sz c ;
jmp PotChk_OK ;
;no pot yet.
clr _switch ;
clr _pwm ;
call SetBuzOnce ;
call disp_nopot ;
inc timer_PotChk ;
mov a, 256-TIME_POTCHK ;
add a, timer_PotChk ;
sz c ;
call power_off ;
ret ;
PotChk_OK:
set pot_f ;
mov a, ad_l ;
mov iad_data, a ;
mov a, 150 ;power on PWM value.
mov pwm, a ;
DispCom:
call DispModeLED ;
call DispForceLED ;
jmp FillTimeValue ;
;*************************************************************
TimeOff_check:
snz minute_f ;do it every minute.
ret ;
sz time_preset ;
jmp $+2
ret ;
sdz time_preset ;
jmp TimeOff_disp ;
call power_off ;
call SetBuzOnce ;
ret ;
TimeOff_disp:
sz error_flag ;
ret ;
jmp DispCom ;
;*************************************************************
; auto off after no operation for 120 minutes.
;
M120Off_check:
ret
snz power_f ;
ret ;
snz minute_f ;do it every minute.
ret ;
sz time_preset ;
ret ;only when not time off state.
inc timer_120m ;
mov a, 256-TIME_120M ;
add a, timer_120m ;
snz c ;
ret
call power_off ;
call SetBuzOnce ;
ret ;
;*************************************************************
; every 800ms get the POT and IGBT temperature.
;
temp_check:
snz ms100_f ;
ret ;every 100ms, sample.
sz temp_counter.2 ;every 4 sample, change.
jmp tc_pot ;
; jmp tc_igbt ;
;***
;igbt temperature.
tc_igbt:
mov a, AN_IGBT ;select AN channel.
call ad_com ;
addm a, temp_lo ;
sz c ;
inc temp_hi ;
inc temp_counter ;
mov a, 03h ;bit 1.0=00, total 4 sample.
and a, temp_counter ;
sz acc ;
ret ;
mov a, 2 ;get the average value.
rrc temp_hi ;
rrc temp_lo ;
sdz acc ;
jmp $-3 ;
mov a, temp_lo ;
mov temp_igbt, a ;
clr temp_hi ;
clr temp_lo ;
call Tigbt_process ;
ret ;
;***
;channel pot
tc_pot:
mov a, AN_POT ;select AN channel.
call ad_com ;
addm a, temp_lo ;
sz c ;
inc temp_hi ;
inc temp_counter ;
mov a, 03h ;bit 1.0=00, total 4 sample.
and a, temp_counter ;
sz acc ;
ret ;
mov a, 2 ;get the average value.
rrc temp_hi ;
rrc temp_lo ;
sdz acc ;
jmp $-3 ;
mov a, temp_lo ;
mov temp_pot, a ;
clr temp_hi ;
clr temp_lo ;
call Tpot_process ;
ret ;
;*************************************************************
current_process:
;*************************************************************
mov a, force_now ;
add a, low(CurrLowTbl) ;
mov tblp, a ;
tabrdl acc ;
sub a, iad_data ;
sz c ;
jmp cp_low ;c=1, table>iad_data
set curr_high_f ;
mov a, iad_data ;
add a, 256-CURR_HIGH ;
snz c ;
clr curr_high_f ;
ret ;
cp_low:
snz power_f ;
ret ;
snz pot_f ;
ret ;
sz force_now ;
jmp cplow_go ;
snz pwm_on_f ;
ret ;
cplow_go:
clr pot_f ;
clr _switch ;
clr _pwm ;
mov a, PWM_POTCHECK ;
mov pwm, a ;
clr force_now ;
clr timer_PotChk ;
call disp_nopot ;
call SetBuzOnce ;
clr timer_3s ;so the next check whil be 3s later.
ret ;
;*************************************************************
voltage_process:
snz ms100_f ;
ret ;
SetVoltHigh:
mov a, vad_data ;
add a, (255-VOLT_HIGH) ;
sz c ;
jmp vp_high ;
clr timer_VoltHigh ;
mov a, vad_data ;
add a, (256-VOLT_NOTHIGH) ;
snz c ;
clr volt_high_f ;
jmp SetVoltLow ;
vp_high:
inc timer_VoltHigh ;
mov a, timer_VoltHigh ;
add a, 256-5 ;
snz c ;
jmp SetVoltLow ;
clr timer_VoltHigh ;
set volt_high_f ;
; ret ;
SetVoltLow:
mov a, vad_data ;
add a, (256-VOLT_LOW) ;
snz c ;
jmp vp_low ;
mov a, vad_data ;
add a, (256-VOLT_NOTLOW) ;
sz c ;
clr volt_low_f ;
ret ;
vp_low:
set volt_low_f ;
ret ;
;*************************************************************
Tigbt_process:
;open
clr igbt_open_f ;
mov a, 255-TEMP_IGBTOPEN ;
add a, temp_igbt ;
snz c ;
set igbt_open_f ;
;short
clr igbt_short_f ;
mov a, 3 ;
add a, temp_igbt ;
sz c ;
set igbt_short_f ;
;over heat
sz igbt_heat_f ;
jmp tp_igbt_hi ;
mov a, 256-TEMP_IGBTHI ;
add a, temp_igbt ;
snz c ;
ret ;
set igbt_heat_f ;
clr _switch ;when igbt overheat, stop IGBT at once.
clr _pwm ;
ret
tp_igbt_hi:
mov a, 256-TEMP_IGBTNOTHI ;
add a, temp_igbt ;
snz c ;
clr igbt_heat_f ;
ret ;
;*************************************************************
Tpot_process:
;short
set pot_err_f ;
mov a, 3 ;
add a, temp_pot ;
sz c ;
ret ;
mov a, 256-8 ;
add a, temp_pot ;
snz c ;
ret
clr pot_err_f ;
;temp_OK?
mov a, temp_preset ;
add a, low(TempHighTbl) ;
mov tblp, a ;
tabrdl acc ;
sub a, temp_pot ;
sz c ;
jmp tp_tempok ;c=1, temp_pot<= TEMP_HIGH edge.
set temp_ok_f ;c=0, temp_pot is bigger than the high level.
ret
tp_tempOK:
mov a, temp_preset ;
add a, low(TempLowTbl) ;
mov tblp, a ;
tabrdl acc ;
sub a, temp_pot ;
sz c ;
clr temp_ok_f ;
ret ;
;*************************************************************
; after power off, turn off the fan when igbt temp is 50 below ,
; or fan worked for over 4 minutes.
;
fan_check:
sz power_f ;
ret ;
snz s3_f ;
ret ;
snz fan_f ;
ret ;
mov a, 256-TEMP_IGBT50 ;
add a, temp_igbt ;
snz c ;
jmp fc_stop ;
inc timer_fan ;
mov a, 256-TIME_FAN ;
add a, timer_fan ;
snz c ;
ret
fc_stop:
clr timer_fan ;
clr fan_f ;
clr _fan ;
ret ;
;************************************************************************
; P=V*I take voltage and current sample,
; and try to make P stable.
;************************************************************************
pwm_process:
call get_vad ;return vad_temp
call get_iad ;return iad_temp
inc vi_counter ;total samples
mov a, vi_counter ;
add a, 256-50 ;20 before
snz c ;
ret ;
clr vi_counter ;
mov a, iad_temp ;get the peak value.
mov iad_data, a ;
mov a, vad_temp ;
mov vad_data, a ;
clr iad_temp ;prepare for the next.
clr vad_temp ;
; adjust pwm here.
snz power_f ;
ret ;
snz pot_f ;
ret ;
sz force_preset ;
jmp $+3 ;
snz pwm_on_f ;
ret ;
call mul_vi ;P=V*I
call pwm_adjust ;
ret ;
;************************************
; p_data= vad_data * iad_data
;
mul_vi:
mov a,vad_data
mov w1, a
mov a,iad_data
mov w0,a
mpyu:
clr g_temp
clr c
mov a,8
mov w2, a
rrc w0
m8u_1:
snz c
jmp m8u_2
mov a,w1
addm a, g_temp
m8u_2:
rrc g_temp
rrc w0
sdz w2
jmp m8u_1
mov a,g_temp
mov p_data, a
ret ;
;************************************
pwm_adjust:
mov a, 100 ;
sub a, pwm ;
snz c ;
jmp pa_go ;
mov a, 100 ;
mov pwm, a ;
pa_go:
mov a, (256-5ah) ;200V
add a, vad_data ;
sz c ;
jmp pa_stable_p ;V >= 200v
jmp pa_stable_i ;V < 200v
pa_stable_p:
mov a, force_preset ;
add a, low(PowerTbl) ;
mov tblp, a ;
tabrdl acc ;
mov w0, a ;w0 is the preset POWER value.
xor a, p_data ;
sz z ;
ret ;stable, return.
mov a, w0 ;w0= preset POWER value.
sub a, p_data ;
snz c ;
jmp pa_pwmdec ;
mov a, w0 ;
sub a, 1 ;
sub a, p_data ;
sz c ;
jmp pa_pwminc ;
ret ;
pa_stable_i:
mov a, force_preset ;
add a, low(CurrentTbl) ;
mov tblp, a ;
tabrdl acc ;
mov w0, a ;w0= preset CURRENT value.
xor a, iad_data ;
sz z ;
ret ;
mov a, w0 ;
sub a, iad_data ;
snz c ;
jmp pa_pwmdec ;
mov a, w0 ;
sub a, 1 ;
sub a, iad_data ;
sz c ;
jmp pa_pwminc ;
ret ;
;*************************
pa_pwmdec:
mov a, 80
sub a, pwm
snz c
dec pwm
ret
pa_pwminc:
mov a, 240 ;253 before
sub a, pwm
sz c
inc pwm
ret
;***********************************
get_vad:
mov a, AN_VOLTAGE ;select AN channel.
call ad_com ;
sub a, vad_temp ;
snz c ;
ret ;value is smaller, return.
mov a, adrh ;
mov vad_temp, a ;
ret ;
;***********************************
get_iad:
mov a, AN_CURRENT ;select AN channel.
call ad_com ;
sub a, iad_temp ;
snz c ;
ret ;value is smaller, return.
mov a, adrh ;
mov iad_temp, a ;
ret ;
;************************************
ad_com:
mov w0, a ;
mov a, 11111000b ;
andm a, adcr ;
mov a, w0 ;select AN channel.
orm a, adcr ;
set start ;
nop ;
clr start ;
sz eoc ;
jmp $-1 ;
mov a, adrh ;
ret ;
;********************************************************************
disp_process:
mov a, disp_mode ;
addm a, pcl ;
jmp dp_idle ;
jmp dp_blink ;
jmp dp_poff ;
;***********************************
dp_idle:
ret ;
;************************************
dp_blink:
snz ms100_f ;
ret ;
sdz timer_disp ;
ret ;
sdz disp_state ;
jmp $+2 ;
jmp disp2idle ;
sz disp_state.0 ;
jmp dp_blinkoff ;
dp_blinkon:
mov a, TIME_BLINKON ;
mov timer_disp, a ;
jmp FillTimeShadow ;
dp_blinkoff:
mov a, TIME_BLINKOFF ;
mov timer_disp, a ;
jmp FillBlank ;
disp2idle:
clr disp_mode ;
jmp FillTimeValue ;
;************************************
dp_poff:
snz ms100_f ;
ret ;
sdz timer_disp ;
ret ;
inc disp_state ;
sz disp_state.0 ;
jmp dp_poffoff ;
dp_poffon:
mov a, TIME_BLINKON ;
mov timer_disp, a ;
set vLED_POWER0 ;
set vLED_POWER1 ;
ret ;
dp_poffoff:
mov a, TIME_BLINKOFF ;
mov timer_disp, a ;
clr vLED_POWER0 ;
clr vLED_POWER1 ;
ret ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -