ATtiny13 and some hacking…

Nikon D40 infrared remote DIY

Posted on December 20, 2009

For my images I use the Nikon D40, but never used the infrared remote function. After google'ing I found some websites on the subject. Here and here. Thanks to these great detailed websites I went to work to make my own Nikon ML-L3 remote control.

The code for getting the triggering to work took some time. The problem eventually was the wrong calculated timings by me. Fortunately, VMLAB showed me the mistakes and I got it working. There is also a short tutorial on VMLAB on this website.

The complete code is below. Note that this is only for the triggering part (no waiting on button or stuff like that) and repeats constantly.

Sorry for little commenting on the code, but those other websites already explain a lot. The code is written in Assembly, perhaps if I did it in C I finished it faster, but where is the fun in that. :P Maybe I'll post a C version later on.

You can also download a zipped version here, D40 IR Remote

; Hello - warning dutch
; Attempt for D40 IR Control

; 2000 us 	ON
; 27830 us 	OFF
; 390 us 	ON
; 1580 us	OFF
; 410 us	ON
; 3580 us 	OFF
; 400 us 	ON
; repeat after 63200 us (OFF)

; bij 9.6Mhz / 8 is 0,83333.... us per tik.

.include "tn13def.inc"

.def mp = r16
.def t1 = r17
.def t2 = r18
.def blinktime = r19

RJMP   	main

delay130:
nop
nop
nop
nop
nop
ret									; 4 tik + rcall 3

main:
	ldi   	mp,0b00001101
   	out   	DDRB,mp

loop:

;(Start pulse) 2000 us	ON
ldi blinktime,77      		; (13.0 uS * 2 ) * 77 = 2002 uS
startpulse1:
		LDI   mp,0x00    			; Led on
		OUT   PORTB,mp
rcall delay130  			; Wait 13 uS
		LDI   mp,0xFF     			; Led off
		OUT   PORTB,mp
rcall delay130  			; wait 13 uS

dec blinktime
brne startpulse1

;27830 us OFF
clr t1
ldi t2, 44
pauze1:
	dec t1
	brne pauze1
	dec t2
	brne pauze1

; 390 us 	ON
ldi blinktime,15
startpulse2:
		LDI   mp,0x00    			; Led on
		OUT   PORTB,mp
rcall delay130  			; Wait 13 uS
		LDI   mp,0xFF     			; Led off
		OUT   PORTB,mp
rcall delay130  			; wait 13 uS

dec blinktime
brne startpulse2

; 1580 us	OFF
clr t1
ldi t2, 3
pauze2:
	dec t1
	brne pauze2
	dec t2
	brne pauze2

; 410 us	ON
ldi blinktime,15
startpulse3:
		LDI   mp,0x00    			; Led on
		OUT   PORTB,mp
rcall delay130  			; Wait 13 uS
		LDI   mp,0xFF     			; Led off
		OUT   PORTB,mp
rcall delay130  			; wait 13 uS

dec blinktime
brne startpulse3

; 3580 us 	OFF
clr t1
ldi t2, 6
pauze3:
	dec t1
	brne pauze3
	dec t2
	brne pauze3

; 400 us 	ON
ldi blinktime,15
startpulse4:
		LDI   mp,0x00    			; Led on
		OUT   PORTB,mp
rcall delay130  			; Wait 13 uS
		LDI   mp,0xFF     			; Led off
		OUT   PORTB,mp
rcall delay130  			; wait 13 uS

dec blinktime
brne startpulse4

; repeat after 63200 us (OFF)
clr t1
ldi t2, 99
pauze4:
	dec t1
	brne pauze4
	dec t2
	brne pauze4

 rjmp loop
Comments (1) Trackbacks (0)
  1. Or you can run a lirc client (e.g., irreco), which has an ML-L3 definition. The Nokia N900 makes for a great IR remote this way.


Leave a comment


No trackbacks yet.