-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphotoshutter.c
214 lines (184 loc) · 4.57 KB
/
photoshutter.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*****************************************************
Universal autoshutter for digital cameras
26.02.2018 - 20.08.2022 by https://github.com/minch-yoda/
ATtiny2313 8 MHz
*****************************************************/
#include <tiny2313.h>
#include <delay.h>
//#include <stdio.h>
//#include <stdlib.h>
const int x0 = 24;
const int x1 = 48;
const int x2 = 96;
int U = 0;
int BASE = 0;
int TIMEOUT = 0;
int RELAY = 1;
int CMD = 1;
//1s/40kHz=25us total (6+19) pulse (microseconds)
//600us/25us=24 cycles
void pulse(int cycles){
int c = 0;
while(c<cycles){
c++;
PORTA.0 = 0; //ON reversed because we use transistor
delay_us(6);
PORTA.0 = 1; //OFF
delay_us(19);
}
delay_us(600);
}
//1800us*4 + 1200us*3 +3000 = 7200+3600 +3000 = 13800us = 13.8ms
void shutter(){
pulse(x2); //3000us
pulse(x1); //1800us
pulse(x0); //1200us
pulse(x1); //1800us
pulse(x1);
pulse(x0);
pulse(x1);
pulse(x0);
}
//1800us*5 + 1200us*2 +3000 = 9000+2400+3000 = 14400us = 14.4ms
void shutter2sec(){
pulse(x2); //3000us
pulse(x1);
pulse(x1);
pulse(x1);
pulse(x0);
pulse(x1);
pulse(x1);
pulse(x0);
}
//1800us*2 + 1200us*5 +3000 = 3600+6000+3000 = 12600us = 12.6ms
void video(){
pulse(x2); //3000us
pulse(x0);
pulse(x0);
pulse(x0);
pulse(x1);
pulse(x0);
pulse(x0);
pulse(x1);
}
//1800us*8 + 1200us*5 = 14400+6000 = 20400us = 20.4ms
void address(){
pulse(x0);
pulse(x1);
pulse(x0);
pulse(x1);
pulse(x1);
pulse(x1);
pulse(x0);
pulse(x0);
pulse(x0);
pulse(x1);
pulse(x1);
pulse(x1);
pulse(x1);
}
void main(void)
{
// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
//DDRx 0 - input pin
//PORTxn 1 - pull-up enabled
//DDRx 1 - output pin
// Port A
//Should be high for out
//VOID RESET FREE RELAY
DDRA =0b0001;
PORTA=0b0011;
// Port B
//All input
//high by default, low when shorted
//30 20 10 5 4 3 2 1
DDRB=0b00000000;
PORTB=0b11111111;
// Port D
//All input
//VOID RELAY_ON +0.5 +0.25 day hour min sec
DDRD=0b00000000;
PORTD=0b11111111;
delay_ms(100);
//0 means pin is shorted (ON) so we check for false value
if(!PIND.0){BASE = 1000;} //seconds
if(!PIND.1){BASE = 60000;} //minutes 60*1000
if(!PIND.2){BASE = 3600000;} //hours 60*60*1000
if(!PIND.3){BASE = 86400000;} //days 24*60*60*1000
if(!PINB.0){U += 1;}
if(!PINB.1){U += 2;}
if(!PINB.2){U += 3;}
if(!PINB.3){U += 4;}
if(!PINB.4){U += 5;}
if(!PINB.5){U += 10;}
if(!PINB.6){U += 20;}
if(!PINB.7){U += 30;}
TIMEOUT = (BASE * U);
if(!PIND.4){TIMEOUT += BASE/4;} //+0.25
if(!PIND.5){TIMEOUT += BASE/2;} //+0.5
if(!PINA.1){CMD = 2;} //shutter 2 sec (Nex5 native command)
if(!PIND.6){CMD = 3;} //video
if(!PINA.1 && !PIND.6){CMD = 4;} //shutter once in x sec
if(TIMEOUT>=100){ //we don't want UINT_MAX
TIMEOUT -= 100; //time buffer to make IR commands execution time identical
}
if(RELAY && CMD!=4 && TIMEOUT>=200){ //we don't want UINT_MAX, also we don't need to subtract in "shutter once in x sec" mode
TIMEOUT -= 200; //accounting for relay interval
}
while(1){
//Sony IR start
switch(CMD){
case 1: //shutter
shutter();
address();
delay_ms(11);
shutter();
address();
delay_ms(20.6); //100 - 79.4
break;
case 2: //shutter 2 sec
shutter2sec();
address();
delay_ms(11);
shutter2sec();
address();
delay_ms(19.4); //100 - 80.6
break;
case 3: //video
video();
address();
delay_ms(11);
video();
address();
delay_ms(23); //100 - 77
break;
case 4: //shutter once in x sec
delay_ms(TIMEOUT);
shutter();
address();
delay_ms(11);
shutter();
address();
delay_ms(20.6); //100 - 79.4
break;
default: break;
}
if(RELAY){
//relay
PORTA.0 = 0; //ON
delay_ms(200);
PORTA.0 = 1; //OFF
}
if(CMD!=4 && TIMEOUT){
delay_ms(TIMEOUT);
} else {
break; //fire only this time if no timeout is set or the cmd is "shutter once in x sec"
}
}
};