Motorised Macro Rail (request to help)

0101001000

New Member
Hello to all,
rail.JPG


I ended with the BIG support of Stewart (SMACKKKKK) this project:

http://www.picaxeforum.co.uk/showthread.php?17248-Motorized-macro-rail-on-the-cheap&highlight=macro+rail

just that I have a problem to solve, if possible:
1) can be put a command to set the shutter time (exposure), for example, then I press VOL + and XX (two numbers) that correspond to the time:

I press VOL+,10 that corrispond to 1000 so in the code:

....
shoot:
pause 5000
high 4
pause 400
low 4
pause YY YY is the number (1000)
return


2) because I want to make very small movements I put a slide that moves (with motor stepper 200 steps) of 0.0025mm ... I just think there is a calculation error:

for example:
I imposed 1 for the resolution then beginning (with vol -) and the slide moves (all OK) ... I press one key and the slide stops and goes back to the start but will stop before and will not return to the starting point ... it seems that wrong calculations

consider that I have long way to make because the slide moves (resolution 1) with 0.002mm for step


sorry for my very very bad English
Roberto
 

bfgstew

Senior Member
Roberto,

shoot:
pause 5000
high 4
pause 400
low 4
pause YY YY is the number (1000)
return

To be honest the easiest way, for the moment, would be to do it via PE then upload it to the Picaxe chip.

The 1st and 3rd large values are to make sure all is steady before the shutter is actuated, the 400 value is the shutter actuation time, alter that one, if need be.

As for the movement, I shall look into it, unless some kind soul comes up with an answer first.

Stewart
 

0101001000

New Member
Hello Stewart,

many thanks for support!!!!!:D

I did some tests:
I set the value of the step 5, and the operation (return to the starting point) is correct under about 260 steps (in my case one step 0.0025, then 0.0025 * 5 * 260 = 3.25mm) around 3.5 mm (280 steps) the slide does not return to 0 but stops much earlier.

the same thing happens with steps 1, around 0.65mm (0.0025 *1* 260 = 0.65mm) work fine ,more than I have the problem ... ...

then for some reason (I do not know) misses the count ...

again many thanks for the help ...
Roberto
 

bfgstew

Senior Member
Roberto,
I think this is down to the code using byte variables (b4 etc), they only allow upto 255 then overflow without error i.e. 255 + 4 = 3

I think the code needs a few tweaks using word variables (eg w4) these give up to 65000 so should't give you problems, But you must read the manual fully to understand how they are used correctly.

Give it a go, if you get stuck or need help just shout.

Stewart
 

bfgstew

Senior Member
Roberto,

Also I think some of the math may be causing some issues, as Picaxe doesn't do fractions. Maybe technical may help here as math is not my strong point!!!!!!!!

Just double checking Roberto, are you using this motor? If not, what motor are you using.
What picaxe chip are you using 08M, 08M2, 08M2+? As some of the IR commands are deprecated.
Please post as well a high quality schematic of your circuit, a high quality pic of your circuit and a full version of the code you are using.
This will give everyone a clearer understanding of your set up and a better chance of resolving any issues/faults.
 
Last edited:

0101001000

New Member
Hello Stewart,
again thank you very much for the help!!!

yes the motor is to techsupplies
I using the 08M2

I do not think there are problems of connections, but in your slide you tried to more 280 steps and see if it returns to the starting point??

many many thanks
Roberto
 

bfgstew

Senior Member
Ok Roberto,

Gave mine a whirl and set it to step at 09 = to 2 steps on motor (entered using IR remote) set at end then to other, started to go back then stops a long way short of the start point, so yes there is a problem with the code.

See if works OK below 255 steps, then we will know if its the byte variable causing the problem.
 

bfgstew

Senior Member
Ok Roberto give this code a try, works ok for me now.

Code:
' 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     = w0
symbol s 	= w1
symbol i 	= w2
symbol direction = w3
symbol nsteps    = w4
symbol nframes   = w5
symbol nslide    = w6
symbol j	 = w7
symbol irflag    = w8
symbol olddir    = w9
symbol contflag  = w10

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
 

0101001000

New Member
Works!!!!

Hello Stewart...
:D
Now it works great ...

You are wonderful.
And one problem has been solved ...
Still remains one.

EDIT:
The cycle does not work well.
I mean now correctly returns to the starting point,but when I start the cycle this does not stop ...
 
Last edited:

bfgstew

Senior Member
Ok, lets sort that out first Roberto.

What I did with the code was replace all the byte variables (b0 - b10) with word variables (w0 - w10).
Go back to using byte variables but change nsteps to a word variable, being careful not to use a byte variable that is used in a word variable.............w0 = b0 and b1
w1 = b2 and b3
w2 = b4 and b5 and so on
Check out the manual on variables so you understand the system and give it a go.
 

bfgstew

Senior Member
Roberto, don't worry. Read this, it explains how variables work and how to use them. I shall look a bit deeper into the code and see what fix I can come up with. In the mean time, read, learn and have a play around with the code, only way to learn........:)
 

0101001000

New Member
thanks for supporting me

I looked the manual but I'm too novice, and I did some tests--> nothing.
but for me it is too difficult at this time.
 

bfgstew

Senior Member
Ok Roberto, we will get this sorted. Not at the moment though as down with the dreaded man flu, so out of action for a bit.
 

bfgstew

Senior Member
A quick shout for help please!

My heads a bit foggy and not firing on all cyinders.

What is the best way of seeing what is happening to the variables in this code as it has no display?

Code:
' 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
	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
Something is happening when it has gone through the steps of setting front and back focus, it should return to the start point ready to run, instead it stops well short of its intended start point, this to me is a sign of something overflowing, but for the life of me, I can't pin it down.
 

bfgstew

Senior Member
Thanks Hippy, sorry for such a simple request but my poor old brain is fried at the moment.....:(
 

bfgstew

Senior Member
Try this version Roberto.

Code:
' 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      ; number of steps the motor takes, between 01 and 99
symbol direction = b3
symbol nsteps    = b4 ; length of one step
symbol nframes   = b5
symbol nslide    = w7 ; number of slides
symbol j	 = w6     
symbol irflag    = b8
symbol olddir    = b9
symbol contflag  = b10
symbol expo = w9        ; camera on 

high 1
high 2
low 4

'           (nsteps)
eeprom 0, (20)

read 0, nsteps

contflag=0
expo = 0

main:
	infrain2
	expo = infra * 100
	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
	pause 500
	goto main

shoot:
	pause 2000    
	high 4	' shoot
	pause expo  ' camera on
	low 4
	pause 1000    ' wait before the next slide
	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
Looks like the issue with stopping has been cured and also the return to start works.
I have also added a small routine that can alter the exposure time (camera on)
shoot:
pause 2000
high 4 ' shoot
pause expo ' camera on
low 4
pause 1000 ' wait before the next slide
return

To alter this, on power up enter a 1 digit number, then press any key, this then multiplies the number entered by 100 so gives a range of between 100 to 900. Continue as normal setting up as before.
A bit basic but it is a start, and it works on mine!
 
Last edited:

0101001000

New Member
Hello Stewart,

now returns to start correctly ... ;)

with the function SERTXD I found the code for the VOL + button (18) and I modified the code so now I can set the delay from 1 to 9 seconds ...
I also made the slide return to the start after making the sequence ...
I tested everything and now is OK with 1000 steps!

Many thanks to everyone for their support
Roberto
 

bfgstew

Senior Member
No problem at all Roberto, glad you have got it working.

Be good for everyone to see the finished unit at some point.
 
Top