Homemade CNC machine control via USB. Selecting a controller for controlling stepper motors, engraving, milling, lathes, and foam cutters. Explanations of commands

Homemade CNC machine control via USB.  Selecting a controller for controlling stepper motors, engraving, milling, lathes, and foam cutters.  Explanations of commands
Homemade CNC machine control via USB. Selecting a controller for controlling stepper motors, engraving, milling, lathes, and foam cutters. Explanations of commands

For self-assembly milling machine you need to select a CNC control controller. Controllers are available as multi-channel: 3 and 4 axis stepper motor controllers, and single-channel. Multichannel controllers are most often found to control small stepper motors, standard size 42 or 57mm (nema17 and nema23). Such motors are suitable for self-assembly of CNC machines with a working field of up to 1 m. When independently assembling a machine with a working field of more than 1 m, you should use stepper motors of standard size 86mm (nema34); to control such motors you will need powerful single-channel drivers with a control current of 4.2A and higher.

To control desktop milling machines, controllers based on specialized SD driver microcircuits are widely used, for example, TB6560 or A3977. This chip contains a controller that generates the correct sine wave for different modes half-step and has the ability to programmatically set winding currents. These drivers are designed to work with stepper motors up to 3A, motor sizes NEMA17 42mm and NEMA23 57mm.

Controlling the controller using specialized or Linux EMC2 and others installed on a PC. It is recommended to use a computer with a processor frequency of at least 1 GHz and 1 GB memory. A desktop computer gives top scores, compared to laptops and much cheaper. In addition, you can use this computer for other tasks when it is not busy controlling your machine. When installing on a laptop or PC with 512MB memory, it is recommended to carry out.

To connect to a computer, use a parallel LPT port (for a controller with a USB interface USB port). If your computer is not equipped with a parallel port (more and more computers are being released without this port), you can purchase a PCI-LPT or PCI-E-LPT port expander card or a specialized USB-LPT controller-converter that connects to the computer via a USB port .

With a desktop engraving and milling machine made of aluminum CNC-2020AL, complete with a control unit with the ability to adjust spindle speed, Figure 1 and 2, the control unit contains a stepper motor driver on a TB6560AHQ chip, power supplies for the stepper motor driver and a spindle power supply.

picture 1

Figure 2

1. One of the first control controllers for CNC milling machines on the TB6560 chip was nicknamed “blue board”, Figure 3. This version of the board was discussed a lot on the forums, it has a number of disadvantages. The first is slow optocouplers PC817, which requires, when setting up the machine control program MACH3, to enter the maximum permissible value in the fields Step pulse and Dir pulse = 15. The second is poor matching of the outputs of the optocouplers with the inputs of the TB6560 driver, which can be solved by modifying the circuit, Figure 8 and 9. The third is the linear regulators of the board's power supply and, as a result, there is a lot of overheating; on subsequent boards, pulse stabilizers are used. The fourth is the lack of galvanic isolation of the power supply circuit. The spindle relay is 5A, which in most cases is not enough and requires the use of a more powerful intermediate relay. The advantages include the presence of a connector for connecting a control panel. This controller is not used.

Figure 3.

2. The CNC machine control controller entered the market after the “blue board”, nicknamed the red board, Figure 4.

Higher frequency (fast) optocouplers 6N137 are used here. Spindle relay 10A. Availability of galvanic isolation for power supply. There is a connector for connecting the fourth axis driver. Convenient connector for connecting limit switches.

Figure 4.

3. The stepper motor controller marked TB6560-v2 is also red, but simplified, there is no power decoupling, Figure 5. Small size, but as a consequence of this smaller size radiator

Figure 5

4. Controller in an aluminum case, Figure 6. The case protects the controller from dust and metal parts; it also serves as a good heat sink. Galvanic isolation for power supply. There is a connector for powering additional +5V circuits. Fast optocouplers 6N137. N low-impedance and Low ESR capacitors. There is no relay for controlling the spindle turning on, but there are two outputs for connecting a relay (transistor switches with OK) or PWM for controlling the spindle rotation speed. Description of connecting relay control signals on the page

Figure 6

5. 4-axis controller of a CNC milling and engraving machine, USB interface, Figure 7.

Figure 7

This controller does not work with the MACH3 program; it comes with its own machine control program.

6. CNC controller of the machine on the SD driver from Allegro A3977, Figure 8.

Figure 8

7.Single-channel stepper motor driver for CNC machine DQ542MA. This driver can be used when self-production a machine with a large working field and stepper motors with a current of up to 4.2A, can also work with Nema34 86mm motors, Figure 9.

Figure 9

Photo of the modification of the blue stepper motor controller board on the TB6560, Figure 10.

Figure 10.

Scheme for fixing the blue stepper motor controller board on the TB6560, Figure 11.

Since I assembled a CNC machine for myself a long time ago and have been using it regularly for hobby purposes for a long time, I hope my experience will be useful, as will the source codes of the controller.

I tried to write only those points that I personally found important.

The link to the controller sources and the configured Eclipse+gcc shell, etc. are located in the same place as the video:

History of creation

Regularly faced with the need to do one or another small “little thing” complex shape, initially thought about a 3D printer. And he even started doing it. But I read the forums and assessed the speed of the 3D printer, the quality and accuracy of the result, the percentage of defects and the structural properties of thermoplastic, and I realized that this is nothing more than a toy.

The order for components from China arrived within a month. And after 2 weeks the machine was working with LinuxCNC control. I assembled it from whatever crap I had at hand, because I wanted to do it quickly (profile + studs). I was going to redo it later, but, as it turned out, the machine turned out to be quite rigid, and the nuts on the studs did not have to be tightened even once. So the design remained unchanged.

Initial operation of the machine showed that:

  1. Do not use a “china noname” 220V drill as a spindle best idea. It overheats and is terribly loud. The lateral play of the cutter (bearings?) can be felt by hand.
  2. The Proxon drill is quiet. The play is not noticeable. But it overheats and turns off after 5 minutes.
  3. A borrowed computer with a bidirectional LPT port is not convenient. Borrowed for a while (finding PCI-LPT turned out to be a problem). Takes up space. And generally speaking..
After initial use, I ordered a water-cooled spindle and decided to make a controller for battery life on the cheapest version STM32F103, sold complete with a 320x240 LCD screen.
Why do people still stubbornly torment 8-bit ATMega for relatively complex tasks, and even via Arduino is a mystery to me. They probably love difficulties.

Controller development

I created the program after thoughtfully reviewing the LinuxCNC and gbrl sources. However, I did not take either of the sources for calculating the trajectory. I wanted to try to write a calculation module without using float. Exclusively on 32-bit arithmetic.
The result suits me for all operating modes and I haven’t touched the firmware for a long time.
Maximum speed, selected experimentally: X: 2000 mm/min Y: 1600 Z: 700 (1600 step/mm. mode 1/8).
But it is not limited by controller resources. It’s just that the disgusting sound of skipping steps even on straight sections through the air is higher. The budget Chinese stepper control board on the TB6560 is not the best option.
In fact, I don’t set the speed for wood (beech, 5mm depth, d=1mm cutter, step 0.15mm) to more than 1200mm. The likelihood of cutter failure increases.

The result is a controller with the following functionality:

  • How to connect to an external computer standard usb mass storage device (FAT16 on SD card). Working with standard G-code files
  • Deleting files via user interface controller.
  • View the trajectory of the selected file (as far as the 640x320 screen allows) and calculate the execution time. In fact, emulation of execution with time summation.
  • View the contents of files in test form.
  • Mode manual control from the keyboard (moving and setting “0”).
  • Start execution of a task using the selected file (G-code).
  • Pause/resume execution. (sometimes useful).
  • Emergency software stop.
The controller will be connected to the stepper control board via the same LPT connector. Those. it acts as a control computer with LinuxCNC/Mach3 and is interchangeable with it.

After creative experiments in cutting out hand-drawn reliefs on wood, and experiments with acceleration settings in the program, I also wanted additional encoders on the axes. Just on e-bay I found relatively cheap optical ecocoders (1/512), the division pitch of which for my ball screws was 5/512 = 0.0098 mm.
By the way, the use of optical encoders high resolution, without a hardware circuit for working with them (the STM32 has it) is pointless. Neither interrupt processing, nor, especially, software polling will ever cope with the “bounce” (I’m saying this for ATMega fans).

First of all, I wanted for the following tasks:

  1. Manual positioning on the table with high precision.
  2. Control of missed steps with control of deviation of the trajectory from the calculated one.

However, I found another use for them, albeit in a rather narrow task.

Using encoders to correct the trajectory of a machine with stepper motors

I noticed that when cutting out a relief, when setting the acceleration in Z to more than a certain value, the Z axis begins to slowly but surely creep down. But, the time for cutting relief with this acceleration is 20% less. Upon completion of cutting out a 17x20 cm relief with a step of 0.1 mm, the cutter can go down 1-2 mm from the calculated trajectory.
Analysis of the situation in dynamics using encoders showed that when lifting the cutter, 1-2 steps are sometimes lost.
A simple step correction algorithm using an encoder gives a deviation of no more than 0.03 mm and reduces processing time by 20%. And even a 0.1 mm protrusion on wood is difficult to notice.

Design


I considered the desktop version with a margin slightly larger than A4 to be an ideal option for hobby purposes. And this is still enough for me.

Movable table

It still remains a mystery to me why everyone chooses a design with a movable portal for tabletop machines. Its only advantage is the ability to process a very long board in parts or, if you have to regularly process material that weighs more than the weight of the portal.

During the entire period of operation, there was never a need to cut out a relief piece by piece on a 3-meter board or engrave on a stone slab.

The movable table has the following advantages for tabletop machines:

  1. The design is simpler and, in general, the structure is more rigid.
  2. All the internals (power supplies, boards, etc.) are hung on a fixed portal and the machine turns out to be more compact and more convenient to carry.
  3. The weight of the table and a piece of typical material for processing is significantly lower than the weight of the portal and spindle.
  4. The problem with cables and spindle water cooling hoses practically disappears.

Spindle

I would like to note that this machine is not for power processing. The easiest way to make a CNC machine for power processing is on the basis of a conventional milling machine.

In my opinion, a machine for power processing of metal and a machine with a high-speed spindle for processing wood/plastics are absolutely perfect different types equipment.

Create conditions at home universal machine at least it makes no sense.

Selecting a spindle for a machine with this type of ball screw and guides with linear bearings unambiguous This is a high speed spindle.

For a typical high-speed spindle (20,000 rpm), milling non-ferrous metals (steel is out of the question) is an extreme mode for the spindle. Well, unless it’s really necessary and then I’ll eat 0.3 mm per pass with watering the coolant.
I would recommend a water-cooled spindle for the machine. With it, during operation, you can only hear the “singing” of the stepper motors and the gurgling of the aquarium pump in the cooling circuit.

What can be done on such a machine?

First of all, I got rid of the housing problem. The body of any shape is milled from “plexiglass” and glued together with a solvent along ideally smooth cuts.

Fiberglass refused universal material. The precision of the machine allows you to cut seat under the bearing, into which it will go cold, as it should be, with a slight tension, and then you can’t pull it out. Textolite gears are perfectly cut with an honest involute profile.

Wood processing (reliefs, etc.) is a wide scope for the realization of one’s creative impulses, or, at a minimum, for the realization of other people’s impulses (ready-made models).

I just haven’t tried the jewelry. There is no place to calcinate/melt/cast the flasks. Although a block of jewelry wax is waiting in the wings.

Among the wide variety of controllers, users are looking for those circuits that will be acceptable and most effective for self-assembly. Both single-channel and multi-channel devices are used: 3- and 4-axis controllers.

Device options

Multi-channel stepper motor controllers (stepper motors) with standard sizes of 42 or 57 mm are used in the case of a small working field of the machine - up to 1 m. When assembling a machine with a larger working field - over 1 m, a standard size of 86 mm is needed. It can be controlled using a single-channel driver (control current exceeding 4.2 A).

Control the machine with numerical control program controlled, in particular, it is possible with a controller created on the basis of specialized driver microcircuits intended for use for SD up to 3A. The CNC controller of the machine is controlled by a special program. It is installed on a PC with a processor frequency of over 1 GHz and a memory capacity of 1 GB). With a smaller volume, the system is optimized.

NOTE! If compared with a laptop, then if connected desktop computer- better results, and it costs less.

When connecting the controller to a computer, use a USB or LPT parallel port connector. If these ports are not available, then expander boards or controller converters are used.

Excursion into history

The milestones of technological progress can be schematically outlined as follows:

  • The first controller on the chip was conventionally called the “blue board”. This option has disadvantages and the scheme required improvement. The main advantage is that there is a connector, and the control panel was connected to it.
  • Following the blue one, a controller called the “red board” appeared. It already used fast (high-frequency) optocouplers, a 10A spindle relay, power isolation (galvanic) and a connector where the fourth axis drivers would be connected.
  • Another similar device with red markings was also used, but more simplified. With its help, it was possible to control a small desktop type machine - one of the 3-axis ones.

  • The next in the line of technological progress was a controller with galvanic isolation for power supply, fast optocouplers and special capacitors, having an aluminum housing that provided protection from dust. Instead of a control relay that would turn on the spindle, the design had two outputs and the ability to connect a relay or PWM (pulse width modulation) speed control.
  • Now, for the manufacture of a homemade milling and engraving machine with a stepper motor, there are options - a 4-axis controller, a stepper motor driver from Allegro, a single-channel driver for a machine with a large working field.

IMPORTANT! Do not overload the motor by using higher and higher speeds.


Controller made from scrap materials

Most craftsmen prefer control via the LPT port for most amateur-level control programs. Instead of using a set of special microcircuits for this purpose, some people build a controller from scrap materials - field effect transistors from the burnt motherboards(at a voltage of over 30 volts and a current of more than 2 amperes).

And since a machine was being created for cutting foam plastic, the inventor used car incandescent lamps as a current limiter, and SDs were removed from old printers or scanners. This controller was installed without changes to the circuit.

To do the simplest machine Do-it-yourself CNC, when disassembling the scanner, in addition to the SD, the ULN2003 chip and two steel rods are removed, they will go to the test portal. In addition you will need:

  • A cardboard box (from which the device body will be mounted). Possible option with textolite or plywood sheet, but cardboard is easier to cut; pieces of wood;
  • tools - in the form of wire cutters, scissors, screwdrivers; glue gun and soldering accessories;
  • board option that fits homemade CNC machine;
  • connector for LPT port;
  • a cylinder-shaped socket for arranging a power supply;
  • connection elements - threaded rods, nuts, washers and screws;
  • program for TurboCNC.

Assembling a homemade device

Having started working on a homemade CNC controller, the first step is to carefully solder the chip onto breadboard with two power buses. Next will be the connection of the ULN2003 output and the LPT connector. Next, we connect the remaining pins according to the diagram. The zero pin (25th parallel port) is connected to the negative pin on the board's power bus.

Then the motor is connected to the control device, and the power supply socket is connected to the corresponding bus. To ensure the reliability of the wire connections, they are fixed with hot glue.

Connecting Turbo CNC will not be difficult. The program is effective with MS-DOS and is also compatible with Windows, but in this case some errors and failures are possible.

Having configured the program to work with the controller, you can make a test axis. The sequence of actions for connecting the machines is as follows:

  • In holes drilled at the same level in three wooden blocks, insert steel rods and secure with small screws.
  • The SD is connected to the second bar, putting it on the free ends of the rods and screwing it using screws.
  • The lead screw is threaded through the third hole and a nut is installed. The screw inserted into the hole of the second bar is screwed in until it stops so that it passes through these holes and comes out onto the motor shaft.
  • Next, you need to connect the rod to the engine shaft with a piece of rubber hose and a wire clamp.
  • Additional screws are required to secure the running nut.
  • The made stand is also attached to the second block using screws. The horizontal level is adjusted with additional screws and nuts.
  • Usually, motors are connected along with controllers and tested for correct connection. This is followed by checking the CNC scaling and running a test program.
  • All that remains is to make the body of the device and this will be the final stage of the work of those who create homemade machines.

When programming the operation of a 3-axis machine, there are no changes in the settings for the first two axes. But when programming the first 4 phases of the third, changes are introduced.

Attention! Using a simplified diagram of the ATMega32 controller (Appendix 1), in some cases you may encounter incorrect processing of the Z axis - half-step mode. But in full version its boards (Appendix 2), axes currents are regulated by external hardware PWM.

Conclusion

In controllers, assembled CNC machines - a wide range of uses: in plotters, small milling cutters, working with wood and plastic parts, steel engravers, miniature drilling machines.

Devices with axial functionality are also used in plotters; they can be used to draw and make printed circuit boards. So the efforts spent on assembly by craftsmen will definitely pay off in the future controller.