Home‎ > ‎

- CNC mill -



Introduction to a Custom CNC Current Supply, Controller, and Interface
Background and Design



This page will show you how to convert your mill to CNC all by yourself by building your own current supply, controller, and interface from scratch!


What you will need:
  • The ability to solder
  • Basic machining skills
  • Any basic mill
  • Time

NOTE: Safety is your responsibility. While the information contained in these pages is intended to instruct in a meaningful and safe manor, the construction of any project often comes with a certain level of inherent danger. As a result, the author in no way assumes any responsibility for any damages incurred while following the steps or instructions in these pages including but not limited to property and personal injury/damage/loss of any kind.  As always, please use proper safety gear when using any power tools or undertaking any construction project, AND USE COMMON SENSE!




Introduction

Systems which utilize computer numerical control are almost entirely dependent on the principals of Mechatronics. The computer which controls the system and its corresponding interface are both purely electronic systems. These signals must therefore be amplified and sent to an actuator in order to provide the mechanical motion necessary for physical control. The actuators of choice for most CNC applications are stepper motors. Stepper motors provide a very simplistic means through which to control their angular position, most frequently just a
step and direction input will suffice. However, the simplistic design of the stepper motor is not without its drawbacks.

One fundamental problem with all stepper motors (more pronounced in larger models), is the large amount of winding inductance and back EMF generated as a result of their many internal poles. As the velocity of a motor increases, the drivers ability to deliver current is impeded by the back EMF of the motor. The diminishing current results in a loss of torque and a reduction in dynamic accuracy. To minimize these effects, thereby stabilizing the torque delivered, a constant-current (variable-voltage) supply must be employed. By increasing the rail voltages applied to the driver, an output voltage capable of overcoming the effects of back EMF can be delivered to the load. However, this same voltage must not be applied at low angular velocities or the result will be excessive heat and ultimately motor failure. Overcoming this important design requirement demands a sophisticated current supply.

The method selected for current regulation is a feedback controller operating off of an error signal generated by the load current. Based on this error signal, a pulse width modulated (PWM) signal will be generated and sent to the first stage of the driver amplifier. The large size of the mill and nature of machining processes requires a system of actuators which can deliver significant amounts of torque. These torque requirements lead to large current demands, often several amps or more. The driver amplifier must therefore be designed to handle such currents; a requirement that leads to many design challenges.



Computer Controller

The tremendous speeds of today’s CPU’s relative to the operating speed of stepper motors allows for the employment of just about any modern desktop computer as a stepper controller. The computer selected for this mill controller is a standard Pentium III desktop machine with a parallel I/O interface. Loaded on this machine is Ubuntu®, a Linux based operating system which was released under the general public licence and is therefore free of charge, including enterprise releases and security updates. Bundled with this operating system is a program called Enhanced Machine Controller (EMC2). EMC2 is a software system for computer control of machine tools such as milling machines, lathes, plasma cutters, robots, hexapods, etc. This program operates under the Linux real-time operating system allowing for both motion control and position sampling in real time. Thanks to the introduction of the Hardware Abstraction Layer (HAL), simple reconfiguration of EMC2 and its corresponding I/O can now be handled without the need of recompiling. This allows for a convenient interface to each stepper driver. Below is a picture of the selected computer (Figure 1.1). On the screen is the standard EMC2 graphical user interface.

Figure 1.1 - Computer controller.




Current Supply

As discussed in the introduction, the method selected for current regulation is a feedback controller operating off of an error signal generated by the load current. Based on this error signal, a pulse width modulated (PWM) signal will be generated and sent to the first stage of the driver amplifier. The bulk of these operations will be handled by an integrated circuit model SG 3524. This IC was specifically designed to be employed as a regulating pulse width modulator. Feeding the sampled voltage (generated by the load current) into the IC’s error amplifier will automatically generate the correct PWM signal. This signal will appear across the collectors of the IC’s output transistors, pins 12 and 13, which have been wired as a single-ended output. The frequency of this signal (chop frequency) is determined by the passive components attached to pins 6 and 7 of the IC. The mathematical formula which relates these components to the chop frequency may be defined as:

f  = 1.30 / (RT * CT)             Where: RT is in kΩ , CT is in μF , f is in kHz

In our case, components have been selected to obtain a chop frequency of about 26kHz (RT = 5 kΩ, CT = 0.01 μF) as seen in the schematic. The variable resistor (seen feeding into pin 2 of the IC) is used to set the desired regulated current level. This is the voltage to which the load current voltage signal is compared to in the by the IC’s internal error amplifier.

The active device through which all motor current will flow is the P-channel MOSFET. This is the power transistor which will be switched on and off to regulate current flow. Ideally the voltages presented at the gate of this transistor will rise and fall instantly, as determined by the PWM IC. Unfortunately in real life, and especially in power MOSFET’s, the gate exhibits a finite capacitance which will effect the signals presented to the gate. To overcome the effects of this inherent capacitance, two small signal transistors wired in a push-pull configuration will be used to feed the gate. These transistors will effectively slam the gate between +24V and +12V providing a much better transient response. The +12V operating condition is again a circumstance of the transistors characteristics. The selected P-channel MOSFET, model IRF4905 has a drain-to-source breakdown voltage of over 50 volts but a gate-to-source breakdown voltage of less than 20 volts. This is the reason for the third small signal transistor which has been wired to interface between the open-collector output of the IC and the input of the push-pull amplifier so as never to allow the gate-to-source voltage to exceed 12V.

The LC portion of this circuit is designed to smooth the ripple caused by the constant switching of the upstream power MOSFET. The series inductor will store energy in a magnetic field while the MOSFET is in conduction and release it during cutoff. This has the effect of maintaining a near constant current over the entire duration of the chop period. The catch diode which is connected between ground and the inductor/transistor node provides a current path while the transistor is in cutoff. The capacitor which appears across ground and the other side of the inductor stores energy in the form of an electric field and always tries to maintain a constant voltage across its terminals. This has a further smoothing effect resulting in a greater reduction in voltage ripple which is ultimately delivered to the motor coils downstream.

The current sensing resistor (R shunt) is connected in series with the load. This resistor has been selected to have a vary low resistance value (0.1 Ohms) to minimize its power consumption. Ohms law states that with a 4 amp current flowing through this resistor, a 0.4 volt drop will be developed across its terminals. Since the error amplifier of the SG 3524 IC works best when the input voltages are between 1.8 to 3.4 volts, the 0.4 volt drop sampled across the current sensing resistor will be amplified six times by the LM 324 single supply op-amp. This amplified signal will then be fed into pin 1 of the SG 3524 as described in the first paragraph of this section.



Interface

Control signals which are sent to the stepper interface can follow many conventions. Typically commercial units follow the convention of step and direction signals however EMC2 also supports phase output. Phase control consists of four phase signals which when connected to the corresponding motor windings provides proper forward and reverse step control. Traditionally four signals would require the employment of four pins from the parallel I/O port, however, since phase signals C and D are simply inverses of phase signals A and B respectively, phases signals A and B can be sent to the interface exclusively. The hardware in the interface can then recreate phase signals C and D from these two signals using simple digital inverters. The phase relationship is depicted graphically in the figure below (Figure 1.2).


Figure 1.2 - Four phase step control.


Sending only two signals to the interface ties up fewer parallel I/O pins which can subsequently be used to carry other signals such as rotary table control, table limit detection, etc. Interestingly most digital inverters come in a 14 pin hex-inverter package. This provides the necessary two inverters for phase C and D recreation with four inverters remaining unused. These unused inverters can be wired in groups of two connected in series to provide a logical buffer. These two buffers can be used to buffer the inputs of phases A and B. With all the phases now available and buffered, only output to the power N-channel MOSFETs needs consideration.

As discussed in the current supply section, MOSFET transistors often have a drain-to-source breakdown voltage which is many times greater than their corresponding gate-to-source breakdown voltage. This is again the case with the selected N-channel phase signal power MOSFETs. The N-channel MOSFETs, model STP100NF04 have a drain-to-source breakdown voltage of over 40 volts but a gate-to-source breakdown voltage of less than 20 volts. To meet this criteria, the inverter selected is an LM 7406 which has open collector high voltage outputs. The gates of the power FETs can therefore be “pulled up” to any desired value using external pull-up resistors.



Operation

All operational testing was performed using a bread-boarded implementation of the circuit in Figure C.1. While breadboards provide a quick method for wiring up small circuits, their contacts are not designed to handle currents in excess of about 1 amp. As a result, all of the high current components of the circuit (the power P-Channel MOSFET, the power inductor, the 1000uF capacitor, R-shunt, and the load) have been soldered directly to 14-gauge solid conductor wire in a “not so elegant” fashion. While not aesthetically pleasing, these heavy conductors provide very low resistance current paths resulting in minimal forward voltage drops across the conductors. The complete circuit is shown below in Figure 1.3.


Figure 1.3 - Complete circuit implementation.



To eliminate the risk of damaging one of the stepper motors during circuit testing, a 1-Ohm power resistor has been substituted as the motor load. This can be seen in the bottom right of the above figure. Also note that the current supply is fully energized and operational in this photo providing a regulated current of almost exactly 4 amps as seen displayed on the red ammeter. Referring to Figure 1.4, which is simply a closeup of the components contained in Figure 1.3, the separated boards/circuits roughly correspond to (from right to left) the LC circuit and P-channel MOSFET, the small signal transistors which drive the gate of the power MOSFET, the operational amplifier which boosts the measured voltage across R-shunt, and the original printed circuit board which still contains PWM IC and computer interface.


Figure 1.4 - Closeup of the complete circuit implementation.



The printed circuit board was created based on the circuit in Figure C.1. Unfortunately the completed circuit did not initially function correctly which drove the need to remove some parts from the board and add additional components to external breadboards. Note that the all circuit changes have already been made to the schematic of Figure C.1. Now that the design is fully functional, a new PC board was created with the trace pattern shown below (which was modified to contain the new components).


Figure 1.5 - PC trace layout for the final implementation.



As discussed in the Current Supply section of this page, pulse width modulation was the selected method of operation. The figure below illustrates the correct operation of the PWM IC. The top trace is the clock signal of the SG 3524 taken directly from pin 3. The bottom trace shows the pulse width modulated output which feeds the gate of the power transistor.



Figure 1.6 - SG 3524 Operational waveforms.


Note that the power transistor which receives this signal is a P-channel MOSFET. This means that the transistor is in conduction when the signal is low and in cutoff when the signal is high. The relatively short duration pulses (bottom trace) indicate that for the purely resistive load being tested, the rail voltages are much higher then that which is required to develop the required four amp load current. It also indicates that the system is capable of driving the load at a much higher voltage when required. This is the exact condition required to combat the motors back EMF as discussed in the introduction.

The actual mill which will ultimately be fully controlled by this system is shown in Figure 1.7. Note that a stepper motor has already been installed on the x-axis. The x-axis is therefore the only axis which has been used for testing, however, all other axis will soon also be controlled by an identical set of stepper motors and controllers (see Next page: Page 2 - CNC Mill Results for complete implementation of all three axis). Figure 1.8 shows a closeup of the installed stepper motor. Figure 1.9 shows a loose stepper motor displaying its type, current specification and step angle. As seen in the figure, the selected stepper motors have a step angle of 1.8 degrees/step. This provides a step resolution of 200 steps per revolution, which with the supplied 0.100 inch/revolution lead screws provides 0.0005 inchs/step. Additional accuracy can also be obtained by setting up the control software to make half steps resulting in 400 discrete steps per revolution.


Figure 1.7 - Mill.




Figure 1.8 - Installed stepper (x-axis).



Figure 1.9 - Selected stepper motor.




Figure C.1 - Current supply, controller and interface schematic.





Next page:  Page 2 - CNC Mill Results









Subpages (1): - CNC Mill Results -