PDA

View Full Version : Camera Flash Trigger showing assembly Interrupts within PBP



BobP
- 7th February 2009, 15:51
Hello All,

This is a program to control a camera slave flash.
Triggered from the cameras own inbuilt flash.

The program is very small demonstrating the use of assembly interrupts in PicBasic Pro.
This program uses Interrupt On Change on a single bit of the GPIO port.


'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : Bob Simpson *
'* Notice : Copyright (c) 2009 Bob Simpson *
'* : All Rights Reserved *
'* Date : 07/02/2009 *
'* Version : 1.03 *
'* Notes : *
'* : *
'************************************************* ***************

'
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''
' PIC Defines
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''
'
@ DEVICE pic12F683, INTRC_OSC_NOCLKOUT
' System Clock Options
@ DEVICE pic12F683, WDT_Off
' Watchdog Timer
@ DEVICE pic12F683, PWRT_ON
' Power-On Timer
@ DEVICE pic12F683, BOD_OFF
' Brown-Out Detect
@ DEVICE pic12F683, MCLR_OFF
' MCLR external ON for enabled
@ DEVICE pic12F683, IESO_ON
' Internal osc start-up
@ DEVICE pic12F683, FCMEN_OFF
' OSC fail detect Detect
@ DEVICE pic12F683, CPD_OFF
' Data Memory Code Protect
@ DEVICE pic12F683, PROTECT_OFF
' Program Code Protection

DEFINE OSC 8 ' PIC will run at 8Mhz so tell PBP
DEFINE INTHAND intcamera ' Tell PBP that there is an interrupt routine

'
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''
' Port Setup
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''
'
INTCON = 0 ' Disable the global interrupt
OSCCON=%01110001 ' Internal 8 Mhz clock
ANSEL=0 ' All Port A is Digital
CMCON0=%0000111 ' Comparators off
VRCON.7=0 ' Power down comparators
CMCON0=7 ' Power down voltage Ref
TRISIO=%111000 ' GPIO bit 0,1 and 2 are outputs rest inputs
WPU=%010000 ' Pull-up for GPIO.4 selected
OPTION_REG.7=0 ' Enable internal pull-ups
IOC =%010000 ' Interrupt on change selected for GPIO.4

'
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''
' Variables and Names Setup
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''
'
wsave VAR BYTE bank0 system ' Saves W
ssave VAR BYTE bank0 system ' Saves STATUS
psave VAR BYTE bank0 system
TRIG VAR BYTE bank0 ' Not used yet
B1 var BYTE ' Temp store
FTrig VAR GPIO.4 ' Input from LED
LCAMERA VAR GPIO.1 ' Output to low voltage trigger
HCAMERA VAR GPIO.0 ' Output to High voltage trigger

CLEAR ' Clear all variables
GoTo mainloop ' jump over the interrupt handler

'
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''
' Interrupt Routine
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''
'
Asm
intcamera
; Save W, STATUS and PCLATH registers
movwf wsave
swapf STATUS,W
clrf STATUS
movwf ssave
movf PCLATH,W
movwf psave

; Trigger Camera output on flash ip
bsf _LCAMERA ; Set output to 1
bsf _HCAMERA ; Set output to 1
clrf _TRIG ; Clear tick store (For future changes. Not used yet)
MOVF GPIO,W ; Read Port to clear IOC flag
bcf INTCON, GIE ; Clear Global interrupt flag in INTCON register
bcf INTCON, GPIE ; Clear port change interrupt enable flag in INTCON register
bcf INTCON, GPIF ; Clear interrupt flag in INTCON register

endint
; Restore PCLATH, STATUS and W registers
movf psave,W
movwf PCLATH
swapf ssave,W
movwf STATUS
swapf wsave,F
swapf wsave,W
retfie

EndAsm

'
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''
' Main Program Starts Here
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''
'
MainLoop:
INTCON=0 ' Disable all interrupts and PortA IOC
LCAMERA=0
HCAMERA=0
B1=GPIO ' Read port to ensure no setting of IOC flag
INTCON =%10001000 ' Enable the RA port change interrupt
NAP 5 ' Sleep till portA change. Watchdog switched off
PAUSEUS 4 ' Give everything time to settle down

FlashTriggered:
INTCON =0 ' Disable interrupts.
pause 500 ' Wait 1/2 second with outputs switched on. Remember outputs have been switched on in the assembler interrupt routine
LCAMERA=0
HCAMERA=0 ' Now switch both outputs off
GOTO MainLoop

END

I am no PicBasic Pro Guru, that mantel is firmly in the hands of others.
But the program is very small with frequent comments and hopefully there are no major mistakes?
Also attached is a zip file contains the information to make a Slave Flash Trigger.

The flash unit has performed over the past 2 weeks with no problems.

Regards,
Bob

b1arrk5
- 7th February 2009, 19:43
Very nice Bob! I've got a few 'peanut' slaves in my bag and they are handy, but I think I'll have to build one of yours to play with. I like the idea of being able to trip two flashes simultaneously, without needing two slaves.
If you want to see pricey accessories, check out the Pocket Wizards. They are professional level radio slaves, and will take a big bite out of your wallet.

Thanks for sharing this,

Jerry.

grounded
- 8th February 2009, 06:10
nice job BobP
I built some of these back a few years ago for my game camera
lot cheaper that store bought stuff
thanks for sharing
cheers