Automated Macro Focus Rail

6,049

24

14

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...

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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.

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

Be the First to Share

    Recommendations

    • Tiny Speed Challenge

      Tiny Speed Challenge
    • Clocks Contest

      Clocks Contest
    • PCB Design Challenge

      PCB Design Challenge

    14 Discussions

    0
    BilloWales
    BilloWales

    Question 7 days 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 7 days 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
    JimM293
    JimM293

    Question 16 days 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 16 days 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
    JimM293
    JimM293

    Reply 16 days ago

    Please put me on the list when you get ready.

    0
    Bantman
    Bantman

    Tip 23 days ago

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

    1
    dtrewren
    dtrewren

    Reply 22 days 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 4 weeks 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.

    0
    dtrewren
    dtrewren

    Answer 4 weeks ago

    Hello there,
    Keeping the camera and subject still between frames and adjusting the lens in practice is extremely difficult - it's just very hard to adjust the lens to get consistent slice depth. Often the camera/lens combination is only moving by less than a millimeter between shots and consistent depth of field overlap between shots is important to get a good stacking result. The best solution is to keep the lens focus fixed and move the camera/lens with respect to the subject.

    I tend not to include links to products for sale in the main body of the instructable (looks like I am selling stuff) but as you have asked specifically here is eBay number of the rail I bought, just enter the number on the eBay search line, cost was £36 : 173877929011

    Cheers,

    Dave

    0
    onetruegod
    onetruegod

    Reply 4 weeks ago

    Thanks for the info and the search number.

    0
    dtrewren
    dtrewren

    Reply 4 weeks ago

    No problem - if you need any more info let me know.

    0
    jessyratfink
    jessyratfink

    5 weeks ago

    Great project and well documented, too :D

    0
    dtrewren
    dtrewren

    Reply 5 weeks ago

    Thank you Jessy - was a lot of fun, now to use for photography :)