- Mon Aug 17, 2009 12:31 pm
#79011
Hi,
I am trying to replicate an infrared trigger for a Nikon dslr as described here.
It basically seems to consist of switching an IR led with these timings.
I cannot for the life of me get my code to work. It definitely does something as evidenced by a red LED I tried but it won't trigger. Was hoping somebody might have a trawl through my code as i've gone through it over and over and can't see anything wrong.
Here is the code i've got. I'm very new to C and avr's so i'm unaware of bad practices right now.
I am trying to replicate an infrared trigger for a Nikon dslr as described here.
It basically seems to consist of switching an IR led with these timings.
Code: Select all
Once it's done that it repeats once more after 63ms. Additionally, for an ON state the IR has to cycled at ~40Khz.ON off ON off ON off ON off
2250us 27600us 650us 1375us 575us 3350us 650us
I cannot for the life of me get my code to work. It definitely does something as evidenced by a red LED I tried but it won't trigger. Was hoping somebody might have a trawl through my code as i've gone through it over and over and can't see anything wrong.
Here is the code i've got. I'm very new to C and avr's so i'm unaware of bad practices right now.
Code: Select all
For reference this is an atmega168 (Arduino) and I have a PIC programmed with the hexfile at the aforementioned website which triggers the camera fine.// mll3 infrared transmitter
// have a feeling util/delay requires timer0 with no prescale
// making do without it
#include <avr/io.h>
#include <avr/interrupt.h>
// setting up a 1MHz clock signal for creating counters
void realtimeclock_setup() {
TCCR0A |= (1<<WGM01);
TCCR0B |= (1<<CS01); // 0.5us or 2Mhz
OCR0A = 0x01; // a 1MHz signal
TIMSK0 |= (1<<OCIE0A);
}
volatile uint16_t clk1, clk2;
// what to do on the TIMER0 compares
SIGNAL(SIG_OUTPUT_COMPARE0A) {
clk1++;
clk2++; // meh
}
// the util/delay.h seems to be massively
// wrong if I create a timer
int delay_us(uint16_t val) {
clk1 = 0;
while ( clk1 < val ){
}
return 0;
}
// creates a 38.5KHz signal for
// a specified duration val (us)
int gensig (uint16_t val) {
clk2 = 0;
while ( clk2 < val ) {
PORTB ^= 0x04;
delay_us(13);
}
return 0;
}
// when the button is pressed perform the trigger signal
int snap(void) {
int i = 0;
// has to do this twice
while ( i <= 1 ) {
gensig(2250); // # of 2250 cycles in 2000us @ 1MHz
PORTB &= ~0x04;
delay_us(27600);
gensig(650); // # 650 of cycles in 650us
PORTB &= ~0x04;
delay_us(1375);
gensig(575); // # 575 of cycles in 575us
PORTB &= ~0x04;
delay_us(3350);
gensig(650); // # 650 of cycles in 650us
PORTB &= ~0x04;
i++;
delay_us(63000); // 63ms
}
return 0;
}
int main (void){
realtimeclock_setup();
DDRB |= 0x04; // an LED
DDRD &= 0xFB;
PORTD |= 0x04; //enable pullup
sei();
while (1) {
if ( PIND & 0x04 )
PORTB &= ~0x04;
else
snap(); // perform trigger signal
}
return 0;
}