;************************************************************************ ;Lizenz****************************************************************** ; ; Autor: Achim Sack, diodenring.de ; Datum: 19.10.2009 ; Version: 2.4 ; ;Mit der Verwendung der hiermit bereitgestellten Software erkennen sie ;folgenden Lizenzvertrag an: ; ; Creative Commons ; Namensnennung-Keine kommerzielle Nutzung ; Weitergabe unter gleichen Bedingungen 3.0 Deutschland ; ;Es ist Ihnen gestattet: ; - das Werk vervielfältigen, verbreiten und öffentlich zugänglich ; machen ; - Abwandlungen bzw. Bearbeitungen des Inhaltes anfertigen ; ;Zu den folgenden Bedingungen: ; - Namensnennung. Sie müssen den Namen des Autors/Rechteinhabers ; in der von ihm festgelegten Weise nennen ; - Keine kommerzielle Nutzung. Dieses Werk darf nicht für ; kommerzielle Zwecke verwendet werden. ; - Weitergabe unter gleichen Bedingungen. Wenn Sie den ; lizenzierten Inhalt bearbeiten oder in anderer Weise ; umgestalten, verändern oder als Grundlage für einen anderen ; Inhalt verwenden, dürfen Sie den neu entstandenen Inhalt nur ; unter Verwendung von Lizenzbedingungen weitergeben, die mit ; denen dieses Lizenzvertrages identisch oder vergleichbar sind. ; ;************************************************************************ ;Standard header********************************************************* ;Configurationword******************************************************* include p10F204.inc __CONFIG _MCLRE_OFF & _CP_OFF & _WDT_ON ;0xFFC ;Intosc 4MHz, WDT, MCLR pullup, MCLR on #define MM_PERSIST_TIME .5 ;[18ms] ;The time a mismatch of the focus ;line must persist to cause a reset ;************************************************************************ ;Variablen*************************************************************** cblock 0x10 ;Note: 0x10 is the first free (implemented) GPR RAM ;on some PIC10F2xx sleep_counter:.0, sleep_counter_L, sleep_counter_H frame_intervall:.0, frame_intervall_L, frame_intervall_H mismatch_counter, focus_timeout GPIO_ ;I/O Buffer TRIS_ ;TRIS Buffer FLAGS endc ;Deklarationen*********************************************************** #define Line1 .1 ; #define Line2 .2 ; #define PGD GPIO,1 ; #define PGC GPIO,0 ; #define RESET_ GPIO,3 ; #define PORT_MISMATCH FLAGS,0 ;Set, if the mismatch routine has detected a mismatch #define MISMATCH_DETECT_EN FLAGS,1 ;set this bit to enable updating of the PORT_MISMATCH bit #define WDT_Timeout_expected FLAGS,2 ;Set, if the program expects a reset due to WDT timeout #define Line1_is_focus FLAGS,3 ;if set, the meaning of the focus and shutter line is swapped ;Resetvector************************************************************* ;Initialisierung********************************************************* org 0x0000 MINIMAL_INIT movwf OSCCAL ;Calibration value for OSCCAL bcf OSCCAL,0 ;No Clockout #IFDEF __10F222 clrf ADCON0 ;No analog inputs (this byte is reset on ANY reset! #ENDIF DETECT_RESET_SOURCE btfsc STATUS, NOT_TO ;If WDT timeout goto INIT_1st_TIME ;WDT caused not the reset btfss WDT_Timeout_expected ;and this was expected to happen goto INIT ; CONTINUE_SLEEP movf TRIS_,W ;Reinit PORTs andlw b'1110' ; movwf TRIS_ ;save to buffer TRIS GPIO ;cleared on reset, too, gp0 always out movlw b'11001000' ; OPTION ;No pullups, no wake on pin change, Presc on WDT ;Finish sleep routine bcf WDT_Timeout_expected ; call DETECT_PORT_MISMATCH ;detect a port mismatch movlw .1 ;update counter subwf sleep_counter_L,f ; btfss STATUS, C ; subwf sleep_counter_H,f ; movf sleep_counter_L,f ;test, if device should sleep again: btfss STATUS, Z ;sleep if sleep_counter != 0 goto sleep_again ; != 0 movf sleep_counter_H,f ; btfss STATUS, Z ; goto sleep_again ; != 0 retlw .0 ; ==0 resume normal operation on the location before from where the sleep was requested sleep_again ;sleep again bsf WDT_Timeout_expected ;signal intended WDT timeout movf GPIO,W ;Update port latch sleep ;Send device to sleep INIT_1st_TIME call sleep_16WDT ;wait additional time to let Vdd stabilize INIT movlw 0x09 ;clear all GPR from 0x09 - 0x1F movwf FSR ; CLEAR_MEM clrf INDF ; incf FSR,f ; movf FSR,W ; andlw 0x1F ; btfss STATUS, Z ; goto CLEAR_MEM ; #IFDEF __10F204 movlw b'01110001' ;No comparator movwf CMCON0 #ENDIF #IFDEF __10F222 clrf ADCON0 ;No analog inputs #ENDIF clrf GPIO ;Bank 0 Default Pin state clrf GPIO_ ;clear buffer movlw b'1110' ; movwf TRIS_ ;save to buffer TRIS GPIO ;Set Pin direction: GP1/2 in, GP0 out movlw b'11001000' ; OPTION ;No pullups, wake on pin change, Presc on WDT INIT_SW clrf frame_intervall_L ;Init frame intervall clrf frame_intervall_H ; call sleep_16WDT ;16*18ms INIT_END call Focus_HIGH goto MAIN ;Hauptprogramm ********************************************************** MAIN ; movlw b'0000' ; ; movwf TRIS_ ;save to buffer ; TRIS GPIO ;Set Pin direction: GP1/2 in, GP0 out ; bsf GPIO,1 ; bcf GPIO,1 ;*************** ;*************** Sample_period_step__1 ;wait until both lines are released call sleep_18ms ; btfss GPIO, Line1 ; goto Sample_period_step__1 ; btfss GPIO, Line2 ; goto Sample_period_step__1 ; ;*************** ;*************** Sample_period_step_0 clrf frame_intervall_L ;Init frame intervall clrf frame_intervall_H ; call sleep_18ms ;wait until one line is 0 but the other one is high btfss GPIO, Line1 ;this one (0) is the focus line goto Sample_period_step_0A btfss GPIO, Line2 goto Sample_period_step_0B goto Sample_period_step_0 Sample_period_step_0A ;Detected, that Line1 is low btfss GPIO, Line2 ;test if Line2 is still high goto Sample_period_step__1 bsf Line1_is_focus ;Detected, that Line1 is focus goto Sample_period_step_1 Sample_period_step_0B ;Detected, that Line2 is low btfss GPIO, Line1 ;test if Line1 is still high goto Sample_period_step__1 bcf Line1_is_focus ;Detected, that Line2 is focus goto Sample_period_step_1 ;*************** ;*************** Sample_period_step_1 call sleep_18ms ;wait until other line is 0, too btfss Line1_is_focus goto Sample_period_step_1b Sample_period_step_1a btfsc GPIO, Line1 goto Sample_period_step_0 btfsc GPIO, Line2 goto Sample_period_step_1 goto Sample_period_step_2 Sample_period_step_1b btfsc GPIO, Line2 goto Sample_period_step_0 btfsc GPIO, Line1 goto Sample_period_step_1 goto Sample_period_step_2 ;*************** ;*************** Sample_period_step_2 ;wait until both lines are released and measure the time call sleep_18ms ; incf frame_intervall_L,f ;inc counter btfsc STATUS, Z ; incf frame_intervall_H,f ; ; btfss GPIO, Line1 ; goto Sample_period_step_2 ; btfss GPIO, Line2 ; goto Sample_period_step_2 ; ;*************** ;*************** Sample_period_step_3a ;wait until focus is pressed again and continue to measure the time movlw .5 ;Focus line has to stay low for a certain period to be valid movwf focus_timeout ;set timeout Sample_period_step_3a_loop ; call sleep_18ms ; incf frame_intervall_L,f ;inc counter btfsc STATUS, Z ; incf frame_intervall_H,f ; btfsc STATUS, Z ;test for overflow (>65535) sleep ;if overflow reset using the WDT: Wait until timeout ; btfss Line1_is_focus ;test for Focus to be low goto Sample_step_3a_L1 ; ; btfsc GPIO, Line1 ; goto Sample_period_step_3a ; goto Sample_step_3a_L2 ; Sample_step_3a_L1 btfsc GPIO, Line2 ; goto Sample_period_step_3a ; goto Sample_step_3a_L2 ; Sample_step_3a_L2 decfsz focus_timeout,f ; goto Sample_period_step_3a_loop; Sample_period_step_3b ;wait until shutter is pressed again and continue to measure the time call sleep_18ms ;if Focus is released, then reset incf frame_intervall_L,f ;inc counter btfsc STATUS, Z ; incf frame_intervall_H,f ; btfsc STATUS, Z ;test for overflow (>65535) sleep ;if overflow reset using the WDT: Wait until timeout btfss Line1_is_focus ;test for Focus to be low goto Sample_step_3b_L2 ; btfsc GPIO, Line1 ; sleep ;focus line high again: reset using timeout btfsc GPIO, Line2 ; goto Sample_period_step_3b ; goto Sample_period_step_4 ; Sample_step_3b_L2 ; btfsc GPIO, Line2 ; sleep ;focus line high again: reset using timeout btfsc GPIO, Line1 ; goto Sample_period_step_3b ; goto Sample_period_step_4 ; ;*************** ;*************** Sample_period_step_4 ;wait for release of both lines call sleep_18ms ; ; btfss GPIO, Line1 ; goto Sample_period_step_4 ; btfss GPIO, Line2 ; goto Sample_period_step_4 ; ;*************** ;*************** Sample_period_step_5 ;cancel overhead due to shutter release ;if (frame_intervall >= 26) then (frame_intervall = frame_intervall-20) else frame_intervall = 5 movf frame_intervall_H,f ; btfss STATUS, Z ;High Byte == 0? goto Sample_period_step_5_adjust ; movlw .20+.5+.1 ; subwf frame_intervall_L,W ; btfsc STATUS, C ; goto Sample_period_step_5_adjust ; movlw .5 ; movwf frame_intervall_L ; goto Sample_period_end ; ; Sample_period_step_5_adjust ; movlw .20 ; subwf frame_intervall_L,f ; btfss STATUS, C ; decf frame_intervall_H,f ; Sample_period_end call Focus_HIGH MAIN_loop ; bsf MISMATCH_DETECT_EN ;enable mismatch actualisation call sleep_frametime ; bcf MISMATCH_DETECT_EN ;disable mismatch actualisation during actual exposure Take_a_picture call Focus_LOW ;Low on Focus line call sleep_16WDT ; call Shutter_LOW ;Low on Shutter line call sleep_4WDT ;sleep call Focus_HIGH ;releases both lines goto MAIN_loop ; ;************************************************************************ ;************************************************************************ Focus_LOW ;make Focus line low btfss Line1_is_focus goto $+.4 bcf GPIO_, Line1 ;clear PORT Bit bcf TRIS_, Line1 ;Focus: output goto $+.3 bcf GPIO_, Line2 bcf TRIS_, Line2 movf TRIS_,W ; TRIS GPIO ; retlw .0 ;************************************************************************ Focus_HIGH ;make focus and shutter line high bsf GPIO_, Line1 ;set PORT Bit bsf GPIO_, Line2 ;set PORT Bit bsf TRIS_, Line1 ;Focus: input bsf TRIS_, Line2 ;Shutter: input movf TRIS_,W ; TRIS GPIO ; retlw .0 ;************************************************************************ Shutter_LOW ;make focus and shutter line low bcf GPIO_, Line1 ;clear PORT Bit bcf GPIO_, Line2 ;clear PORT Bit bcf TRIS_, Line1 ;Focus: output bcf TRIS_, Line2 ;Shutter: output movf TRIS_,W ; TRIS GPIO ; retlw .0 ;************************************************************************ DETECT_PORT_MISMATCH ;detect if a PORT should be high, but is driven low externally btfss MISMATCH_DETECT_EN ;if detection is enabled: evaluate ports (else: do not update MM flag) goto DETECT_PORT_MM_NO_MM ;Asume: No mismatch, reset counter, etc. movf GPIO, W ; xorwf GPIO_, W ;bit is set, if mismatch andwf TRIS_,W ;Mask inputs only btfss Line1_is_focus goto $+.3 andlw .1< 0x1F) error "Some variables are located outside the valid adress range" endif end ;Revision history ; ;30.06.10 ver 2.4 ; fixed: Corrected the mismatch detection to be also active during ; the training period. Mismatch timeout reduced to ~100ms. ; ; ;10.06.10 ver 2.4 alpha ; by request: ; changed added an intervall counter to specify a certain minimal time ; the Port-missmatch must persist, before it causes a reset: ; Pentax cameras seem to pull the Focus line down about 2 sec ; after exposure for most likely 10-300ms. This will be skipped now. ; ; ;06.06.10 ver 2.3a ; changed disable clockout by clearing OSCCON, 0 ; ; ;05.11.09 ver 2.3 ; changed TRIS settings after a mismatch detected in DETECT_PORT_MISMATCH ; minor code changes ; ;03.11.09 ver 2.3 ; changed Focus and Shutter line are now mapped to GPIO1, GPIO2 ; added device "learns" which line is shutter, and which is focus ; added if during learning phase (step3) Focus goes low and high ; again, but Shutter does not, then reset the device ; => can abort the learning phase ; => device is always in the start condition (step -1) if ; the button if the camera is only tapped ; ;03.11.09 Begin revision history