; ; To ensure correct timing the time constant of the RC-network must ; satisfie 512*(1/f)=-R*C*ln(1-2/5). ; For the A/D converter to operate properly, the capacitor must be ; completly discharged between each conversion. This is done by allowing ; the discharging to take a minimum of 200us. ; ; USES: ; AD_L = Low Results ; AD_H = Low ; AD_Sreg = Low Interrupt storage ; AD_Flag = Low conversion flags ; temp = High Scratch (extern) ; TCR_Ini = high Prescale(extern) ; ; 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 .equ AD_Done = 7 ; "Flags" - extern .equ AD_Err = 6 .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 ; ; Enable analog comp interrupt and set to trigger on rising edge ; .set ACSR_INIT= ACSR_INIT | (1<