|
第3部分
-
- ; 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
- 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
- ; if an other timing than 7.5° is wanted, change YL,YH here
- ; example (13.1°):
- ; lsr YH
- ; ror YL
- ; mov temp1,YL ; 1/32 + 1/64 = 1/21.33 (30°-16.9°=13.1°)
- ; mov temp2,YH
- ; lsr temp2
- ; ror temp1
- ; add YL, temp1
- ; adc YH, temp2
- ; example (10.3°):
- ; lsr YH
- ; ror YL
- ; mov temp1,YL ; 1/32 + 1/64 + 1/128 = 1/18.3 (30°-19.7°=10.3°)
- ; mov temp2,YH
- ; lsr temp2
- ; ror temp1
- ; add YL, temp1
- ; adc YH, temp2
- ; lsr temp2
- ; ror temp1
- ; add YL, temp1
- ; adc YH, temp2
- ; example (8.9°):
- ; lsr YH
- ; ror YL
- ; mov temp1,YL ; 1/32 + 1/64 + 1/128 + 1/256 = 1/17.1 (30°-21.1°=8.9°)
- ; mov temp2,YH
- ; lsr temp2
- ; ror temp1
- ; add YL, temp1
- ; adc YH, temp2
- ; lsr temp2
- ; ror temp1
- ; add YL, temp1
- ; adc YH, temp2
- ; lsr temp2
- ; ror temp1
- ; add YL, temp1
- ; adc YH, temp2
- ; example (7.5°):
- ; do nothing
- ; example (6.1°):
- ; mov temp1,YL ; 1/16 + 1/256 = 1/15.06 (30°-23.9°=6.1°)
- ; mov temp2,YH
- ; ldi temp4, 4 ; divide by 16
- ;calc_OCT1_dt: lsr temp2
- ; ror temp1
- ; dec temp4
- ; brne calc_OCT1_dt
- ; add YL, temp1
- ; adc YH, temp2
- ; example (4.7°):
- ; mov temp1,YL ; 1/16 + 1/128 = 1/14.22 (30°-25.3°=4.7°)
- ; mov temp2,YH
- ; ldi temp4, 3 ; divide by 8
- ;calc_OCT1_dt: lsr temp2
- ; ror temp1
- ; dec temp4
- ; brne calc_OCT1_dt
- ; add YL, temp1
- ; adc YH, temp2
- 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
- ;-----bko-----------------------------------------------------------------
- .if RC_PULS == 1
- evaluate_rc_puls:
- sbrs state1, RC_PULS_UPDATED
- rjmp eval_rc_p90
- mov temp1, new_rcpuls_l
- mov temp2, new_rcpuls_h
- cbr state1, (1<
- subi temp1, low (MIN_RC_PULS)
- sbci temp2, high (MIN_RC_PULS)
- brcc eval_rc_p00
- clr temp1
- clr temp2
- eval_rc_p00: lsr temp2
- ror temp1
- lsr temp2
- ror temp1
- lsr temp2
- ror temp1
- mov temp3, temp1
- subi temp1, low (POWER_RANGE)
- sbci temp2, high (POWER_RANGE)
- brcs eval_rc_p10
- ldi temp3, low (POWER_RANGE)
- eval_rc_p10: mov ZH, temp3
- eval_rc_p90: ret
- .endif
- ;-----bko-----------------------------------------------------------------
- evaluate_sys_state:
- sbrs state1, T1OVFL_FLAG
- rjmp eval_sys_s99
- ; do it not more often as every 65µs
- cbr state1, (1<
- ; control current
- eval_sys_i: sbrs state0, I_pFET_HIGH
- rjmp eval_sys_i_ok
- cbr state0, (1<
- mov i_temp1, current_err
- cpi i_temp1, CURRENT_ERR_MAX
- brcc panic_exit
- inc current_err
- rjmp eval_sys_ub
- eval_sys_i_ok: tst current_err
- breq eval_sys_ub
- dec current_err
- ; control voltage
- eval_sys_ub: sbrs state0, UB_LOW
- rjmp eval_sys_ub_ok
- cbr state0, (1<
- mov i_temp1, sys_control
- cpi i_temp1, POWER_RANGE
- brcc eval_sys_s99
- inc sys_control
- rjmp eval_sys_s99
- eval_sys_ub_ok: tst sys_control
- breq eval_sys_s99
- dec sys_control
-
- eval_sys_s99: rcall set_new_duty
- ret
- panic_exit: ; !!!!!! OVERCURRENT !!!!!!!!
- cli
- rjmp reset
- ;-----bko-----------------------------------------------------------------
- wait_OCT1_before_comp_scan:
- sbr state0, (1<
- lds YL, wt_comp_scan_l
- lds YH, wt_comp_scan_h
- rcall tcnt1_to_temp
- add YL, temp1
- adc YH, temp2
- ldi temp1, (1<<
- out TIMSK, temp1
- out OCR1AH, YH
- out OCR1AL, YL
- ldi temp1, (1<<<
- out TIMSK, temp1
- ldi temp4, EXT0_EN ; ext0int enable
- out GIMSK, temp4 ; enable ext0int
- wait_OCT1_next: sbrc state0, OCT1_PENDING
- rjmp wait_OCT1_next
- wait_OCT1_tot: cbi ADCSRA, ADEN ; switch to comparator multiplexed
- in temp1, SFIOR
- ori temp1, (1<
- out SFIOR, temp1
- sbr state0, (1<
- rcall tcnt1_to_temp
- ldi YL, low (compScanTIMEOUT)
- ldi YH, high(compScanTIMEOUT)
- add temp1, YL
- adc temp2, YH
- ldi temp3, (1<<
- out TIMSK, temp3
- out OCR1AH, temp2
- out OCR1AL, temp1
- ldi temp3, (1<<<
- out TIMSK, temp3
- ldi temp4, EXT0_EN ; ext0int enable
- out GIMSK, temp4 ; enable ext0int
- ret
- ;-----bko-----------------------------------------------------------------
- wait_OCT1_before_switch:
- sbr state0, (1<
- rcall tcnt1_to_temp
- lds YL, wt_FET_switch_l
- lds YH, wt_FET_switch_h
- add temp1, YL
- adc temp2, YH
- ldi temp3, (1<<
- out TIMSK, temp3
- out OCR1AH, temp2
- out OCR1AL, temp1
- ldi temp3, (1<<<
- out TIMSK, temp3
- ldi temp4, EXT0_EN ; ext0int enable
- out GIMSK, temp4 ; enable ext0int
- ; don't waste time while waiting - do some controls, if indicated
- OCT1_ready: sbrc state1, CALC_NEXT_OCT1
- rcall calculate_next_timing_values ; calculate values while compare timer is active
- .if RC_PULS == 1
- sbrc state1, EVAL_RC_PULS
- rcall evaluate_rc_puls
- .endif
- sbrc state1, EVAL_SYS_STATE
- rcall evaluate_sys_state
- OCT1_wait: sbrc state0, OCT1_PENDING
- rjmp OCT1_wait
- ret
- ;-----bko-----------------------------------------------------------------
- set_new_duty: mov temp1, ZH
- sub temp1, sys_control
- brcc set_new_duty10
- ldi temp1, MIN_DUTY-1
- set_new_duty10: lds temp2, OCT1_high ; get actual RPM reference high
- cpi temp2, 8 ; lower than 8xx? ( 1831 RPM )
- brcs set_new_duty20 ; on carry - test next range
- ldi temp2, POWER_RANGE ; higher than 1/4 power max ?
- lsr temp2
- lsr temp2
- cp temp1, temp2
- brcs set_new_duty30 ; on carry - not higher, no restriction
- mov temp1, temp2 ; low (range1) RPM - set to 1/4 max
- rjmp set_new_duty30
- set_new_duty20: cpi temp2, 4 ; lower than 4xx? ( 3662 RPM )
- brcs set_new_duty30 ; on carry - not lower, no restriction
- ldi temp2, POWER_RANGE ; higher than 1/2 power max ?
- lsr temp2
- cp temp1, temp2
- brcs set_new_duty30 ; on carry - not higher, no restriction
- mov temp1, temp2 ; low (range2) RPM - set to 1/2 max
- set_new_duty30: com temp1 ; down-count to up-count (T0)
- mov tcnt0_pwron_next, temp1 ; save in next
- ; tcnt0_power_on is updated to tcnt0_pwron_next in acceptable steps
- ret
- ;-----bko-----------------------------------------------------------------
- set_default_timeout:
- ldi temp1, NO_POWER
- mov tcnt0_power_on, temp1
- ldi temp1, 8
- sts OCT1_high, temp1
- ldi YL, low (defaultTIMEOUT)
- ldi YH, high(defaultTIMEOUT)
- sts wt_comp_scan_l, YL ; write default timing value
- sts wt_comp_scan_h, YH
- ret
- ;-----bko-----------------------------------------------------------------
- .if UART_CONTROL == 1
- read_uart: in temp1,UDR ; read data - clear rxc-flag
- cpi temp1,'+'
- brne read_uart_10
- ; do (+) job
- cpi ZH, POWER_RANGE
- brsh read_uart_90
- rcall send_byte
- inc ZH
- rcall set_new_duty
- rjmp read_uart_90
- read_uart_10: cpi temp1,'-'
- brne read_uart_20
- ; do (-) job
- cpi ZH, MIN_DUTY-1
- breq read_uart_90
- rcall send_byte
- dec ZH
- rcall set_new_duty
- rjmp read_uart_90
- read_uart_20:
- .if UART_FULL == 1
- cpi temp1,'#'
- brne read_uart_30
- ; do (#) job
- clr XH
- ldi XL, uart_data
- sbr state0, (1<
- ldi temp1,0x0d
- rcall send_byte
- ldi temp1,'#'
- st X+,temp1
- mov temp1,state0
- rcall hex2buf
- mov temp1,state1
- rcall hex2buf
- mov temp1,tcnt0_power_on
- rcall hex2buf
- lds temp1,wt_comp_scan_h
- rcall hex2buf
- lds temp1,wt_comp_scan_l
- rcall hex2buf
- ldi temp1,'-'
- st X+,temp1
- rjmp read_uart_90
- .endif
- read_uart_30: cpi temp1,'1'
- brne read_uart_40
- ; do (1) job
- ldi ZH, MIN_DUTY+0x30
- rcall send_byte
- rcall set_new_duty
- rjmp read_uart_90
- read_uart_40: cpi temp1,'2'
- brne read_uart_89
- ; do (2) job
- ldi ZH, MIN_DUTY-1
- rcall send_byte
- rcall set_new_duty
- rjmp read_uart_90
- read_uart_89: ldi temp1,'?'
- rcall send_byte
- read_uart_90: ret
复制代码 |
|