' Macro focus rail driver
' Unipolar stepper (12V 1.8deg) connected to ULN2003A:
' green, white, red, brown -> Out1-Out4
' 08m 2 -> ULN In2
' 08m 1 -> ULN In3
' Out4 -> optocoupler for shutter triggering (tip+, sleave-)
' IR detector codes:
' CH+ back focus
' CH- front focus
' NN steps in one slide (in 0.01mm)
' AV/TV the next slide will be continuous (any key to interrupt)
' Vol- mark focus (front) and start moving focus back; mark focus end by any key
' slide to the front of the stack
' Power start shooting
symbol slack = 5 ' how many micro steps to add when changing direction
symbol steppause = 1 ' larger number will make it go slower
' - useful if you have a stepper with very few steps per revolution
symbol stepc = b0
symbol s = b1
symbol i = b2
symbol direction = b3
symbol nsteps = b4
symbol nframes = b5
symbol nslide = b6
symbol j = b7
symbol irflag = b8
symbol olddir = b9
symbol contflag = b10
high 1
high 2
low 4
' (nsteps)
eeprom 0, (20)
read 0, nsteps
contflag=0
main:
infrain2
if infra<10 then
infra=infra+1
infra=infra//10
nsteps=infra*10
pause 500
infrain2
infra=infra+1
infra=infra//10
nsteps=nsteps+infra
write 0, nsteps
elseif infra=37 then
contflag=1
pause 500
infrain2
pause 500
endif
select infra
case 17 ' front focus
direction=2
gosub slide
case 16 ' back focus
direction=0
gosub slide
case 19 ' Vol- - mark focus start
nslide=0
irflag=0
pause 200
do
pause 200
direction=0
gosub slide
nslide=nslide+1
'pause 200
loop while irflag=0
pause 2000
for j=1 to nslide
direction=2
gosub slide
next j
gosub slide
direction=0
gosub slide
case 21 ' Power - start shooting run
gosub shoot
for j=1 to nslide
direction=0
gosub slide
gosub shoot
next j
endselect
'debug
pause 500
goto main
shoot:
pause 5000
high 4 ' shoot
pause 400
low 4
pause 3000 ' wait before the next slide (exposure time)
return
slide:
if direction<>olddir then ' remove sprocket slack
for i=1 to slack
gosub onestep
next i
endif
irflag=0
lup:
for i=1 to nsteps
gosub onestep
pause steppause
next i
if irflag=0 AND contflag=1 then goto lup
contflag=0
olddir=direction
return
onestep:
' s=direction*2
stepc=stepc+direction-1
let stepc=stepc // 4
lookup stepc, (%00000110, %00000100, %00000000, %00000010), s
let pins=s
if pin3=0 then
irflag=1
endif
'pause 1
return