For completeness here is count2200 which is the last of the high speed code.
This routine counts to see if it is time for the slow speed code. If it is, it copies the contents of the accumulators to a safe location and clears the accumulators. After that it is safe to re-enable the timer 2 interrupt. We are still inside the timer 2 interrupt routine, but we will not be using the high speed variables so it is safe to allow this part of the code to be interrupted. In fact it is necessary because the slow speed routines are going to take a lot longer than one quarter cycle to complete.
Robert Hoolko
count2200:
; Update counters
; Count 2200ths of a sec
; and call the slow loop routines if it is time
; Registers r16 r17 r18 Z are free
lds r16,c2200
inc r16 ; 2200dths
sts c2200,r16
cpi r16,74 ; 74 = 30 Hz
breq cntslow ;
ret
; We are now in the slow loop, 30 Hz
cntslow:
clr r16
sts c2200,r16 ; clear counter
lds r16,Iaccum ; copy accumulated data I
lds r17,Iaccum+1
lds r18,Iaccum+2
sts Ihold,r16
sts Ihold+1,r17
sts Ihold+2,r18
lds r16,Qaccum ; copy accumulated data Q
lds r17,Qaccum+1
lds r18,Qaccum+2
sts Qhold,r16
sts Qhold+1,r17
sts Qhold+2,r18
clr r16
sts Iaccum,r16 ; clear accumulators
sts Iaccum+1,r16
sts Iaccum+2,r16
sts Qaccum,r16
sts Qaccum+1,r16
sts Qaccum+2,r16
; It is now safe to allow the T2
sei ; interrupt to occur again
rcall Islow ; go do the slow routines
ret
This routine counts to see if it is time for the slow speed code. If it is, it copies the contents of the accumulators to a safe location and clears the accumulators. After that it is safe to re-enable the timer 2 interrupt. We are still inside the timer 2 interrupt routine, but we will not be using the high speed variables so it is safe to allow this part of the code to be interrupted. In fact it is necessary because the slow speed routines are going to take a lot longer than one quarter cycle to complete.
Robert Hoolko
count2200:
; Update counters
; Count 2200ths of a sec
; and call the slow loop routines if it is time
; Registers r16 r17 r18 Z are free
lds r16,c2200
inc r16 ; 2200dths
sts c2200,r16
cpi r16,74 ; 74 = 30 Hz
breq cntslow ;
ret
; We are now in the slow loop, 30 Hz
cntslow:
clr r16
sts c2200,r16 ; clear counter
lds r16,Iaccum ; copy accumulated data I
lds r17,Iaccum+1
lds r18,Iaccum+2
sts Ihold,r16
sts Ihold+1,r17
sts Ihold+2,r18
lds r16,Qaccum ; copy accumulated data Q
lds r17,Qaccum+1
lds r18,Qaccum+2
sts Qhold,r16
sts Qhold+1,r17
sts Qhold+2,r18
clr r16
sts Iaccum,r16 ; clear accumulators
sts Iaccum+1,r16
sts Iaccum+2,r16
sts Qaccum,r16
sts Qaccum+1,r16
sts Qaccum+2,r16
; It is now safe to allow the T2
sei ; interrupt to occur again
rcall Islow ; go do the slow routines
ret