Internet Windows Android

CNC milling machine with offline controller on STM32. The choice of the controller for controlling stepper motors, engraving, milling, lathes, foam cutters Micro nc controller standalone cnc

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

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

Controller management using specialized or or Linux EMC2 and others installed on a PC. It is recommended to use a computer with at least 1GHz processor and 1GB memory. A desktop computer gives better results than laptops and is much cheaper. In addition, you can use this computer for other jobs when it is not busy operating your machine. When installing on a laptop or PC with 512MB of memory, it is recommended to run the .

The LPT parallel port is used to connect to a computer (for a controller with a USB interface, the 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 aluminum engraving and milling machine CNC-2020AL, complete with a control unit with the ability to adjust the spindle speed, Figure 1 and 2, the control unit contains a stepper motor driver on a TB6560AHQ chip, stepper motor driver power supplies and a spindle power supply.

picture 1

Figure 2

1. One of the first CNC milling machine controllers based on the TB6560 chip was nicknamed the "blue board", Figure 3. This board option has been discussed a lot on the forums, it has a number of disadvantages. The first is slow PC817 optocouplers, which requires, when setting up the MACH3 machine control program, to enter the maximum allowable value in the Step pulse and Dir pulse = 15 fields. The second is poor matching of the optocouplers outputs with the inputs of the TB6560 driver, which is solved by finalizing the circuit, Figure 8 and 9. Third - Linear power supply regulators of the board and, as a result, a large overheating, switching regulators are used on subsequent boards. Fourth - the lack of galvanic isolation of the power circuit. Spindle relay 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 the control panel. This controller does not apply.

Figure 3

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

More high-frequency (fast) 6N137 optocouplers are used here. Spindle relay 10A. The presence of galvanic isolation for power supply. There is a connector for connecting the driver of the fourth axis. 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 result, the size of the radiator is also smaller.

Figure 5

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

Figure 6

5. 4 axis controller of CNC router, 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 machine controller on the stepper motor driver from Allegro A3977, Figure 8.

Figure 8

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

Figure 9

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

Figure 10.

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

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

Device options

Multi-channel controllers of stepper motors (stepping motors) with 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 size of 86 mm is needed. It can be controlled using a single-channel driver (control current exceeding 4.2 A).

To control a machine with numerical control, in particular, it is possible with a controller created on the basis of specialized microcircuits - drivers intended for use for stepper motors 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 1GHz and a memory capacity of 1 GB). With a smaller volume, the system is optimized.

NOTE! If compared with a laptop, then in the case of connecting a stationary computer - the best results, and it is cheaper.

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

Excursion into history

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

  • The first controller on the chip was conditionally called the "blue board". This option has drawbacks and the scheme needed to be improved. The main advantage is that there is a connector, and the control panel was connected to it.
  • Following the blue, a controller appeared, called the "red board". It already used fast (high-frequency) optocouplers, a 10A spindle relay, power decoupling (galvanic) and a connector where fourth-axis drivers would be connected.
  • Another similar device with a red marking was also used, but more simplified. With its help, it was possible to control a small desktop-type machine - from among the 3-axis ones.

  • The next in the line of technical progress was a controller with galvanic power isolation, fast optocouplers and special capacitors, which has an aluminum case 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 home-made 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 stepper motor by using large and high speed.


Scrap controller

Most DIYers 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 improvised materials - field-effect transistors from burnt motherboards (at a voltage of over 30 volts and a current of more than 2 amperes).

And since a machine was created for cutting foam plastic, the inventor used automobile incandescent lamps as a current limiter, and SD was removed from old printers or scanners. Such a controller was installed without changes in the circuit.

To make the simplest CNC machine with your own hands, by disassembling the scanner, in addition to the stepper motor, the ULN2003 chip and two steel bars are also removed, they will go to the test portal. In addition, you will need:

  • Cardboard box (the device body will be assembled from it). A variant with textolite or plywood sheet is possible, but cardboard is easier to cut; pieces of wood;
  • tools - in the form of wire cutters, scissors, screwdrivers; glue gun and soldering accessories;
  • a board option that is suitable for a 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

When starting to work on a homemade CNC controller, the first step is to carefully solder the chip onto a breadboard with two power rails. Next, the connection of the ULN2003 output and the LPT connector will follow. Next, the remaining conclusions are connected according to the scheme. The zero pin (25th parallel port) is connected to the negative pin on the board's power bus.

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

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

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

  • Steel rods are inserted into holes drilled at the same level in three wooden bars and fixed with small screws.
  • SD is connected to the second bar, putting it on the free ends of the rods and screwed using screws.
  • A lead screw is threaded through the third hole and a nut is placed. The screw inserted into the hole of the second bar is screwed up to the stop so that, having passed through these holes, it goes out onto the motor shaft.
  • Next, the rod is connected to the motor shaft with a piece of rubber hose and a wire clamp.
  • Additional screws are required to secure the nut.
  • The made stand is also attached to the second bar with screws. The horizontal level is adjusted with additional screws and nuts.
  • Usually motors are connected together with controllers and tested for correct connection. This is followed by checking the scaling of the CNC, running the test program.
  • It remains to make the body of the device and this will be the final stage of the work of those who create home-made machines.

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

Attention! Using the 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 the full version of his board (Appendix 2), the axis currents are regulated by an external hardware PWM.

Conclusion

In controllers assembled by CNC machines - a wide range of uses: in plotters, small milling machines 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 produce printed circuit boards. So the effort spent on assembly by craftsmen will definitely pay off in the future controller.

1. Appearance of the board

1 - SLOT for SD card;

2 - start button;

3 - manual control joystick;

4 - LED (for X and Y axes);

5 LED (for Z axis);

6 - conclusions for the spindle power button;

8 - low level outputs (-GND);

9 - high level outputs (+5v);

10 - pins for 3 axes (Xstep, Xdir, Ystep, Ydir, Zstep, Zdir) 2 pins for each;

11 - pins of the LPT connector (25 pins);

12 - LPT connector (female);

13 - USB connector (only for power supply + 5v);

14 and 16 - spindle frequency control (PWM 5 V);

15 - GND (for spindle);

17 - output for ON and OFF of the spindle;

18 - spindle speed control (analogue from 0 to 10 V).

When connected to a ready-made board with drivers for a 3-axis CNC that has an LPT output:

Install jumpers between 10 pins and 11 pins.

Pins 8 and 9 from 11, they are needed if additional enable and disable pins are allocated for the drivers (there is no specific standard, so it can be any combination, you can find them in the description, or by typing :) -)

When connected to individual drivers with motors:

Install jumpers between the 10 pins Step, Dir of the "RFF" board and Step, Dir of your drivers. (do not forget to supply power to drivers and motors)

Turn on "RFF" in the network. Two LEDs will light up.

Insert a formatted SD card into LOT 1. Press RESET. Wait until the right LED lights up. (About 5 sec) Remove the SD card.

A text file named "RFF" will appear on it.

Open this file and enter the following variables (Here in this form and sequence):

Example:

V=5 D=8 L=4.0 S=0 Dir X=0 Dir Y=1 Dir Z=1 F=600 H=1000 UP=0

V - conditional value from 0 to 10 of the initial speed during acceleration (acceleration).

Command Explanations

D - pitch splitting set on motor drivers (should be the same on all three).

L is the length of the passage of the carriage (gantry), with one revolution of the stepper motor in mm (it should be the same on all three). Insert the rod from the handle instead of the cutter and manually scroll the motor one full turn, this line will be the value L.

S - what signal turns on the spindle, if 0 means - GND if 1 means + 5v (you can choose empirically).

Dir X, Dir Y, Dir Z, the direction of movement along the axes, can also be selected empirically by setting 0 or 1 (it will become clear in manual mode).

F - idle speed (G0), if F=600, then the speed is 600mm/sec.

H - the maximum frequency of your spindle (needed to control the spindle frequency using PWM, let's say if H=1000, and S1000 is written in the G-code, then the output at this value will be 5v, if S500 then 2.5 v, etc., variable S in G-code must not be greater than H in SD.

The frequency at this pin is about 500 Hz.
UP - stepper motor driver control logic, (there is no standard, it can be both high + 5V and low -) set 0 or 1. (it works for me anyway. -)))

The controller itself

See video: 3-axis CNC control board

2. Preparation of the control program (G_CODE)

The board was developed under ArtCam, so the control program must be with an extension. TAP (remember to put in mm, not inches).
The G-code file saved on the SD card must be named G_CODE.

If you have a different extension, such as CNC, then open your file with notepad and save it as G_CODE.TAP.

x, y, z in the G-code must be capitalized, the dot must be a dot, not a comma, and even an integer must be with 3 zeros after the dot.

Here it is in this form:

X5.000Y34.400Z0.020

3. Manual control

Manual control is carried out using the joystick, if you have not entered the variables in the settings specified in paragraph 1, "RFF" board
will not work even in manual mode!
To switch to manual mode, press the joystick. Now try to manage it. Looking at the board from above (SLOT 1 at the bottom,
12 LPT connector at the top).

Forward Y+, backward Y-, right X+, left X-, (if the move is wrong in the Dir X, Dir Y settings, change the value to the opposite).

Press the joystick again. The 4th LED will light up, which means you have switched to control the Z axis. Joystick up - spindle
should go up Z+, joystick down - go down Z- (in case of wrong move in Dir Z settings, change the value
to the opposite).
Lower the spindle until the cutter touches the workpiece. Press the start button 2, now this is the zero point from here the execution of the G-code will begin.

4. Offline operation (Perform G-code cutting)
Press button 2 again, with a slight hold.

After releasing the button, the "RFF" board will begin to control your CNC machine.

5. Pause mode
Briefly press button 2 while the machine is running, cutting will stop and the spindle will rise 5mm above the workpiece. Now you can control the Z axis both up and down, do not be afraid to even delve into the workpiece, because after pressing button 2 again, cutting will continue from the paused value along Z. In the pause state, turning off and turning on the spindle with button 6 is available. X and Y axes in Pause mode cannot be controlled.

6. Emergency stop of work with the spindle moving to zero

By holding button 2 for a long time during autonomous operation, the spindle will rise 5 mm above the workpiece, do not release the button, 2 LEDs will start blinking alternately, the 4th and 5th, when the blinking stops, release the button and the spindle will move to the zero point. Pressing button 2 again will execute the job from the very beginning of the G-code.

Supports commands such as G0, G1, F, S, M3, M6 to control the spindle speed. There are separate outputs: PWM from 0 to 5V and the second analog from 0 to 10V.

Accepted command format:

X4.000Y50.005Z-0.100 M3 M6 F1000.0 S5000

Lines do not need to be numbered, spaces should not be set, F and S should be indicated only when changing.

Small example:

T1m6 G0Z5.000 G0x0.000Y0.000S50000M3 G0x17.608y58.073z5.000 G1Z-0.600F1000.0 G1X17.606Y58.132F1500.0 x17.599y58.363 x17.597y58.476 x17.603y58.707 x17.6058.707 x17.6058.748

Demonstration of the RFF controller

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

I tried to write only those moments that personally seemed important to me.

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

History of creation

Regularly faced with the need to make one or another small “thing” of complex shape, I initially thought about a 3D printer. And even started doing it. But after reading the forums and evaluating the speed of the 3D printer, the quality and accuracy of the result, the percentage of rejects and the structural properties of thermoplastics, I realized that this is nothing more than a toy.

The order for components from China came in a month. And after 2 weeks the machine was working with control from LinuxCNC. Collected from any garbage that was at hand, because I wanted to 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.

The initial operation of the machine showed that:

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

Controller Development

I created the program after a thoughtful review of the sources of LinuxCNC and gbrl. However, neither those nor those source codes for calculating the trajectory were taken. 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 the firmware has not been touched for a long time.
Maximum speed selected experimentally: X:2000mm/min Y:1600 Z:700 (1600 step/mm. mode 1/8).
But it is not limited by controller resources. Just above the already nasty sound of skipping steps even straight stretches through the air. The budget Chinese stepper control board on the TB6560 is not the best option.
In fact, the speed on wood (beech, 5mm depth, d = 1mm cutter, step 0.15mm) is not more than 1200 mm. Increases the risk of cutter breakage.

The result is a controller with the following functionality:

  • Connecting to an external computer as a standard usb mass storage device (FAT16 on SD card). Working with standard G-code format files
  • Deleting files through the controller's user interface.
  • Viewing the trajectory for the selected file (as far as the 640x320 screen allows) and calculating the execution time. In fact, emulation of execution with the summation of time.
  • View the contents of files in a test form.
  • Manual control mode from the keyboard (moving and setting "0").
  • Starting the task for the selected file (G-code).
  • Pause/resume execution. (sometimes useful).
  • Emergency software stop.
The controller will be connected to the stepper control board through the same LPT connector. Those. it acts as a control computer with LinuxCNC/Mach3 and is interchangeable with it.

After creative experiments on carving hand-drawn reliefs on a tree, and experiments with acceleration settings in the program, I also wanted encoders on the axes. Just on e-bay I found relatively cheap optical encoders (1/512), the pitch of which for my ball screws was 5/512 = 0.0098mm.
By the way, the use of high-resolution optical encoders without a hardware scheme for working with them (the STM32 has it) is pointless. Neither interrupt processing, nor, moreover, a software poll will ever cope with the “bounce” (I say 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 application for them, albeit in a rather narrow task.

Using encoders to correct the path of a machine tool with stepper motors

I noticed that when cutting out the 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 relief cutting time with this acceleration is 20% less. At the end of the cutting of the 17x20 cm relief with a step of 0.1 mm, the cutter can go down by 1-2 mm from the calculated trajectory.
An analysis of the situation in dynamics by encoders showed that when the cutter is raised, sometimes 1-2 steps are 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 a tree is difficult to notice.

Design


The ideal option for hobby purposes was the desktop version with a field slightly larger than A4. And I still have enough of it.

movable table

It still remains a mystery to me why everyone chooses a design with a movable portal for desktop machines. Its only advantage is the ability to process a very long board in parts or, if you have to process material on a regular basis, the weight of which is greater than the weight of the portal.

During the entire period of operation, there has never been a need to cut out the relief on a 3-meter board in parts or make an engraving on a stone slab.

The sliding table has the following advantages for desktop machines:

  1. The design is simpler and, in general, the design is more rigid.
  2. All giblets (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 mass of the table and a piece of typical material for processing is significantly lower than the mass of the portal and spindle.
  4. The problem with the cables and hoses of the water cooling of the spindle 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 power metalworking machine and a high-speed wood/plasticsworking machine are completely different types of equipment.

To create a universal machine at home at least does not make sense.

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

For a typical high speed spindle (20,000 rpm), milling non-ferrous metals (not even talking about steel) is an extreme mode for the spindle. Well, unless it is very necessary, and then I will eat 0.3 mm per pass with watering the coolant.
The spindle for the machine would recommend water-cooled. With it, only the “singing” of stepper motors and the gurgling of the aquarium pump in the cooling circuit are heard during operation.

What can be done on such a machine

First of all, the problem of cases went away for me. The case of any shape is milled from "plexiglas" and glued together with a solvent along ideally smooth cuts.

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

Woodworking (reliefs, etc.) - a wide scope for the realization of their creative impulses, or, at least, for the implementation of other people's impulses (ready-made models).

But I haven't tried jewelry. There is nowhere to ignite / melt / pour the flasks. Although a bar of jewelry wax is waiting in the wings.