As some of you are aware, I have a small desktop milling machine (Taig) that I converted for CNC control. And a very useful feature to implement on a CNC machine is the use of home and limit switches. Home switches provide a known reference point for the software for each axis. Limit switches provide for a hard wired safety so that, in the event of a software hiccup, the system does not exceed the physical travel limits for each axis.
On my machine I originally used micro switches to provide these functions.
And these worked very well until I installed a new interface card in my CNC controller. The old interface card used the PC parallel port to communicate between the computer and the CNC controller. This is fine and it does provide real-time control of the machine. But I began to encounter problems with the Mach 3 software and wanted to migrate to another software suite. I found a software package called USB CNC Controller that uses a USB port to communicate between the PC and the CNC controller. The new interface card came with very little documentation and I ended up connecting the limit switches incorrectly. As a result of this the machine did not sense the switches and ran right through them!
I realized then that I needed to upgrade to a non-contact style limit switch. I would also like to use this style switch for my Rostock project.
Limit switches based upon optical sensors are not a good fit for a machine that throws swarf all over the place, but may work well for the Rostock project. I decided to pursue a limit switch based upon a Hall Effect sensor and the following is what I learned along the way.
Hall Effect Sensors:
The effect of generating a measurable voltage by using magnetic fields was discovered by Dr. Edwin Hall, for whom it is named, back in the late 1870’s. Dr. Hall observed that when a magnet was placed so that its field was perpendicular to one face of a thin rectangle of gold through which current was flowing, a difference in potential appeared at the opposite edges.
The modern Hall Effect sensor consists of an integrated circuit chip that contains the Hall element (a thin rectangular p-type semiconductor material) and signal conditioning electronics (voltage regulator, operational amplifier, and output driver stage).
Regulated voltage is applied to the semiconductor material causing a current to pass through. When a magnetic force is applied (perpendicular to the flow of current), the magnetic flux lines exert a force on the semiconductor material which deflects the charge carriers (electrons and holes) to either side of the semiconductor slab. The movement of charge carriers is a result of the magnetic force passing through the semiconductor material. As the electrons and holes move toward the sides a potential difference is produced between the two sides of the slab. This difference in potential is directly proportional to the strength of the magnetic field passing through the semiconductor material.
The voltage produced is quite small, on the order of just a few microvolts, so it is applied to the operational amplifier to produce a useable voltage. This voltage is then supplied to either a Schmitt-trigger and transistor stage or straight to a transistor stage.
Hall Effect sensors are available with digital and analog (linear) outputs:
Digital
Digital output sensors have a Schmitt-trigger with built-in hysteresis connected to the op-amp. When the magnetic flux passing through the Hall Sensor exceeds a pre-set value the output switches from the “OFF” condition to the “ON” condition. The built-in hysteresis prevents oscillation of the output signal as the sensor transitions in and out of the magnetic field.
Analog
Analog, or Linear, sensors provide a continuous voltage output that is proportional to the strength of the magnetic field. In linear output sensors the voltage will increase with the magnetic field until the operational amplifier enters saturation, the limits imposed upon it by the power supply. Any additional increase in the magnetic field will have no effect once the amplifier reaches saturation.
The sensed magnetic field can be either positive or negative. As a result the operational amplifier will be driven either positive or negative, thus requiring two power supplies. To avoid needing two supply voltages, a fixed offset or bias is introduced into the operational amplifier. The bias appears on the output when no magnetic field is present and is referred to as the null voltage. When a positive magnetic field is sensed, the output increases above the null voltage. When a negative magnetic field is applied the output decreases below the null voltage (but remains positive).
I borrowed some of the graphics from this web site, more detailed information about how Hall effect sensors work can be had from them: http://www.electronics-tutorials.ws/electromagnetism/hall-effect.html
Design:
I first experimented with circuits designed around analog devices (operational amplifiers) like many of the products already available for sale on the web.
Don’t beat me up too badly on this circuit as I know veery little about operational amplifier circuit design. I was just winging it!
I had some success, but found that there were many limitations. One problem that I encountered was the lack of hysteresis, the circuit would oscillate horribly when the sensed field was at or near the set point. I experimented with various feedback options, regenerative forced the operational amplifier into saturation and latched the output until power was removed. Degenerative feedback offered slightly better results but I just wasn’t pleased with some of the trade-offs. (Sorry, no pictures because I was without a camera until recently)
Since I love playing with microcontrollers I decided to try using an attiny85 as the foundation for my limit switch. In this way I could address the problems/limitations through software.
Design Objectives:
So I sat down and thought about what features I would like to incorporate into a limit switch design. I settled on the following objectives;
- Bipolar response - The switch needed to be able to sense the magnet regardless of which pole was facing the sensor.
Adjustable trip point - Be able to electrically adjust how close the magnet needs to be before transitioning the output to the “ON” state.
Hysteresis - To avoid oscillation when the sensed field is at, or near, the set point.
Fault Detection – Detect if the Hall Effect sensor has failed and provide an indication of a fault condition.
Error Handling - In the event of a fault disable the machine for safety.
The first stated objective was to eliminate the need to determine the magnet orientation during installation on the CNC machine. Yes, I am basically lazy and want to make the sensor as simple to install as possible!
The second objective eliminates the need for precise physical alignment during installation. Yep, that laziness thing again!
The third objective came about as a direct result of my experiments using operational amplifiers. I experienced oscillations in the output which rendered the circuit useless for my intended application.
The fourth objective arose when the regulator on my breadboard power supply shorted and delivered unregulated voltage which destroyed the Hall Effect sensor. Because the operational amplifier had a wider operating voltage range, it was not destroyed and continued to operate. I troubleshot the circuit for much longer that I care to admit before realizing what had happened.
The fifth and final objective just made sense, if the sensor fails don’t let the machine move!
Hardware:
Processor Selection – For this design I selected the Atmel Attiny85 microcontroller. This processor comes in an 8 pin package and has more than enough memory, peripherals, and I/O for this project. Initial software development was accomplished using an Arduino board for proof of concept. Later the software was rewritten for the Attiny85 using the Arduino IDE. I’m currently working on writing the code in gcc using Atmel Studio. That software is coming along well, but my first attempts at uploading the hex files met with failure. More on that phase later.
Sensor Selection - To accomplish the first goal I selected a single supply ratiometric linear Hall Effect sensor (AH3503). This type of sensor uses a push-pull output and is ratiometric to the supply voltage with respect to offset and gain. The AH3503 can sense either pole of the magnet which is not the case with all linear output devices. With no magnetic flux field present the output is approximately one half of the supply voltage (Supply= 5V) or ~2.5V in this case. In the presence of a magnetic field the output voltage either increases above 2.5V or decreases below 2.5V depending upon which pole of the magnet is facing the sensor. The amount of deviation is proportional to the strength and polarity of the magnetic field. The AH3503 output does not operate rail-to-rail, from 0 to 5V, it reaches saturation prior to the upper or lower supply voltage. This works to our advantage for this application and we will see how this is important to the design later.
Datasheet: http://p.globalsources.com/IMAGES/PDT/SPEC/229/K1011923229.pdf
Circuit Board – I designed several versions of a Attiny85 breakout board for my personal use. I have one SMD with an on board regulator, one SMD without the regulator circuit, and one through hole version. I had intended to use the SMD without regulator to make the limit switches. With the addition of a small piece of proto board I expected to make a compact limit switch design. Then reality struck and I realized that I am an idiot! While designing the breakout boards I had neglected to ensure that the spacing between headers was a multiple of .1” and so the boards will not directly mate with proto board hole patterns. I can still use them, but what a major blunder!
Pin Assignment - As you can see on the schematic
PB0 (D0 in Arduino) is assigned to the Sense LED. As the name implies, this LED provides a visual indication when the magnet is sensed. But it is also used to indicate a fault condition in the event of a Hall sensor malfunction.
PB1 (D1 in Arduino) is the actual output to the machine. It is currently designed to as an active low, meaning that when the magnet is sensed, the output goes low and in the absence of the magnet it goes high.
PB3 (D3/A3 in Arduino) is an input for the potetiometer used to adjust the set point.
PB4 (D4/A2 in Arduino) is an input used to measure the voltage output from the AH3503 (Hall Sensor).
Here is a photo of the circuit on a breadboard to test the code. The LED on the top right represents the output to the machine’s limit switch input. This output is currently set to output a high when not at the limit (to emulate a normally closed mecahnical switch typically used) and the output goes low to indicate a limit (or if a fault is detected in the hall sensor - disables machine movement). And the LED on the left represents the state indicator (Off = when not at the setpoint (limit), On = Setpoint (limit) reached, Flashing = a faulty hall effect sensor).
The next picture shows the same circuit when a magnet is in the detection range set by the potentiometer. This is actually the maximum detectable distance for the circuit.
You can clearly see that the output LED is indicating a low (limit/setpoint reached) and the indicator LED has illuminated.
The next step is to build the circuit into a prototype that can be attached to the machine for testing. So I machined some parts to make an enclosure using 0.2 inch thick plexiglass. I made a cover for the enclosure out of 0.125 plexiglass to lessen the overall height of the finnished box.
I currently am lacking the acrylic adhesive and a few resistors required to finish the prototype circuit. The parts will stack as shown below (with the addition of the missing components). The bottom and mid-section of the enclosure will be bonded together and the top will screw on to allow for access in the future.
The programming connector will double as the interface to the machine. The machine will supply +5v and Ground through the programming connector and the limit switch output will be provided to the machine through the same.
I know video would be nice, but I currently have no means to create videos.
Well, that is all that I have right now. I will update this post as I make headway. As always I welcome your comments and suggestions. And thank you for taking the time to listen.