## step size of the focusing motor in the lens

**Moderators:** ChrisR, Chris S., Pau, rjlittlefield

- iconoclastica
**Posts:**303**Joined:**Sat Jun 25, 2016 12:34 pm**Location:**Wageningen, Gelderland

### step size of the focusing motor in the lens

Focus stacks can be realized by changing the camera-object distance or by changing the focus distance of the lens, if an ordinary camera lens is used. For not-so-extreme macro photography (i.e. 1:1 tp 1:10 or even less) I prefer the latter method. It doesn't suffer from that much perspective change and the camera doesn't need to make long rides.

The canon sdk allows to drive the lens's focusing motor, at least for lenses that support it. Some do, some don't, my favorite 60mm does. I spent the past weeks to write me the software to run stacks by this method, for doing it by keyboard is a boring job and I made too many mistakes. The next thing I would like to add to this program is an option to propose the step-size. Most of the information to do this is available: the aperture size in use, the distance the lens is focused to (albeit none to accurate), and regressions to pupil ratios and magnification. So, expressed in length units, I already can approximate the required step size.

The missing info, however, is what change is effectuated by driving the focusing motor one step. The way I can think of to measure it is to repeatedly photograph a ruler at a 45 degree angle, separated by a known number of steps, and then try to estimate the focus shift from the recorded photos. But perhaps there are smarter ways, or possibly someone even has done this?

The canon sdk allows to drive the lens's focusing motor, at least for lenses that support it. Some do, some don't, my favorite 60mm does. I spent the past weeks to write me the software to run stacks by this method, for doing it by keyboard is a boring job and I made too many mistakes. The next thing I would like to add to this program is an option to propose the step-size. Most of the information to do this is available: the aperture size in use, the distance the lens is focused to (albeit none to accurate), and regressions to pupil ratios and magnification. So, expressed in length units, I already can approximate the required step size.

The missing info, however, is what change is effectuated by driving the focusing motor one step. The way I can think of to measure it is to repeatedly photograph a ruler at a 45 degree angle, separated by a known number of steps, and then try to estimate the focus shift from the recorded photos. But perhaps there are smarter ways, or possibly someone even has done this?

--- felix filicis ---

See this thread: https://www.photomacrography.net/forum/ ... hp?t=11519

And this one: https://www.photomacrography.net/forum/ ... ht=measure

- iconoclastica
**Posts:**303**Joined:**Sat Jun 25, 2016 12:34 pm**Location:**Wageningen, Gelderland

OK, for whom it might interest I have determined the step size function (possibly noone, but I did all the work so I'll report it here ).

I shot two measuring ranges, one at the closest possible distance, the other at about half a meter distance. The subject was a ruler at sharp angle with the lens axis. I took one shot, stepped 50 or 10 of the smallest steps, then the next shot and on, until I obeserved the focus going beyond the end of the ruler. I tried to point in the photo the marking best in focus and calculated the distance to that marking on the ruler. In the far series the depth of field is greater and therefore it's harder to pinpoint the exact position of the focus. Which is clear in the graph:

The next step is to relate this function to the near and far focal distance which is written into the EXIF data. That is none too precise, but I suppose if I always round towards the larger step size, the number of focus motor pulses will remain conservative.

I still have to figure out though how to convert the focal distance as measured from the sensor plane to the same used in depth of field calculations.

I shot two measuring ranges, one at the closest possible distance, the other at about half a meter distance. The subject was a ruler at sharp angle with the lens axis. I took one shot, stepped 50 or 10 of the smallest steps, then the next shot and on, until I obeserved the focus going beyond the end of the ruler. I tried to point in the photo the marking best in focus and calculated the distance to that marking on the ruler. In the far series the depth of field is greater and therefore it's harder to pinpoint the exact position of the focus. Which is clear in the graph:

The next step is to relate this function to the near and far focal distance which is written into the EXIF data. That is none too precise, but I suppose if I always round towards the larger step size, the number of focus motor pulses will remain conservative.

I still have to figure out though how to convert the focal distance as measured from the sensor plane to the same used in depth of field calculations.

--- felix filicis ---

- rjlittlefield
- Site Admin
**Posts:**20975**Joined:**Tue Aug 01, 2006 8:34 am**Location:**Richland, Washington State, USA-
**Contact:**

Just so you know, I've been watching with interest to see how this thread would go.

My usual guidelines to people who want to focus-stack "by ring" is that the required focus step will depend strongly on effective aperture, may depend weakly or not at all on focus distance and zoom setting, and in any case can only be determined for sure by experiment.

Those guidelines are based on a simple model that corresponds to lenses that focus by extension using a uniform helix. Think of old manual-focus lenses.

A short but cryptic explanation is that if you look at depth-of-

I am not aware of good data that either supports or contradicts those guidelines. Perhaps your effort can provide the first!

Looking at your graph, one aspect bothers me: I have no idea how to interpret your numbers. What is "distance" measured with respect to? What is the corresponding magnification at the plane of focus?

--Rik

My usual guidelines to people who want to focus-stack "by ring" is that the required focus step will depend strongly on effective aperture, may depend weakly or not at all on focus distance and zoom setting, and in any case can only be determined for sure by experiment.

Those guidelines are based on a simple model that corresponds to lenses that focus by extension using a uniform helix. Think of old manual-focus lenses.

A short but cryptic explanation is that if you look at depth-of-

**focus**at the sensor, as opposed to depth-of-**field**at the subject, then the governing equation from the rule of 1/4-lambda wavefront error is that DepthOfFocus = lambda/NA^2, where NA = 1/(2*Fe) and Fe = effective F-number. Notice that the equation contains nothing about focus distance, unless changing focus also changes effective aperture.I am not aware of good data that either supports or contradicts those guidelines. Perhaps your effort can provide the first!

Looking at your graph, one aspect bothers me: I have no idea how to interpret your numbers. What is "distance" measured with respect to? What is the corresponding magnification at the plane of focus?

--Rik

- iconoclastica
**Posts:**303**Joined:**Sat Jun 25, 2016 12:34 pm**Location:**Wageningen, Gelderland

Hi Rik,

I then wondered whether the exponential function would adequately describe the increase in step size. Assuming my lens is driven by a uniform helix too, and that on step of the focusing motor causes an unknown but constant angular displacement, I simulated the increase in object distance by linearly increasing the back distance using the lens equation (1/f = 1/o + 1/b). More than anything this made obvious that the exponential function is not suited to describe the stepsize and I had better derive a more fitting function.

From the lens equation it follows that the object distance as function of the back distance is

o(b) =

and therefore the increase in object distance per decrease of back distance, the derivative of this function, or

o'(b)=do/db=

Now I have to feed this to non-linear regression software, but I'll have to find a way to get passed the unknown offset in rotation of the second series of measurements.

Wim

I measured the distance from the front of the lens, not knowing the zero-reference. But I could easily correct that number afterwards. So I did, once I noted that the closest distance I found was 12.5cm short of the closest focus distance from the specs. After changing the reference to the plane of the sensor, the fit to the exponential function improved. However, the first thing I noticed this morning was that I made a mistake with plus and minus and that the d0 in the graph was in fact half a lens' length in front of the lens.What is "distance" measured with respect to?

I then wondered whether the exponential function would adequately describe the increase in step size. Assuming my lens is driven by a uniform helix too, and that on step of the focusing motor causes an unknown but constant angular displacement, I simulated the increase in object distance by linearly increasing the back distance using the lens equation (1/f = 1/o + 1/b). More than anything this made obvious that the exponential function is not suited to describe the stepsize and I had better derive a more fitting function.

From the lens equation it follows that the object distance as function of the back distance is

o(b) =

and therefore the increase in object distance per decrease of back distance, the derivative of this function, or

o'(b)=do/db=

Now I have to feed this to non-linear regression software, but I'll have to find a way to get passed the unknown offset in rotation of the second series of measurements.

I would say so, since Fe=(1+M)*N with M=magnification and N the F-number. N doesn't change indeed, but M decreases with distance starting at 1x at the closest focus point.Notice that the equation contains nothing about focus distance, unless changing focus also changes effective aperture.

Wim

--- felix filicis ---

- rjlittlefield
- Site Admin
**Posts:**20975**Joined:**Tue Aug 01, 2006 8:34 am**Location:**Richland, Washington State, USA-
**Contact:**

You're placing too much faith in a particular model. The actual behavior varies from system to system. Most obviously, modern Nikon camera+lens systems have a user interface that works directly in Fe. In such case the physical aperture will be automatically widened to compensate for longer extension. With your Canon system, the user interface does use N, but still it's not always true that Fe=(1+M)*N. For example I have read that one of Canon's early macro lenses lost only 1 stop from nominal aperture at 1:1, versus 2 stops predicted by the formula. Presumably this is because part of the magnification increase was achieved by shortening the effective focal length while leaving the physical aperture unchanged, effectively making smaller N for larger M.iconoclastica wrote:I would say so, since Fe=(1+M)*N with M=magnification and N the F-number. N doesn't change indeed, but M decreases with distance starting at 1x at the closest focus point.Notice that the equation contains nothing about focus distance, unless changing focus also changes effective aperture.

It's great to try fitting your data to a simple model, but don't get hung up on assuming that the model is right.

--Rik

- iconoclastica
**Posts:**303**Joined:**Sat Jun 25, 2016 12:34 pm**Location:**Wageningen, Gelderland

One advantage of oversimple models is that they clearly show where the thinking goes wrong. In this case: the lens extension per rotation step is not constant as an ideal helicoid would be, but seems to be accelerated towards the longer focusing distances.

I think I would best fit just any curve to the data with no other consideration than that it fits the data well, and when reversed predicts the shift in focus well. Or alternatively use tabled data.

But coming back to your first reply,

I think I would best fit just any curve to the data with no other consideration than that it fits the data well, and when reversed predicts the shift in focus well. Or alternatively use tabled data.

But coming back to your first reply,

What is the reason to bother about the depth of focus when I want to make ovelapping slices of field-in-focus, and how could I arrive at a value for the effective focus if it isn't by N(1+M)?A short but cryptic explanation is that if you look at depth-of-focus at the sensor, as opposed to depth-of-field at the subject, then the governing equation from the rule of 1/4-lambda wavefront error is that DepthOfFocus = lambda/NA^2, where NA = 1/(2*Fe) and Fe = effective F-number. Notice that the equation contains nothing about focus distance, unless changing focus also changes effective aperture.

--- felix filicis ---

- iconoclastica
**Posts:**303**Joined:**Sat Jun 25, 2016 12:34 pm**Location:**Wageningen, Gelderland

I made some additional measurements to fill the gaps.

The 'focus shift' is how far the centre of focus moves forward given the number of motor steps, starting from the nearest possible focus (i.e. 210mm from the sensor plane). F(r) is the focal shift, and f'(r) therefore the increment per motor step.

The 'focus shift' is how far the centre of focus moves forward given the number of motor steps, starting from the nearest possible focus (i.e. 210mm from the sensor plane). F(r) is the focal shift, and f'(r) therefore the increment per motor step.

--- felix filicis ---

- rjlittlefield
- Site Admin
**Posts:**20975**Joined:**Tue Aug 01, 2006 8:34 am**Location:**Richland, Washington State, USA-
**Contact:**

I agree. And it looks to me from this last graph like you've made great progress in collecting clean data and then fitting it.I think I would best fit just any curve to the data with no other consideration than that it fits the data well, and when reversed predicts the shift in focus well. Or alternatively use tabled data.

I'm curious, are you using a single functional form to fit all your data at once, or is the red line some piecewise fit?

I will be very interested to see what your work ends up producing in terms of increments per focus step, by the time you run through the DOF equations based on magnification. As a wild guess, I expect it will be nearly constant at low magnifications, then increase as you approach 1:1.

Responding to your questions...

Sometimes it's simpler to think in terms of what's happeningiconoclastica wrote:What is the reason to bother about the depth of focus when I want to make ovelapping slices of field-in-focus

*behind*the lens, rather than in front of it.

Suppose you want to focus stack a landscape, extending clear out to infinity. Where should the focus points go?

I think it's quite difficult to answer that question by manipulating the standard DOF equations that work in terms of magnification or distance to subject.

But if we shift our point of view and think about what happens

*behind*the lens, then the problem gets simple. The subject at infinity will focus at one FL behind the lens. That's the first image. The depth of

*focus*can be obtained from the 1/4-lambda rule, DOF = lambda/NA^2, where NA = 1/(2*Fe). Let's just call that "s", for step size. So then move the sensor back one step, to a distance of FL+s behind the lens. The corresponding front focus distance can then come from your o(b) equation, so FFD = 1/(1/FL-1/(FL+s)). The next sensor position is at FL+2s, then FL+3s, and so on.

It's a very simple method. I use it to generate the tables at https://www.zerenesystems.com/cms/stack ... landscapes . George Douvos does something similar in his FocusStacker app.

In the regime of low magnifications, it works great, and it produces the very simple result that step size in terms of a uniform helix depends only on Fe, not directly on any distance.

For someone who is focusing by rear bellows extension, this method also scales gracefully to high magnifications. But when focusing by other methods like you're using, it cannot be trusted to scale well.

I assume you mean effective aperture. That's easily measured by photographing a target that has uniform brightness, and seeing how much additional exposure factor you need to match pixel values between infinity focus and close focus settings. If you're lucky it will be 2 stops additional exposure at M=1, and then you could safely use the (1+M) model. Otherwise I think it's measure and fit.how could I arrive at a value for the effective focus if it isn't by N(1+M)?

--Rik

- iconoclastica
**Posts:**303**Joined:**Sat Jun 25, 2016 12:34 pm**Location:**Wageningen, Gelderland

Here I am lucky: the histogram shifts down exactly two stops when the same white background is photographed at infinity and 1:1 magnification (or 21 cm). I can make it one stop by turning the lens to its 1:2.5 mark.I assume you mean effective aperture. That's easily measured by photographing a target that has uniform brightness, and seeing how much additional exposure factor you need to match pixel values between infinity focus and close focus settings. If you're lucky it will be 2 stops additional exposure at M=1, and then you could safely use the (1+M) model. Otherwise I think it's measure and fit.

I had CurveExpert Pro trying a large number of functions and it came up with a rational function (i.e. 1st order divided by 2nd order) to yield the best fit. Having a biological background myself, such a perfect result looks almost fraudulent to me...I'm curious, are you using a single functional form to fit all your data at once, or is the red line some piecewise fit?

I will implement your algorithm and see what it leads to.

thanks,

Wim

--- felix filicis ---

- rjlittlefield
- Site Admin
**Posts:**20975**Joined:**Tue Aug 01, 2006 8:34 am**Location:**Richland, Washington State, USA-
**Contact:**

I understand your feelings. Biological systems are generally too messy and noisy to be accurately modeled by any simple function.iconoclastica wrote:I had CurveExpert Pro trying a large number of functions and it came up with a rational function (i.e. 1st order divided by 2nd order) to yield the best fit. Having a biological background myself, such a perfect result looks almost fraudulent to me...

But lens systems are different.

As an example, consider the model system that consists of a single "thick" lens (multiple elements but no variable spacings), focused entirely by extension, controlled by steps along a uniform helix, such that step 0 gives 1:1 and step N focuses at infinity.

After slogging through the algebra, it turns out that in theory the total distance from sensor to focused subject, as a function of step number, is just a rational function, 2nd order divided by 1st order.

In practice, as long as you make all measurements on axis and your lens is free of longitudinal aberrations (spherical & chromatic), the model will be a perfect reflection of reality to within measurement error.

Clearly your measurements are well made!

By the way, in such a system, at 1:1, changing the extension has no effect on focal point, only on magnification. This is because the total distance, sensor to subject, reaches a minimum at 1:1 and becomes larger on either side of that. The Canon MP-E 65 has a similar behavior, except that its minimum distance is reached at about 1.4X (if I recall correctly). Trying to focus-stack "by ring" at that point with an MP-E is a highly frustrating and unproductive exercise!

--Rik

- rjlittlefield
- Site Admin
**Posts:**20975**Joined:**Tue Aug 01, 2006 8:34 am**Location:**Richland, Washington State, USA-
**Contact:**

Recording some math, before I erase my whiteboard...

i: distance from sensor to rear principal plane

g: gap between principal planes

o: distance from front principal plane to subject

d: distance from sensor to focused subject

f: focal length of the lens

s: size of rear extension step

n: rear extension step number, such that n=0 gives 1:1.

Then from:

d = i + g + o

1/f = 1/i + 1/o

i = 2f - s*n

we can slog through the algebra to get that:

d = (c1+c2*n+c3*n^2) / (c4+c5*n)

where

c1 = 4*f*f+g*f

c2 = -4*f*s-g*s

c3 = s*s

c4 = f

c5 = -s

Define symbols as follows:As an example, consider the model system that consists of a single "thick" lens (multiple elements but no variable spacings), focused entirely by extension, controlled by steps along a uniform helix, such that step 0 gives 1:1 and step N focuses at infinity.

i: distance from sensor to rear principal plane

g: gap between principal planes

o: distance from front principal plane to subject

d: distance from sensor to focused subject

f: focal length of the lens

s: size of rear extension step

n: rear extension step number, such that n=0 gives 1:1.

Then from:

d = i + g + o

1/f = 1/i + 1/o

i = 2f - s*n

we can slog through the algebra to get that:

d = (c1+c2*n+c3*n^2) / (c4+c5*n)

where

c1 = 4*f*f+g*f

c2 = -4*f*s-g*s

c3 = s*s

c4 = f

c5 = -s

*Ref: topic41580_stepSizeOfTheFocusingMotorInTheLens.xlsx*