Sunday, 4 January 2015

Eyepiece - on stepper drivers and motion sensors

I have spent the past couple of days designing the electronics by which to control the stepper motor that will be used to operate the fine focus of the microscope for image stacking.

The mechanism has an extremely free operation and the end stops cause the knobs to continue to rotate through use of a fairy stiff friction clutch.

The output torque of a stepper motor is roughly proportional to the current through the windings, and thus to the voltage of the electrical supply.

The motor that I have has 40Ω windings, and is designed for use at somewhere around 20V - therefore, it would be possible to drive the stepper at a lower voltage, set so that the motor stalls at the end of the focus mechanism's travel.
Preliminary circuit design - stepper controller


Stalling a stepper motor (difficult to do when fully powered) doesn't damage the motor or the drive circuitry (one of the reasons for my choice of stepper rather than a DC servo motor).

I am still refining the design and features of the board which will be used to drive the stepper motor.


_______________________________


While on the subject of the focus mechanism, I wanted to be able to detect when the motor stalled. One way would be to use an optical encoder, either attached to the motor or to the focus knob, but the problem remains that if the knob bounces as the motor state changes, that small motion could well be registered as continued movement.

To prevent this, a quadrature encoder would be required - and thus calling for its own additional circuitry to determine whether the motor was stalled or not.

The alternative would be to use dome form of optical device to detect the net motion of the knurling on the knob.

Now, what device do we all use to detect relative motion?

A clue, most of them are attached to our computers and located alongside the keyboard.

A cheap mouse will do the job, and ten minutes effort with Google provided sufficient information to be able to, theoretically, access a USB mouse directly from software.

Edit:

I have now tested this idea - and, not only does it work, but it detects the three microswitches, too!

Because of the way Plug 'n' Play works, multiple mouse devices are separately enumerated, and their names placed in the appropriate directory
 /dev/input/by-id/ 

The python program that is used as a proof of concept is:

#!/usr/bin/python

# Core logic courtesy of PeterO on the Raspberry Pi forum.
#  http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=80987

import struct
import binhex

# You'll need to find the name of your particular mouse to put in here...
file = open("/dev/input/by-id/usb-192f_USB_Optical_Mouse-event-mouse","rb")


while True:


    byte = file.read(16)
#    h = ":".join("{:02x}".format(ord(c)) for c in byte)
#    print "byte=",h

    (type,code,value) =  struct.unpack_from('hhi', byte, offset=8)

    if type == 1 and value == 1:
        if code == 272:
            print "LEFT PRESS",
        if code == 273:
            print "RIGHT PRESS",
        if code == 274:
            print "CENTRE PRESS",
        print code

    if type == 2:
        if code == 0:
            print "MOVE L/R",value
        if code == 1:
            print "MOVE U/D",value

    if type == 0:
        print "Clear Event", type, code, value

    if (type <> 0) and (type <> 1) and (type <> 2) :
        print "other event", type, code, value


_______________________________


While I like to build my electronics on custom printed circuit boards and, indeed, have the software to do so, it tends to be somewhat expensive - especially should any error be made in the board design.

Since it is unlikely that this electronic design will ever be anything but a one-off, I have decided that I will be building using either proto-board or strip-board.
That is, to say, AFTER testing the design out using breadboard!




No comments:

Post a Comment

Comments and suggestions are warmly welcomed.