One of my
friends wanted a microcontroller to send commands to a digital
camera. There are lots of such projects on the web and there is even
more cheap Chinese remote controllers but no remote does exactly what
my buddy needed. He already had a hardware which I mentioned in
previous post and a regular remote controller for his Olympus
camera. First of all we had to generate 36KHz carrier frequency, we
did it using Timer1 in CTC mode:
PORTB &= ~(1<<1); //there is 0 on pin when OC1A is disabled
DDRB |= (1<<1); //OC1A pin works as output
TCCR1B |= (1<<WGM12) | (1<<CS10); //CTC mode and clock source selection
TCNT1 = 0; //clear timer register
OCR1A = 14; //1MHz/(2*36KHz) ~ 14
//TCCR1A |= (1<<COM1A0); //enables OC1A output
Then we had to
key carrier frequency with data which will convince camera to take a
picture. Information sources we used were lirc drivers www.lirc.org
and signals received from regular controller. Every bit consists from
two consecutive states zero and one, meaning of a bit is encoded in
length of the second state. This way transmission is immune against
clock desynchronization. Data transmitted
by remote controller which we reverse-engineered looks like this:
It turned out
that camera needs only that marked with red box part of a signal.
Rest of transmission is redundant in case of that specific camera. Setting and
clearing COMA10 bit controls whether carrier frequency is supplied to
IR LED or not, we wrote simple preprocessor directives:
#define HEADER TCCR1A |= (1 << COM1A0); _delay_us(8853); TCCR1A &= ~(1 << COM1A0); _delay_us(4489);
#define ONE TCCR1A |= (1 << COM1A0); _delay_us(559); TCCR1A &= ~(1 << COM1A0); _delay_us(1670);
#define ZERO TCCR1A |= (1 << COM1A0); _delay_us(559); TCCR1A &= ~(1 << COM1A0); _delay_us(555);
And function
sends a “take a picture” command to camera:
HEADER;
ZERO;ONE;ONE;ZERO;ZERO;ZERO;ZERO;ONE;ONE;ONE;ZERO;ONE;ONE;ONE;ZERO;ZERO;ONE;ZERO;ZERO;ZERO;ZERO;ZERO;ZERO;ZERO;ZERO;ONE;ONE;ONE;ONE;ONE;ONE;ONE;ONE;
Now when we knew
that it works we'll clean up this code to make it non-blocking, neat
and easy to read and maintain. The most important thing is that
controlling digital camera is not_so_difficult_as_you_thought.
No comments:
Post a Comment