; ; A .01uF cap can be discharged in roughly 2.5 uS. by the 90S1200. ; This version is called periodically from the timer interrupt and does not ; use the analog interrupt. ; ; Hardware equates, constants, etc. ; .equ ADOUT = PORTB .equ ADIN = PINB .equ ADDDR = DDRB .equ REYE = PB3 ; Right Eye enable .equ LEYE = PB2 ; Left Eye enable .equ CAP = AIN0 ; Charge/discharge capacitor ;.equ CAP = PB4 ; Charge/discharge capacitor .macro Enable sbi ADDDR, @0 ; Set to output sbi ADOUT, @0 ; Drive LDR .endmacro .macro Disable cbi ADOUT, @0 ; Set low cbi ADDDR, @0 ; tri-state the LDR .endmacro .macro Discharge ; sbi ACSR, ACD ; power down comparator sbi ADDDR, CAP .endmacro .macro Measure ; cbi ACSR, ACD ; power up comparator (+ 1 ma) cbi ADDDR, CAP .endmacro ; ; NOTES: ; The initial state of this is messy. The capacitor will likely be charged ; a tad, plus the accumulators are zero so it will take a few cycles ; to have stable readings. ; .cseg ;************************************************************************** ; ; ADX_convert - Subroutine to start an A/D conversion ; ; Called periodically to initiate conversion. ; ; Periodic rate is 60 hz to try to negate effects of electrical ; lighting. ; ; NOTES: ; ; 1. Initial state is all flags cleared, accumulators cleared. ; 2. The high speed routine will do a "right" channel conversion first. ; 3. The first pass through will be "right". The second pass will ; be "left". When done with Left, set init to true to enable ; accumulation (filtering) ; 4. High speed routine triggers off of "AD_Done" being reset ; 5. AD_Ovr is not used at this time. ; 6. 'T' bit is used to determine Left/Rightness of pass. ; 7. Accumulation starts from Zero, so need to wait a bit for ; the results to level out. Also, the capacitor won't be discharged ; for the first pass, so wait 1 sec (30 conversions) for steady state. ; AD_Conv: bst Flags, AD_Left ; // Store direction in 'T' brtc AD_01 ; If (ADLeft == TRUE) { add Left_eye, AD_Results ; AD_Left += AD_Results ror Left_eye ; AD_Left = AD_Left/2 Enable REYE ; Enable(REYE) cbr Flags, (1<