PDA

View Full Version : Pentax IR Remote



peu
- 4th January 2011, 22:02
I want to make an infrared remote for the new pentax cameras for doing timelapses, as any timelapse shooter it involves triggering a IR sequence every X amount of time. The interval part is pretty straightforward, I want a little help regarding the IR sequence.

Here is the required pulse train:

http://img811.imageshack.us/img811/6074/pentaxprotocol.jpg

What would be the best way to send this thru a pic 12F683 pin? First I tought about using PWM or HPWM but these are limited to 32Khz

Thanks in advance!


Pablo

peu
- 5th January 2011, 02:26
This is what I got so far, I need to test it tomorrow with a camera, in simulation it looks OK, but I'm open to suggestions for improvement.

I need to code the operator input side of the program where the user selects with a pot the interval, now it just triggers once a second


'************************************************* ***************
'* Name : pentax.BAS *
'* Author : PEU based on examples from www.rentron.com *
'* Notice : Copyleft (c) 2011 *
'* : No Rights Reserved on derived work *
'* Date : 04-Jan-11 *
'* Version : 1.0 *
'* Notes : *
'************************************************* ***************
@ #define IRTX GPIO ; Define port to use for IR out
@ #define PIN 2 ; Define port pin to use for IR out
@ device pic12f683,INTRC_OSC_NOCLKOUT , wdt_on, mclr_off, protect_off


DEFINE OSC 4
GPIO.2 = 1 ' IR LED off -----|<|----/\/\/\----+5
TRISIO.2 = 0 ' Output for IR signal
CMCON0 = 7 ' Comparators disabled
ANSEL = 0 ' A/D disabled

' IR carrier generator routines. Freq.inc.

Cycles VAR BYTE ' Number of carrier cycles

PAUSE 100
GOTO OverFreq ' jump over pulse routines


' Generate "Cycles" number of ~38.4kHz pulses
ASM
_Pulse38
bcf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
goto $+1 ; + 2uS = 11uS
goto $+1 ; + 2uS = 13uS
bsf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
nop ; + 1uS = 10uS
decfsz _Cycles,f ; + 1uS = 11S
goto _Pulse38 ; + 2uS = 13uS
return ; Return to caller
ENDASM

OverFreq:

Main:

sleep 1 'sleep one second
gosub trigger 'send trigger pulse

GOTO Main

Trigger: 'generate pentax trigger pulse
Cycles = 255
CALL Pulse38
Cycles = 244
CALL Pulse38
pauseus 3000
cycles = 37
CALL Pulse38
pauseus 1000
cycles = 37
CALL Pulse38
pauseus 1000
cycles = 37
CALL Pulse38
pauseus 1000
cycles = 37
CALL Pulse38
pauseus 1000
cycles = 37
CALL Pulse38
pauseus 1000
cycles = 37
CALL Pulse38
pauseus 1000
cycles = 37
CALL Pulse38
pauseus 5000 'end of stream
return


END

fratello
- 5th January 2011, 08:46
Or You can try something like this :

@ device pic12F683, XT_OSC, wdt_off, pwrt_on, mclr_off, protect_off, bod_off
DEFINE OSC 4
INCLUDE "MODEDEFS.BAS"

GPIO = %00111011
TRISIO = %00111011 ' ATTENTION !!!
CCP1CON = %00001100 ' Mode select = PWM
T2CON = %00000100 ' Timer2 ON + 1:1 prescale
PR2 = %00011001 ' Set PWM frequency to 39kHz
ANSEL = %00000000
CMCON0 = %00000111

but1 var GPIO.0

; gpio.2 is CCPR1L
CCPR1L = 0

i var byte
'=========================================
main:
pause 100

if but1=1 then do_command


do_command:
CCPR1L=8
pauseus 1300
CCPR1L=0
pauseus 300
for i=1 to 7
CCPR1L=8
pauseus 100
CCPR1L=0
pauseus 100
next i

PAUSE 500

Goto Main

peu
- 5th January 2011, 16:56
The code I posted had the duty cycle inverted, just modified the assembly routine (swapped BSF & BCF) and it works, just tested it with my pentax Kx. Im happy :)

fratello: tested your code but it does not work, then I simulated it and the pulsetrain was very noisy maybe thats the cause.

Here is the modified code:


'************************************************* ***************
'* Name : pentax.BAS *
'* Author : PEU based on examples from www.rentron.com *
'* Notice : Copyleft (c) 2011 *
'* : No Rights Reserved on derived work *
'* Date : 04-Jan-11 *
'* Version : 1.0 *
'* Notes : pablou at gmail dot com *
'************************************************* ***************
@ #define IRTX GPIO ; Define port to use for IR out
@ #define PIN 2 ; Define port pin to use for IR out
@ device pic12f683,INTRC_OSC_NOCLKOUT , wdt_on, mclr_off, protect_off


DEFINE OSC 4
GPIO.2 = 1 ' IR LED off -----|<|----/\/\/\----+5
TRISIO.2 = 0 ' Output for IR signal
CMCON0 = 7 ' Comparators disabled
ANSEL = 0 ' A/D disabled

' IR carrier generator routines. Freq.inc.

Cycles VAR BYTE ' Number of carrier cycles

PAUSE 100
GOTO OverFreq ' jump over pulse routines


' Generate "Cycles" number of ~38.4kHz pulses
ASM
_Pulse38
bsf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
goto $+1 ; + 2uS = 11uS
goto $+1 ; + 2uS = 13uS
bcf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
nop ; + 1uS = 10uS
decfsz _Cycles,f ; + 1uS = 11S
goto _Pulse38 ; + 2uS = 13uS
return ; Return to caller
ENDASM

OverFreq:

Main:

sleep 1 'sleep one second
gosub trigger 'send trigger pulse

GOTO Main

Trigger: 'generate pentax trigger pulse
Cycles = 255
CALL Pulse38
Cycles = 244
CALL Pulse38
pauseus 3000
cycles = 37
CALL Pulse38
pauseus 1000
cycles = 37
CALL Pulse38
pauseus 1000
cycles = 37
CALL Pulse38
pauseus 1000
cycles = 37
CALL Pulse38
pauseus 1000
cycles = 37
CALL Pulse38
pauseus 1000
cycles = 37
CALL Pulse38
pauseus 1000
cycles = 37
CALL Pulse38
pauseus 5000 'end of stream
return


END

Bruce
- 5th January 2011, 18:56
Actually - it should work either way, but your last version will be leaving the IR LED ON if the cathode is connected to GPIO.2.

peu
- 5th January 2011, 19:47
Actually - it should work either way, but your last version will be leaving the IR LED ON if the cathode is connected to GPIO.2.

You are right, I left it again the way you coded it and it works the same :)

Thanks for the example BTW, without it I would be lost.
I finished the full timelapse+remote code but Im keeping it to myself at this moment, the code I posted and a little thinking will serve as the foundation to do any remote trigger operation with Pentax cameras.

Happy 2011 :)

Bruce
- 5th January 2011, 20:31
Glad I could help, but I would like to see you share what you have. Unless, of course, it's something you plan to sell as a product.

What goes around - comes around, and the folks you help along your way never seem to forget you..;)

peu
- 5th January 2011, 21:58
Bruce, you are right again.

After thinking about... lets say 2 minutes :) here is the code, I hope you and everyone else help me to make it better, there are a couple of things that can be improved for sure.

Good thing about it is that you change the pulse train and bingo timelapse remote for another brand, or even better, add a dipswitch and make the remote multibrand.


'************************************************* ***************
'* Name : pentax.BAS *
'* Author : PEU based on examples from www.rentron.com *
'* Notice : Copyleft (c) 2011 *
'* : No Rights Reserved on derived work *
'* Date : 05-ENE-11 *
'* Version : 1.02 *
'* Notes : pablou at gmail dot com *
'************************************************* ***************
@ #define IRTX GPIO ; Define port to use for IR out
@ #define PIN 2 ; Define port pin to use for IR out
@ device pic12f683,INTRC_OSC_NOCLKOUT , wdt_on, mclr_off, protect_on


DEFINE OSC 4
GPIO = 0
TRISIO.2 = 0 ' LED IR
TRISIO.1 = 0 ' LED testigo
TRISIO.5 = 1 ' Input para interruptor normal abierto (con pulldown)
CMCON0 = 7 ' Comparadores deshabilitados
ANSEL = 0 ' A/D deshabilitado
GIE VAR INTCON.7 ' Global interrupt enable 1=ON, 0=OFF
GPIE VAR INTCON.3 ' Port change interrupt enable 1=ON, 0=OFF
GPIF VAR INTCON.0 ' Port Change Interrupt Flag bit

Cycles VAR BYTE ' Number of carrier cycles
ContaSec var word ' Contador de segundos
TLFlag var byte ' Se programo el contador?
IRLED var GPIO.2 ' alias LED IR
LED var GPIO.1 ' alias LED testigo
BOTON var GPIO.5

GIE = 0 ' Disable global ints
GPIE = 1 ' Enable port change int
IOC.5 = 0 ' Int-on-change for GPIO.5 disbled
PAUSE 100 ' Pausita pa estabilizar todo al arranque
GOTO OverFreq ' jump over pulse routines


' Generate "Cycles" number of ~38.4kHz pulses Bruce at www.rentron.com
ASM
_Pulse38
bcf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
goto $+1 ; + 2uS = 11uS
goto $+1 ; + 2uS = 13uS
bsf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
nop ; + 1uS = 10uS
decfsz _Cycles,f ; + 1uS = 11S
goto _Pulse38 ; + 2uS = 13uS
return ; Return to caller
ENDASM

OverFreq:

contasec=0
tlflag=0

'Si el micro arranca con el boton apretado contar segundos
while boton=1
contasec = contasec + 1
high led
pause 50
low led
pause 950
tlflag=1
wend

contasec = contasec - 1 ' descontar un segundo, algun dia mejorare la rutina

'Loop del TimeLapse
if tlflag = 1 then

while boton = 0
sleep contasec ' dormir por el tiempo programado
gosub trigger ' disparar
high led ' prende LED testigo
pause 50 ' sisi agrega 50ms, no me calienta en lo mas minimo :)
low led ' apaga LED testigo
wend

' Se acabo el timelapse porque se apreto el boton
for contasec = 1 to 15 ' avisarle al usuario parpadeando el LED testigo
high led
pause 100
low led
pause 100
next

endif
IOC.5 = 1 ' Int-on-change for GPIO.5 enabled
GPIO = 0
Main: ' Loop principal
@sleep ' Dormir

while boton=0 ' Mientras no se aprete el boton no dejar pasar
wend
GPIF = 0 ' Clear port change interrupt flag
gosub trigger ' Disparar
high led ' prende LED testigo
pause 50
low led ' apaga LED testigo

GOTO Main

Trigger: ' Generar el pulso de disparo PENTAX
Cycles = 255
CALL Pulse38
Cycles = 239
CALL Pulse38
pauseus 3000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 5000 ' Fin del tren de pulsos PENTAX
return


END ' Fin



Sorry for spanish comments, google translate is your friend :)

http://img337.imageshack.us/img337/8316/pentaxremote.png


Pablo

peu
- 5th January 2011, 22:08
Nikon Protocol: http://www.sbprojects.com/projects/nikon/index.htm

Canon: http://www.doc-diy.net/photo/rc-1_hacked/

peu
- 5th January 2011, 23:06
add resistors for LED, not included in schematic (and neither in my protoboard :) ) and a transistor for more IR range, measured 387 microampere in the main loop while in sleep and 8mA while triggering, can it be made to consume even less in case the switch is left on?

peu
- 6th January 2011, 00:14
Current version instructions:

to enable timelapse function press pushbutton while powering ON the remote, the red led will flash each second passed, once you release the pushbutton this will be the interval time.

to exit the timelapse mode, just press the pushbutton longer than the intervall, once out of the mode the red led will flash briefly.

After exiting timelapse mode, if you press the pushbutton momentarily it will trigger once, if you keep it pressed it will trigger continuously.

if you start the remote without the pushbutton pressed it will work like previous paragraph.


While I was driving home I had an idea, why not add 2 more pushbuttons to easily have longer periods, one can be x10 seconds and the other minutes. And then, when outside the timelapse function these buttons can be programmed to trigger a certain amount of photos in a row, say for example 3 photos and 6 photos or any combination that can be programmed.

Bruce
- 6th January 2011, 05:18
Nifty project. Could even use a serial LCD and have a boat-load of options with a menu.

ardhuru
- 6th January 2011, 13:46
Hi,

Speaking of intervalometers, did you see the one at http://www.doc-diy.net/photo/hdr-jack/#thecircuit ?

It uses an atmel and is meant for a Canon, but the design is ingenious.

Or this: http://cms.diodenring.de/en/electronic/mikrocontroller/82-intervalltimerv2 ; based on 10F222, works with Canon, Nikon & the newer Pentaxs.

Planning to build one for my Canon 500D...

Regards,

Anand

peu
- 6th January 2011, 15:13
Hi,

Speaking of intervalometers, did you see the one at http://www.doc-diy.net/photo/hdr-jack/#thecircuit ?

It uses an atmel and is meant for a Canon, but the design is ingenious.

Or this: http://cms.diodenring.de/en/electronic/mikrocontroller/82-intervalltimerv2 ; based on 10F222, works with Canon, Nikon & the newer Pentaxs.

Planning to build one for my Canon 500D...

Regards,

Anand

I started with a Canon A570is and CHDK but wanted to use the DSLR for its many advantages, built the diodenring timelapse but my brand new pentax K-x does not have the 2.5mm jack as my previous pentax K-100, stupid me I realized this AFTER building it :) so the only choice left was to build it using the IR sensor. Crossed many mails with Achim (from diodenring) he is a helpfull guy.

Regarding the HDR-jack I think this can also be implemented via IR, but not looked into it yet.

Regarding the program in this thread, I know the timing loop at the begining can be improved using a better way to count time. I could use some help there :)


Pablo

ScaleRobotics
- 6th January 2011, 15:30
Regarding the program in this thread, I know the timing loop at the begining can be improved using a better way to count time. I could use some help there :)

Darrel has some great interrupt include files. It makes it pretty easy to do some great things with interrupts, and they can be very efficient as well. Here is a link to a timer example of his. http://darreltaylor.com/DT_INTS-14/elapsed.html

peu
- 6th January 2011, 16:53
interesting, never looked deeply into them, now that I did I have some warnings at compile time, maybe you can help me

PIC12F683
pbp 2.60b
latest mapsm from MPLAB IDE v8.63
Downloaded ReEnterPBP.bas and DT_INTS-14.bas from Darrel Site and placed at pbpw folder
And Im trying the example you linked (http://darreltaylor.com/DT_INTS-14/elapsed.html)
this example requires Elapsed_INT.bas which I found in this thread: http://www.picbasic.co.uk/forum/showthread.php?t=3251&p=17473#post17473 also placed it at pbpw folder. Is this the current version?


when I compile the example (using MPASM from microcodestudio) I get these errors:

Warning[219] C:\progra~1\picbas~1\pbppic14.lib 2934 : Invalid RAM location specified.
Warning[219] C:\progra~1\picbas~1\pbppic14.lib 2939 : Invalid RAM location specified.
Warning[219] C:\progra~1\picbas~1\pbppic14.lib 3059 : Invalid RAM location specified.
Warning[219] C:\progra~1\picbas~1\pbppic14.lib 3075 : Invalid RAM location specified.

What Im doing wrong?

peu
- 6th January 2011, 18:32
the problem was the LCDOUT, doh! :) back to learning this interesting interrupt stuff

peu
- 6th January 2011, 22:17
Added the timer as suggested and it works! BUT, now I lost two things and I don't know why:

1) the led thats supposed to flash once a second inside the time counting loop only flashes once.

2) When outside the timelapse function in the previous version if I left the button pressed the camera shooted continuously, now it shots one time per press

As a BONUS I translated all the comments to English :)


'************************************************* ***************
'* Name : pentax.BAS *
'* Author : PEU based on examples from www.rentron.com *
'* Notice : Copyleft (c) 2011 *
'* : No Rights Reserved on derived work *
'* Date : 05-ENE-11 *
'* Version : 1.01 *
'* Notes : pablou at gmail dot com *
'************************************************* ***************
@ #define IRTX GPIO ; Define port to use for IR out
@ #define PIN 2 ; Define port pin to use for IR out

' 12F683.INC at picbasic folder has this defined already for MPASM use
' __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_ON
'@ device pic12f683,INTRC_OSC_NOCLKOUT , wdt_on, mclr_off, protect_on


INCLUDE "DT_INTS-14.bas"
INCLUDE "ReEnterPBP.bas"
INCLUDE "Elapsed_INT.bas" ; Elapsed Timer Routines by Darrel Taylor

DEFINE OSC 4

GPIO = 0
TRISIO.2 = 0 ' LED IR
TRISIO.1 = 0 ' Red LED
TRISIO.5 = 1 ' Normal open pushbutton (w/ pulldown)
CMCON0 = 7 ' Comparators disabled
ANSEL = 0 ' A/D disabled
' GIE VAR INTCON.7 ' Global interrupt enable 1=ON, 0=OFF
GPIE VAR INTCON.3 ' Port change interrupt enable 1=ON, 0=OFF
GPIF VAR INTCON.0 ' Port Change Interrupt Flag bit

Cycles VAR BYTE ' Number of carrier cycles
ContaSec var word ' Seconds Counter
TLFlag var byte ' Timelapse counter programmed?
IRLED var GPIO.2 ' alias LED IR
LED var GPIO.1 ' alias red LED
BOTON var GPIO.5 ' pushbutton

GIE = 0 ' Disable global ints
GPIE = 1 ' Enable port change int
IOC.5 = 0 ' Int-on-change for GPIO.5 disbled
PAUSE 100 ' little pause to settle the processor after cold start


GOTO OverASM ' jump over ASM routines

' Generate "Cycles" number of ~38.4kHz pulses Bruce at www.rentron.com
ASM
_Pulse38
bcf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
goto $+1 ; + 2uS = 11uS
goto $+1 ; + 2uS = 13uS
bsf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
nop ; + 1uS = 10uS
decfsz _Cycles,f ; + 1uS = 11S
goto _Pulse38 ; + 2uS = 13uS
return ; Return to caller
ENDASM

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor

INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
ENDASM

OverASM: ' END of ASM routines

contasec=0
tlflag=0


' New timer
GOSUB ResetTime ' Reset Time to 0d-00:00:00.00
GOSUB StartTimer ' Start the Elapsed Timer

while boton = 1 ' Loops while the button is pressed
if SecondsChanged = 1 then 'if the seconds changed flash the red led
high led
pause 50
low led
SecondsChanged = 0 ' set flag back to 0
endif
tlflag=1 ' This flags lets me know if the timer was used
wend

contasec = Seconds + (Minutes * 60) ' Total time elapsed
gosub StopTimer

'Loop del TimeLapse
if tlflag = 1 then ' if the timer was used continue

while boton = 0
sleep contasec ' sleep programmed time
gosub trigger ' trigger
high led ' red LED on
pause 50 ' little pause
low led ' red LED off
wend

' Timelapse ended because the button was pushed
for contasec = 1 to 15 ' flash red LED to let the user know
high led
pause 100
low led
pause 100
next

endif
IOC.5 = 1 ' Int-on-change for GPIO.5 enabled
GPIO = 0
Main: ' main Loop

ASM
sleep ; Sleep
endasm

while boton=0 ' wait for button push
wend
GPIF = 0 ' Clear port change interrupt flag
gosub trigger ' trigger
high led ' red LED on
pause 50
low led ' red LED off
pause 200 ' debounce

GOTO Main

Trigger: ' PENTAX pulse train
Cycles = 255
CALL Pulse38
Cycles = 239
CALL Pulse38
pauseus 3000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 5000 ' end PENTAX pulse train
return


END ' Fin :)

peu
- 7th January 2011, 01:16
While debugging the firmware I took so many pictures that I decided to make a timelapse out of them :)

Enjoy in 1080p


http://www.youtube.com/watch?v=PtOaztPppgc

peu
- 7th January 2011, 16:30
Solved the trigger by holding button, ingenuity works :)
I still can't figure out why the led does not blink while counting time at the first while wend

And I noticed the ASM SLEEP does not work, consumption is the same (0.4mA) regardless I use it or comment it out. I replaced @ sleep with ASM SLEEP ENDASM to compile with MPASM do I need to add something else?

changed code:


'************************************************* ***************
'* Name : pentax.BAS *
'* Author : PEU based on examples from www.rentron.com *
'* Notice : Copyleft (c) 2011 *
'* : No Rights Reserved on derived work *
'* Date : 05-ENE-11 *
'* Version : 1.10 *
'* Notes : pablou at gmail dot com *
'************************************************* ***************
@ #define IRTX GPIO ; Define port to use for IR out
@ #define PIN 2 ; Define port pin to use for IR out

' 12F683.INC at picbasic folder has this defined already for MPASM use
' __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_ON
'@ device pic12f683,INTRC_OSC_NOCLKOUT , wdt_on, mclr_off, protect_on


INCLUDE "DT_INTS-14.bas"
INCLUDE "ReEnterPBP.bas"
INCLUDE "Elapsed_INT.bas" ; Elapsed Timer Routines by Darrel Taylor

DEFINE OSC 4

GPIO = 0
TRISIO.2 = 0 ' LED IR
TRISIO.1 = 0 ' Red LED
TRISIO.5 = 1 ' Normal open pushbutton (w/ pulldown)
CMCON0 = 7 ' Comparators disabled
ANSEL = 0 ' A/D disabled
' GIE VAR INTCON.7 ' Global interrupt enable 1=ON, 0=OFF
GPIE VAR INTCON.3 ' Port change interrupt enable 1=ON, 0=OFF
GPIF VAR INTCON.0 ' Port Change Interrupt Flag bit

Cycles VAR BYTE ' Number of carrier cycles
ContaSec var word ' Seconds Counter
TLFlag var byte ' Timelapse counter programmed?
IRLED var GPIO.2 ' alias LED IR
LED var GPIO.1 ' alias red LED
BOTON var GPIO.5 ' pushbutton

GIE = 0 ' Disable global ints
GPIE = 1 ' Enable port change int
IOC.5 = 0 ' Int-on-change for GPIO.5 disbled
PAUSE 100 ' little pause to settle the processor after cold start


GOTO OverASM ' jump over ASM routines

' Generate "Cycles" number of ~38.4kHz pulses Bruce at www.rentron.com
ASM
_Pulse38
bcf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
goto $+1 ; + 2uS = 11uS
goto $+1 ; + 2uS = 13uS
bsf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
nop ; + 1uS = 10uS
decfsz _Cycles,f ; + 1uS = 11S
goto _Pulse38 ; + 2uS = 13uS
return ; Return to caller
ENDASM

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor

INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
ENDASM

OverASM: ' END of ASM routines

contasec=0
tlflag=0


' New timer
GOSUB ResetTime ' Reset Time to 0d-00:00:00.00
GOSUB StartTimer ' Start the Elapsed Timer

while boton = 1 ' Loops while the button is pressed
if SecondsChanged = 1 then 'if the seconds changed flash the red led
high led
pause 50 'should blink once a second but it doesn't
low led
SecondsChanged = 0 ' set flag back to 0
endif
tlflag=1 ' This flags lets me know if the timer was used
wend

contasec = Seconds + (Minutes * 60) ' Total time elapsed
gosub StopTimer

'Loop del TimeLapse
if tlflag = 1 then ' if the timer was used continue

while boton = 0
sleep contasec ' sleep programmed time
gosub trigger ' trigger
high led ' red LED on
pause 50 ' little pause
low led ' red LED off
wend

' Timelapse ended because the button was pushed
for contasec = 1 to 15 ' flash red LED to let the user know
high led
pause 100
low led
pause 100
next

endif

IOC.5 = 1 ' Int-on-change for GPIO.5 enabled
GPIO = 0

Main: ' main Loop

ASM
SLEEP ; Sleep
endasm

while boton=0 ' wait for button push
wend

GPIF = 0 ' Clear port change interrupt flag

while boton=1 ' shoot while pressed
gosub trigger ' trigger
high led ' blink red LED
pause 50
low led
wend

GOTO Main

Trigger: ' PENTAX pulse train
Cycles = 255
CALL Pulse38
Cycles = 239
CALL Pulse38
pauseus 3000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 5000 ' end PENTAX pulse train
return


END ' Fin :)

peu
- 11th January 2011, 20:34
Here is version 2 of the PENTAX / NIKON IR remote, yes, I added Nikon support, needs to be tested with a Nikon camera as I don't have one.

Removed Darrel's Instant Interrupt elapsed timer because I was unable to make it work, also polished the code a little. As previous versions there is room for improvements, I hope someone else is interested in making it even better.

The device while sleeping uses only one microampere, so its suitable to be used with a button 3v 2032 battery.

You can add a second pushbutton but normally closed for power supply to briefly reset the remote to use it for timelapses again.[edit] or enable MCLR and use a normal pushbutton conecting pin 4 to GND and a 10k pull up resistor to VDD.

Attached is the HEX file for 12F683

http://img210.imageshack.us/img210/6144/remotei.jpg


'************************************************* ***************
'* Name : pentax.BAS *
'* Author : PEU based on examples from www.rentron.com *
'* Notice : Pablo E. Untroib (c) 2011 *
'* : No Rights Reserved on derived work *
'* : Free for personal use
'* Date : 11-ENE-11 *
'* Version : 2.10 *
'* Notes : pablou at gmail dot com *
'* : Consumption while sleeping is 1 microamper *
'************************************************* ***************
@ DEVICE PIC12F683,INTRC_OSC_NOCLKOUT,WDT_ON,MCLR_OFF,BOD_O FF,PWRT_OFF
@ #define IRTX GPIO ; Define port to use for IR out
@ #define PIN 2 ; IR LED output GND---/\/\/\---|<|--GPIO.2

define OSC 4 ' Defines oscilator frequency

'DEFINE DEBUG_REG GPIO ' used at debug time
'DEFINE DEBUG_BIT 4
'DEFINE DEBUG_BAUD 2400

GIE VAR INTCON.7 ' Global interrupt enable 1=ON, 0=OFF
GPIE VAR INTCON.3 ' Port change interrupt enable 1=ON, 0=OFF
GPIF VAR INTCON.0 ' Port Change Interrupt Flag bit
LED VAR GPIO.1 ' LED output GND---/\/\/\---|<|--GPIO.1
Cycles VAR BYTE ' Number of carrier cycles
ContaSec var word ' Seconds Counter
ContaMili var byte ' Miliseconds Counter
TLFlag var byte ' Timelapse counter programmed?
BOTON var GPIO.5 ' Key input (10K pull-UP w/switch to ground)

CMCON0 = 7 ' All digital
GPIO = 0 ' Clear port on boot
TRISIO = %00100000 ' GPIO.5 input, rest outputs
GIE = 0 ' Disable global ints

GOTO OverASM ' jump over ASM routines

' Generate "Cycles" number of ~38.4kHz pulses Bruce at www.rentron.com
ASM
_Pulse38
bcf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
goto $+1 ; + 2uS = 11uS
goto $+1 ; + 2uS = 13uS
bsf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
nop ; + 1uS = 10uS
decfsz _Cycles,f ; + 1uS = 11S
goto _Pulse38 ; + 2uS = 13uS
return ; Return to caller
ENDASM

OverASM: ' END of ASM routines

contasec = 0
ContaMili = 0
tlflag = 0

while boton = 0 ' Loops while the button is pressed
contamili = contamili + 1
pause 100
if contamili = 8 then ' I count 0 to 8 so I can flash the LED 100ms
contamili = 0
contasec=contasec + 1
high led
pause 100
low led
endif
tlflag=1 ' This flags lets me know if the timer was used
wend


' this is needed because the SLEEP takes about 2.3 seconds to react
' see SLEEP description in PBP manual
if contasec > 2 then
contasec = contasec - 2
endif

pause 1000 ' debounce pushbutton

'Loop del TimeLapse
if tlflag = 1 then ' if the timer was used continue

while boton = 1
sleep contasec ' sleep programmed time
gosub trigger ' trigger
high led ' red LED on
pause 50 ' little pause
low led ' red LED off
wend

WDTCON = 0 ' Disable WDT when not needed for power savings

' Timelapse ended because the button was pushed
for contasec = 1 to 5
high led ' flash red LED to let the user know timelapse ended
pause 100
low led
pause 100
next

endif

GPIE = 1 ' Enable port change int
IOC.5 = 1 ' Int-on-change for GPIO.5 enabled

' Main loop works as a normal remote,
' one push triggers, hold pushbutton triggers continuously
Main:

@ SLEEP ' SLEEP until Key is pressed

WHILE Boton = 0 ' Wait for Key release
gosub trigger
high led
pause 200
WEND
low led
GPIF = 0 ' Clear port change interrupt flag
GOTO Main

Trigger: ' PENTAX pulse train begins
Cycles = 255
CALL Pulse38
Cycles = 239
CALL Pulse38
pauseus 3000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 1000
cycles = 38
CALL Pulse38
pauseus 2000 ' end PENTAX pulse train with 2ms pause

Cycles = 76 ' NIKON pulse train begins
CALL Pulse38
pauseus 28000
cycles = 15
CALL Pulse38
pauseus 1580
cycles = 15
CALL Pulse38
pauseus 3580
cycles = 15
CALL Pulse38
pauseus 63200
Cycles = 76
CALL Pulse38
pauseus 28000
cycles = 15
CALL Pulse38
pauseus 1580
cycles = 15
CALL Pulse38
pauseus 3580
cycles = 15
CALL Pulse38
pauseus 2000 ' end NIKON pulse train with 2ms pause


return

END

Instructions:

to enable timelapse function press pushbutton while powering ON the remote, the red led will flash each second passed, once you release the pushbutton this will be the interval time.

to exit the timelapse mode, just press the pushbutton longer than the intervall, once out of the mode the red led will flash briefly.

After exiting timelapse mode, if you press the pushbutton momentarily it will trigger once, if you keep it pressed it will trigger continuously.

if you start the remote without the pushbutton pressed it will work like previous paragraph.

peu
- 13th January 2011, 20:12
Routing and Drilling the PCBs


http://www.youtube.com/watch?v=9oDjPjiNE9Q

mackrackit
- 13th January 2011, 21:29
Nice!!!! :D

BrianT
- 25th January 2011, 09:43
I did a similar camera control several years back. I used HPWM which will go to 38+KHz if you define the oscillator as one value then load a crystal of twice that value.

For example
DEFINE OSC 10 but in practice load a 20 MHz crystal.
HPWM 1, 127, 19400

That shags all your other timings so it can get tricky with other delays and serial in/out but it works for me.

HTH
BrianT