|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2008-6-16 16:01:32
|
显示全部楼层
请问【5楼】 feng_matrix :
calculate_next_timing_values:
rcall tcnt1_to_temp
ldi temp4, EXT0_EN ; ext0int enable
out GIMSK, temp4 ; enable ext0int
sts tcnt1_sav_l, temp1
sts tcnt1_sav_h, temp2
sts tcnt1_sav_x, temp3
lds YL, last_tcnt1_l
lds YH, last_tcnt1_h
lds ZL, last_tcnt1_x
sub temp1, YL
sbc temp2, YH
sbc temp3, ZL
; now temp-registers hold the time of 360° - means: 6 commutations
; each commutation is divided in two stages:
; a) wait for expected zero-crossing
; b) wait less than 30° and commutate
; divide by 12 would result in 0° timing ( 30° )
; *** earlier zero-crossing as it is expected, cannot be detected
; *** switch to next commutation not less than 30° - means: stall
; divide by 16 would result in 7.5 degree timing ( 30.0°-22.5° ), works !
; *** start to look for zero-crossing 7.5° earlier than it is expected
; *** switch to next commutation 7.5° earlier than 30°
; 7.5° value can be changed when setting <wt_FET_switch>
ldi temp4, 4 ; divide by 16
calc_OCT1_d16: lsr temp3
ror temp2
ror temp1
dec temp4
brne calc_OCT1_d16
mov YL, temp1
mov YH, temp2
mov ZL, temp3
; ZL should be zero - if not, use max value
tst temp3
brne calc_OCT1_res
sts OCT1_high, temp2
tst temp2
breq calc_OCT1_of10
subi temp1, low (defaultTIMEOUT)
sbci temp2, high(defaultTIMEOUT)
brcc calc_OCT1_res
rjmp calc_OCT1_of80
calc_OCT1_of10: mov temp2, tcnt0_power_on
asr temp2
asr temp2 ; (e7-ff)
subi temp2, 0xca ; 9c->1b and ff->33
; the maximum of allowed RPM is dependent from PWM
; therefore 134000 RPM (refered to 6 commutations each) is reached now
;temp2 rpm (6 Kom.) rpm Achse
;0x1b 138888 23148 ; full power
;0x33 73529 12254 ; lowest power
cp temp1, temp2
brcc calc_OCT1_of80
calc_OCT1_res: rcall set_default_timeout
rjmp calc_OCT1_of90
calc_OCT1_of80:
sts wt_comp_scan_l, YL ; capture compare offset for time from switch to comparator scanning
sts wt_comp_scan_h, YH
sts wt_FET_switch_l, YL ; capture compare offset for time from zero-crossing to switch
sts wt_FET_switch_h, YH
calc_OCT1_of90: lds temp1, tcnt1_sav_l
lds temp2, tcnt1_sav_h
lds temp3, tcnt1_sav_x
sts last_tcnt1_l, temp1
sts last_tcnt1_h, temp2
sts last_tcnt1_x, temp3
ret
这段程序是从T1中得到转一周360度(6次换相)的时间,然后除以16得到延迟22.5度的时间,一下的部分有什么用呢
; ZL should be zero - if not, use max value
tst temp3
brne calc_OCT1_res
sts OCT1_high, temp2
tst temp2
breq calc_OCT1_of10
subi temp1, low (defaultTIMEOUT)
sbci temp2, high(defaultTIMEOUT)
brcc calc_OCT1_res
rjmp calc_OCT1_of80
calc_OCT1_of10: mov temp2, tcnt0_power_on
asr temp2
asr temp2 ; (e7-ff)
subi temp2, 0xca ; 9c->1b and ff->33
; the maximum of allowed RPM is dependent from PWM
; therefore 134000 RPM (refered to 6 commutations each) is reached now
;temp2 rpm (6 Kom.) rpm Achse
;0x1b 138888 23148 ; full power
;0x33 73529 12254 ; lowest power |
|