Automated Macro Focus Rail

9,861

44

26

Introduction: Automated Macro Focus Rail

About: I am an electronics engineer working in telecommunications in the UK. Generally I work on chip design for digital radio receivers. I like all things arty and consider chip design a bit arty :) Basically I h…

Hello community,

I would like to present my design for an automated macro focus rail. Ok, so the first question what the devil is a focus rail and what is it used for ? Macro or close up photography is the art of imaging the very small. This can be done at varying magnifications or ratios. For example an imaging ratio of 1:1 means the subject be photographed is projected onto the camera sensor at life size. An imaging ratio of 2:1 means the subject will be projected at twice life size onto the sensor and so on ...

A common artefact of macro photography is very shallow depth of field. Whether using dedicated macro lenses, taking standard lenses and reversing them or using bellows generally speaking the depth of field is shallow. Up until relatively recently this has been a creative issue with macro photography. However, it is now possible to create macro images with as much depth of field as you wish by a process called focus stacking.

Focus stacking involves taking a series or "stack" of images at different focal points from the closest subject point to the furthest subject point. The stack of images is then digitally combined to create a single image with much deeper depth of field. This a fantastic from a creative point of view as the photographer can choose how they wish their image to appear and how much should be in focus to achieve maximum impact. The stacking can be achieved is various ways - it is possible to use Photoshop to stack or a dedicated piece of software such as Helicon Focus.

Step 1: Focus Rail Principle and Design Criteria

The principle behind the focus rail is quite straight forward. We take our camera and lens and mount them on a high-resolution linear rail that permits the camera/lens combination to be moved closer or farther away from the subject. So, using this technique we are not touching the camera lens, other than maybe to achieve initial foreground focus, but are moving the camera and lens with respect to the subject. If we consider the lens depth of field to be shallow this technique generates focus slices at various points through the subject. If the focus slices are generated such that the depth of field slightly overlaps, they can be digitally combined to create an image with continuous focus depth across the subject.

Ok, so why move the big heavy camera and lens and not the relatively small and light subject of interest ? Well the subject might very well be alive, say an insect. Moving a living subject when you are trying to keep it still may not work too well. In addition, we are trying to keep consistent lighting from one shot to the next so moving the subject would mean moving all the lighting too to avoid moving shadow.

Moving the camera and lens is the best approach.

Step 2: My Focus Rail Main Design Features

The focus rail I have designed carries the camera and lens on a sturdy motor driven mechanical linear rail. The Camera can be easily attached and removed using a quick release dove tail mount.

The mechanical rail is driven in and out using a computer controller stepper motor and can provide a linear resolution of approximately 5um which I personally think is more than adequate most scenarios.

The control of the rail is achieved using a simple to use PC/Windows based user interface or GUI.

Position control of the rail can also be achieved manually using a rotary control with programmable resolution situated on the motor control board (although it could be positioned anywhere, say as a hand control).

The application firmware running on the control board microprocessor can be re-flashed via USB mitigating the need for a dedicated programmer.

Step 3: The Focus Rail in Action

Before getting into the detail of construction and build let us look at the focus rail in action. I have taken a series of videos details different aspects of the design - they may cover some aspects out of order.

Step 4: Focus Rail - the First Test Shot I Obtained From the Rail

At this stage I thought I would share a simple image obtained using the focus rail. This was essentially the first test shot I took once the rail was up and running. I simply grabbed a small flower from the garden and popped it on a piece of wire in order to support it infront of the lens.

The composite flower image was a composite of 39 separate images, 10 steps per slice across 400 steps. A couple of images were discarded prior to stacking.

I have attached three images.

  • The final focus stacked shot output from Helicon Focus
  • The Image on top of the stack - forground
  • The image on the bottom of the stack - background

Step 5: The Control Board Detail and Walk Through

In this section I present a video detailing the motor control board component parts and construction technique.

Step 6: The Control Board Manual Step Control

In this section I preset another short video detailing the manual control operation.

Step 7: Control Board Schematic Diagram

The image here shows the control control board schematic. We can see that by utilizing the powerful PIC microcontroller the schematic is relatively simple.

Here is a link to a high resolution schematic :

https://www.dropbox.com/sh/hv039yinfsl1anh/AADQjyy...

Step 8: PC Based User Interface Software or GUI

In this section I again use a video to demonstrate the PC based application control software often referred to as a GUI (Graphical User Interface).

Step 9: Principle and Operation of the Bootloader

Although not not related in any way to the focus rail operation the bootloader is an essential part of the project.

To reiterate - what is a bootloader ?

The purpose of a bootloader is to allow the user to reprogram or reflash the main application code (in this case the Focus Rail application) without the need for a dedicated specialized PIC programmer. If I were to distribute pre-programmed PIC microprocessors and needed to issue a firmware update the bootloader allows the user to reflash the new firmware without either having to buy a PIC programmer or return the PIC to me for a reflash.

A bootloader is simply a piece of software running on a computer. In this case the bootloader is running on the PIC microcontroller and I refer to this as firmware. The bootloader could be located anywhere in program memory but I find in more convenient to locate it right at the start of program memory within the first 0x1000 byte page.

When a microprocessor is powered up or reset it will start program execution from a reset vector. For the PIC microprocessor the reset vector is located at 0x0 and normally (without a bootloader) this would either be the start of the application code or a jump to the start depending on how the code is located by the compiler.

With a bootloader present following power up or reset it is the bootloader code that is executed and the actual application is located higher up in memory (termed relocated) from 0x1000 and above. The first thing the bootloader does is check the status of the bootloader hardware button. If this button is not pressed the bootloader automatically transfers program control to the main code in this case the Focus Rail application. From the users point of view this is seamless and the application code just appears to execute as expected.

However, if the bootloader hardware button is pressed during power up or reset the bootloader will attempt to establish communication with the host PC in our case via the radio serial interface. The PC bootloader application will detect and communicate with the PIC firmware and we are now ready to start a reflash procedure.

The procedure is straightforward and is conducted as follows:

  • The maunal focus button is depressed while hardware is powered up or reset.
  • PC application detects PIC bootloader and green status bar displays 100% plus PIC detected message is displayed.
  • User selects 'Open Hex File' and using the file chooser navigates to the new firmware HEX file.
  • User now selects 'Program/Verify' and the flashing process starts. First the new firmware is flashed by the PIC bootloader and then read back and verified. Progress is reported by the green progress bar at all stages.
  • Once program and verify is complete the user presses the 'Reset Device' button (bootloader button not pressed) and the new firmware begins execution.

Step 10: PIC18F2550 Microcontroller Overview

There is far too much detail to go into with regard to the PIC18F2550. Attached is the data sheet top level specification. If you are interested the entire datasheet can be downloaded from the MicroChip website or just google the device.

Step 11: AD4988 Stepper Motor Driver

The AD4988 is a fantastic module, perfect for driving any four wire bipolar stepper motor up to 1.5A.

Features:
Low RDS (On) Output
Automatic current decay mode detection / selection
Mix with slow current decay modes
Synchronous rectification for low power dissipation
Internal UVLO
Cross-current protection
3.3 V and 5 V compatible logic supply
Thermal shutdown circuitry
Ground fault protection
Load short-circuit protection
Optional step five models: full, 1/2, 1/4, 1/8 and 1/16

Step 12: Mechanical Rail Assembly

This rail was picked up from eBay for a great price. It is very robust and well made and came complete with stepper motor.

Step 13: Project Summary

I have very much enjoyed designing and building this project and have ended up with something I can actually use for my macro photography.

I tend to only build things that are of practical use and that I will personally use. I am more than happy to share far more design detail than has been covered in this article including programmed tested PIC controllers if you are interested in building a macro focus rail for yourself. Just leave acomment or private message me and I will get back to you. Many thanks for reading, I hope you enjoyed ! Best Regards, Dave

1 Person Made This Project!

Recommendations

  • Pets Challenge

    Pets Challenge
  • Stone, Concrete, Cement Challenge

    Stone, Concrete, Cement Challenge
  • DIY Summer Camp Contest

    DIY Summer Camp Contest

26 Comments

0
mohamad.desouki
mohamad.desouki

13 days ago

Great job Dave. Thanks for sharing the info.

0
belbury
belbury

Question 8 months ago

Hi Dave, I would love to have a go at making the focus rail biut would not have a clue on the software aspects - the GUI PC Interface and the hex coding for the PIC. Would I be able to purchase these from you? .........Thanks ...Mark

0
dtrewren
dtrewren

Answer 7 months ago

Hi Mark,
Excellent - I can help you if you want to have a crack at building a rail. A couple of other guys have already been successful. I can supply you a programmed tested PIC micro and have all the GUI software for download. So you just have to build the hardware - leave the software/firmware to me. Message me via instructables and send an email address for easier communication.

0
paj6149
paj6149

Question 1 year ago

Hi Dave, Thanks for the great project and explanations. It has really wet my appetite. I was considering purchasing one of the exorbitantly priced auto slide rails until i found your website. Can you tell me the minimum distance the stepper motor will move the rail. Are we talking fractions of a mm. or a number of microns (wishful thinking)? I have found a rail almost identical to yours on Banggood's site but longer. Thanks in advance.
P.S. Sorry Dave, I've just re-watched your Rail in Action video and you answered my question in that. You state 5 microns per 1/16th of a motor turn. If my calculation is right that is 1/200th of a mm. That is very impressive and just what I want for my macro photography. Hoping you get enough demand for the PCB kit. Thanks again for a very interesting article.

0
dtrewren
dtrewren

Answer 1 year ago

Hello there,
Thank you for the very positive feedback !
Yes, I measured a minimum travel of just over 5um at one step and 1/16 stepping. Obviously this is just a function of the mechanics and there are plenty of other budget mechanical rails available with a finer pitch lead screw although I wouldn't think you would need anything less than 5um.
Best regards,
Dave

0
JimM293
JimM293

Question 1 year ago on Step 4

Great project! I've done some macro photo work using a Sony Alpha with software controlled auto focus stepping with mixed results. Have you considered offering a PCB with part layout, a pre flashed PIC (with socket to prevent noobs burning the PIC), your GUI and a complete parts list for sale? I've seen similar complete ready to use systems for sale for hundreds of US dollars.

0
dtrewren
dtrewren

Answer 1 year ago

Hi Jim, thanks for the positive feedback. Yeh I am thinking of banging out a bunch of PCB's for guys that might want to build the design. Indeed I have also seen systems for, as you say, hundreds of pounds. The pre-flash PIC is not a problem as it has an embedded boatloader for subsequent re-flash and software updates. I will consider a kit if there is enough demand.

0
paj6149
paj6149

Reply 1 year ago

Me also. Thanks

0
starguywisc
starguywisc

Reply 1 year ago

I'm interested. :)

0
JimM293
JimM293

Reply 1 year ago

Please put me on the list when you get ready.

0
Zorro1930
Zorro1930

Reply 1 year ago

Put me on the list as well please!

0
Zorro1930
Zorro1930

1 year ago

Hi Dave
I am a real newbie with electronics, but love macro photography and stacked focus is a real interest. Is there Mac software as well as PC software to do the set up?

0
dtrewren
dtrewren

Reply 1 year ago

Hi there,
Very pleased you like the project. There isn't currently a Mac based application for the focus rail. I was under the impression it was possible to run Windows based applications on a Mac in an emulation mode ? The focus rail application has a very low overhead so this might be a good option although I have not tried this as have no Mac equipment.

0
Reddinr24
Reddinr24

1 year ago

Nice project. I've been planning on starting macro photography once I retire. This gave me even more motivation! Is your controller compatible with Helicon Remote? Any thoughts along those lines?

0
dtrewren
dtrewren

Reply 1 year ago

Hi There,
Thank you for your feedback and interest. No my design is not compatible with Helicon - I designed it stand alone considering other software. I just needed a focuser rail so sat down and came up with a design that suited my needs. I use Helicon for stacking the output images from the rail but don't use Helicon remote.
Cheers,
Dave

0
BilloWales
BilloWales

Question 1 year ago on Introduction

I am primarily a photographer, but get great satisfaction for making accessories for my photography. I intend to attempt to build your impressive automated macro stage and have ordered the drive system.
1. Can you provide a list of the components used on your board, I tried to make notes from the video not did not get it all
2. I am good on the mechanical side and have some experience of electronics but have never used PICs so have no idea how to flash them. Are there any solutions like buying them pre-flashed for novices like me.
Thank you for your inspiration. Bill

0
dtrewren
dtrewren

Answer 1 year ago

Hi Bill,
Excellent - always good when someone wants to have a crack at building one of my designs. Probably easlier if we carry on discussions via email rather than this interface. If you send me a private message via instructables with your email I can get back to you with more information.
Cheers,
Dave

0
Bantman
Bantman

Tip 1 year ago

You should participate in the PCB Contest. I would vote for this one for sure!

1
dtrewren
dtrewren

Reply 1 year ago

Hi Bantman,

Interesting - I wasn't aware there was a PCB contest, I will do some digging to find out what it is all about.

Cheers,

Dave

0
onetruegod
onetruegod

Question 1 year ago

Interesting project Dave.
Couldn't you keep the subject and the camera still and just adjust the focus between shooting frames?
You said "This rail was picked up from eBay for a great price", what is the rail's full description? What's it cost? A link to a listing would be nice.