There is a DC motor. The task is to develop, assemble and test a device that allows the implementation of a current loop in relation to this motor. The desired transient time for a stopped motor (without back-EMF) is no more than 10 ms. The communication interface with the external control controller is SPI. DC motor, commutator, maximum voltage 24V, operating current up to 5A.
What does current loop mean? The most common drivers for controlling motors are all sorts of variations of half-bridges that amplify the voltage. But I want the driver to take current, not voltage, into the input. The force developed by the electric drive is directly proportional to the strength of the current flowing. This means that it is directly proportional to the acceleration on the engine shaft. Such a current circuit will allow you to avoid perversions that you need to go through without it, as I did here.
I have divided this text into two articles:
- 1. Motor resistance and inductance measurement
- 2. Development of the control circuit
This is what the layout of the control hardware looks like:
The system will include:
- A power key chip that receives an input PWM signal and amplifies it.
- Current sensor.
- A control microcontroller that implements feedback and control law.
Current sensor and its testing
The Allegro ACS714 ($3) Hall sensor was selected as a current sensor, producing an analog signal centered at 2.5V and 185mV/A, typical error 1.5%.
An RC circuit was added to the sensor as a low pass filter with a cutoff frequency of 16kHz. The current sensor was powered from a 4.96V source; a resistor was connected in series with the sensor, through which 2A was passed. The theoretical voltage at the output pin should be 4.96/2 + (2 * 0.185 +- 1.5%), the measurement showed 2.84 V, which fits within the calculated parameters. Then the direction of current flow through the resistor was changed, at -2A the measured voltage at the output pin of the sensor was 2.11V, which again fits into the calculated parameters:
This check was necessary because... I bought several breadboards with ACS712 and ACS714 from different manufacturers, and only one was included in the datasheet parameters!
Winding resistance: classification of machines, structure of motors
Electrical machines used in everyday life and in production are classified. There are generators, electric motors that convert electricity into mechanical energy, and specialized machines that convert one type of energy into another. The task of the former is to convert mechanical into electrical energy.
According to their design, electric motors are either commutator or brushless. The first are electric machines that use direct current, i.e. they can be used as generator sets. Much less often they are used to work with direct current - single-phase units of low power. Brushless electric motors are power machines that, in most cases, operate exclusively on alternating current. Based on the principle of action they are divided into:
- asynchronous motors - the main specificity of operation is notable for their use as electric motors;
- synchronous motors - they are used both as generators and as electric motors.
The nameplate located on the motor housing indicates the nominal technical characteristics, winding connection diagram, resistance of elements of asynchronous equipment: motor, complex systems. One of the most important parameters is the power of the electric motor. This characteristic determines the mechanical power that develops on the shaft within the nominal operating mode. In generators, this value is understood as the power of the electric motor supplied to the external circuit of the infrastructure.
Structure of asynchronous motors
This type of electric motor is the most common due to its relatively simple design, high performance characteristics that can be controlled, and cost. Functionality and nominal parameters allow the use of asynchronous devices in all areas of activity, including highly complex production, agriculture, and transport infrastructure.
Typical design of asynchronous machines with a short-circuited moving part:
- the fixed part is the core, two stator windings, and the frame. The stator core is a component element included in the magnetic drive complex of the machine. It is a hollow cylinder in which grooves are located in the axial direction. The core grooves are designed to accommodate three-phase stator windings - they are made using insulated copper wire, much less often - from aluminum wire;
- terminal box;
- air gap separating the elements;
- core of the moving mechanism (rotor);
- bearing shield.
The ends of the stator windings are connected by clamps - placed in a box with terminals on the motor housing. Six ends of the windings are supplied to the output in a way that allows the electric motor to be operated at different power supply voltages.
The rotor core is also part of the magnetic circuit. It is represented by compressed thin sheets of electrical steel. As in the case of the stator, it has the shape of a cylinder, but with longitudinal grooves in the outer part, and is equipped with a hole for the location of the shaft.
Interesting : Machines with a phase moving part are units that are used less often than short-circuited ones. This is due to the increased price, expensive maintenance, and lower reliability. They are used to equip drives for installations in which start-up conditions are significantly complicated. Motors with a phase moving part are quite often found in systems that require increased smoothness and deep adjustment of the technical characteristics of power devices.
Crane electric motors and high frequency asynchronous machines (AM)
Power plants are distinguished by their properties, due to which the units can withstand short-term and intermittent loads with frequent starts, braking and significant volumes of overloads. Such units have increased mechanical strength and insulation resistance to heating of an engine operating on an asynchronous principle.
Installations in cranes are notable for their reduced inertia of rotating parts and overload capacity. All this allows the motors to be operated in extremely difficult technical process conditions.
High-frequency asynchronous motors are used to equip the drives of electric tools. The power of the electric motor is small, the weight is insignificant, but the speed is increased. For such equipment, squirrel-cage motors are relevant - additional cleaning from abrasives and dust arising during the technical process is ensured by closed airflow. Magnetic cores are equipped with thin sheets of electrical graded steel.
Microcontroller
ATMega328p, operating at a frequency of 16 MHz, was selected as the control microcontroller.
The microcontroller is connected to a Chinese clone of Arduino Nano v3 ($1.5). The microcontroller generates a PWM signal through an eight-bit counter with a divider of 8, so the frequency of the PWM signal is 16 * 10^6 /255 /8 = 7.8 kHz, which fits within the maximum 20 kHz available to the driver.
The microcontroller ADC divider is set to 128; Since each measurement requires approximately 13 clock cycles, the maximum frequency of current flow measurements is approximately 16 * 10^6 / 128 / 13 = 9.6 kHz. Measurements are made in the background, notifying the main program of completion by calling the appropriate interrupt.
Three-phase network power calculation
Electrical energy to all objects is initially supplied through a three-phase network. In private houses it can be supplied directly, but in an apartment building it only reaches the input switchgear. Further on, single-phase lines disperse throughout the apartments. In any case, it will be necessary to calculate the power of the three-phase network in order to determine in advance its ability to withstand the planned current loads.
In order to make correct calculations, you need to know the features of such networks, the principles of their operation and technical characteristics. All necessary calculations are performed manually using formulas or using an online calculator.
Logs
I struggled for a long time with how to record what was happening inside the microcontroller, because it has very little memory.
As a result, I discovered that the native SPI interface is very fast, and as a result, all debugging information is transmitted by the microcontroller via the SPI interface; a widely available ($10 on Dilextreme, $6 on AliExpress) Chinese clone of the Saelae Pro 8 Logic logic analyzer was used to record it. After very simple manipulations of flashing VID/PID, it can be used with native software from Saelae. I use sigrok (pulseview). It has an extremely simple log file format, which I simply read with my homemade fifty-line program. I bought this analyzer on the advice of gbg, who repaired my Spectrum remotely for me (thank you very much!), and I consider it the best investment in the last two years. For example, I applied a sinusoidal signal (in PWM) to the output of the controller, and the logic analyzer sees it perfectly:
All this was put together, the photo is given in the title of the post.
Almost all the articles that I post here are my work diary. I learn something (in this case management theory) and diligently write down what I learn. The best way to write it down is to write an explanation of how it all works. Then I post the articles on different platforms, for example here.
I have two goals when writing text:
a) get feedback from people who know more than me.
For example, almost everything that I learned for these two articles was told to me by dear Arastas, please love and favor: a person who spends his personal time teaching idiots like me.
Again, gbg, who wrote me linear algebra for my computer graphics lectures, and then debugged the electronics for me over the phone many thousands of kilometers away.
b) just write:
This way I get a library of personal experience, which I return to periodically.
By the way, thematic media, what percentage of authors agree to your support program terms?
Fourier transform
The first thing you need to understand when reading my texts is that I believe that a function and a vector are the same thing.
All the talk about infinity bores me and obscures the essence of what is happening. Generalized functions and the like are a way of looking at pathological cases using the same language as cases where there is no pathology. It’s just that I’m not interested in pathologies. Valery Ivanovich Opoytsev (Boss) spoke well on this topic:
In any field, it is useful to be in a suitable environment of oral communication, where the bookish husks fall off.
Sometimes nothing changes in essence, but there is a feeling of falling into a rut and liberation from dogma. For science, which is always wearing a mask, this is especially important. The essence is behind the scenes, before the eyes - lace. And there is always something missing. Either simplicity, or complexity, but you can’t determine exactly what. Something is moving somewhere, you are on the sidelines, and time is disappearing into the sand, not to mention life. Next, an attempt is made to move the situation forward by simulating a writing environment where the “veils fall away.” The external outline of the content is more or less unclear from the table of contents, but the main goal is what is behind the scenes. Remove the veil, makeup, remove the decorations. Oversimplify, even lie a little, because dosing the truth is the cornerstone of explanation. The results, overloaded with details, do not fit where they should. The epiphany happens when the plump head falls to the level of “two times two”, while the count goes on in the millions. Such is the dialectic here.
If we have a vector (7,12,18,-2), then it can be considered as a set of coefficients in a weighted sum.
7*(1,0,0,0) + 12*(0,1,0,0) + 18*(0,0,1,0) + (-2)*(0,0,0,1) . In exactly the same way, we can consider this vector to be the values of the function at points 0, 1, 2, 3, because our vectors (0,1,0,0) and similar ones can be considered as a shift of a unit impulse: If we constantly increase the number of vectors (shifted unit impulses ) in the basis, we get the usual functions. Unfortunately, such a basis can be quite inconvenient to work with. Let's take the following function as an example:
We have already talked about what the Fourier transform is. In short, this is a change of basis.
In our case, the Fourier transform is a function from real numbers to complex numbers:
A function's argument (real number) is simply the number of the basis function or vector (actually, a pair of basis functions), and its value is the corresponding (pair of) coordinates in for those two vectors in the basis. The Fourier basis is the sines and cosines of various frequencies. The frequency is the number of the basis function.
For our specific function f(t), which is already a weighted sum of sine and cosine, it is very easy to calculate its expansion into a Fourier basis:
That is, our function f(t) has zero coordinates for all basis vectors, except for vectors number 11 and 41.
How is the Fourier basis useful? For example, because the differentiation operation linearly transforms this basis. Let's say we want to calculate the Fourier transform of the derivative f'(t). How to do it? As an option, straight forward: first calculate the derivative, and then calculate the Fourier transform:
Obviously, when differentiating sin(x), it will become sin(x+90°), that is, it is extremely easy to find a correspondence between the Fourier basis expansion of the original function and its derivative: Multiplication by
i
is simply a rotation of the complex plane, which corresponds to +90° in the argument of our function. That is, the differentiation operation, which is difficult to do in the basis of unit impulses, in the Fourier basis is simply scaling and rotating by 90 degrees. Beautiful, is not it?
Laplace transform
Approximately the same story happens with the Laplace transform.
Unfortunately, unlike the Fourier basis, the Laplace basis is non-orthogonal, and therefore is a little more complex for intuitive understanding. Well, that's not the point. Laplace went a little further. If Fourier had only sinusoids in his basis, then Laplace had sinusoids with exponential decay in his basis. Where did he get them from? This is extremely, extremely useful for solving linear differential equations. Let's think about what function transforms into itself upon differentiation? Exhibitor. What about differentiation twice? Sinus. And their combinations give all possible functions that can appear when solving (linear) diffuses, which is what the Marquis de Laplace used. We will not go into details of how these properties are derived (it’s better to carefully consider the properties of the Fourier basis, it is simpler), let’s just note the following facts:
1. Laplace transform is linear:
2. The Laplace transform of the derivative is an affine action on the transformation of the function itself: 3. So, if we have a DC motor, then the flowing current I(t) and the terminal voltage U(t) are related by the following differential equation, where w(t ) is the speed of rotation of the motor shaft: Here L is the inductance and R is the resistance, which is what we are looking for. I will not repeat where this diffuser comes from, since I have already described it in detail and on my fingers (see “Maxwell’s equations on my fingers”).
Since our task is to find L and R, let's rigidly fix the motor shaft, thus forcing w(t) to be zero:
On the advice of Arastas, I supplied two types of signals to my engine: a square wave and a sine wave. Then I measured the current flowing, the picture looks something like this:
Here the blue traces are the input voltage that I am monitoring, and the green ones are the current measurements taken with the ACS714.
My microcontroller code, which generates 11 experiments with square waves and sinusoids of various amplitudes and frequencies, can be viewed here.
Let's solve our differential equation for both types of voltage signal, obtain a parametric current output, and adjust the parameters so that the theoretical curve approximates the actual measurements as best as possible.
Preparing to measure the electric motor before rewinding.
In preparation, before starting measurements, you should thoroughly clean the stator core (and, if necessary, the rotor) from dirt and oil, remnants of the old winding and its insulation, layers of varnish, paint, rust, etc. When cleaning the core stator, you should not use a file even with a fine notch. It is best to use only a rag soaked in kerosene; as a last resort, firmly adhered particles are removed with a scraper. It is convenient to wipe the inside of the grooves with a rope dipped in kerosene. After cleaning, the core is wiped dry with a clean rag.
Input signal - Heaviside function (half-wave square wave)
So, w(t) = 0, initial conditions I(0) = 0, the current does not flow at the very beginning.
If we apply a constant voltage U0 to the motor terminals, how should the flowing current behave? Let's take the Laplace transform from the left and right sides of the differential equation (1):
To get the second line, I used the linearity of the Laplace transform, U0/s - I took it from the table (usually Laplace transforms are not calculated manually, they use tables).
To obtain the third row, the derivative property was used.
The last line is obtained from the penultimate line using the method of indefinite decompositions. The point of this transition is to again obtain a table function. Of course, in the twenty-first century there is no need to count this with your hands.
Now it remains to apply the inverse Laplace transform (for the right side we look at the table) and we have solved our diffuser. The transition to the Laplace basis turned the differential equation into an ordinary algebraic one!
Quick check of the result: after a few milliseconds, the inductance will no longer play a role, and we will get a flowing current U_0 / R (Ohm's law). At the very beginning, the flowing current is zero and increases exponentially, and the rate of increase directly depends on the inductance. Sanity check passed.
The measurement file is here. Three columns, seconds, applied voltage (in volts), measured current (in amps).
Here is the code that selects the resistance and inductance parameters for this experiment:
Hidden text
import numpy as np from scipy.optimize import curve_fit import matplotlib.pyplot as plt U0 = 19.2 def unit_step_current(x, R, L): return [U0/R — U0/R*np.exp(-t*R/L) for t in x] data = np.genfromtxt('unit_step_19.2V.csv', delimiter=',', names=['t', 'V', 'A']) [R, L] = curve_fit(unit_step_current , data['t'], data['A'])[0] print(R, L) fig = plt.figure() ax1 = fig.add_subplot(1,1,1) ax1.set_title(“Resistance/ inductance fitting") ax1.set_xlabel('Time, seconds') ax1.set_ylabel('Current (A), tension (V)') ax1.plot(data['t'], data['V'], color= 'b', label='input tension') ax1.plot(data['t'], data['A'], color='g', label='measured current') model=unit_step_current(data['t '], R, L) ax1.plot(data['t'], model, color='r', label='fitted curve') ax1.legend() plt.show()
It says the pair fits well R=4.4 Ohm, L=6mHenry, here is the graph:
Using a calculator to calculate power
The online calculator significantly speeds up power calculations in a three-phase network. To do this, the power and nature of the load - active and reactive, mains voltage, as well as the type of network - single or three-phase must be known in advance. All parameters are calculated using the formulas and methods given above. You just need to insert the necessary data into the windows and click the “Calculate current” button. In the window indicating the current in A, the desired result will appear, showing the magnitude of the current in terms of power.
Input signal - sine
Let's repeat the procedure for a voltage sinusoid with amplitude U0 and frequency F0.
Let's apply the Laplace transform to equation (1), first to the right side: and then to the left: Now the inverse transformation will give us the following law of current flow: Again, a quick sanity check: zero current at the very beginning, a few milliseconds of transient processes (an exponential directly dependent from inductance). After some time, the current flowing is the weighted sum of the sine and cosine of the same frequency (the frequency is equal to the input, this is good). This sum gives a sinusoid slightly shifted in time. Great, the result is plausible. The measurements are here, and the code for selecting parameters is here. It gives approximately the same values of resistance and inductance, which is what we needed. Here's the chart:
Why not measure the parameters directly, why all this garden with microcontrollers? Firstly, I have nothing to measure inductance with. Yes, and measuring engine resistance with an ohmmeter can have its own nuances.
Further, the parameters found at high signal amplitude do not exactly coincide with what is obtained at low voltages. It may be interesting (not discussed here) to make a model not only of the motor, but of the entire system as a whole, including the nonlinearity of the PWM driver.
Well, then all that remains is to develop a regulator that will take the required current at the input. Stay in touch!
Calculation of consumer power
First of all, you need to establish in advance the amount of electricity consumed. To do this, the power of all consumers in the house is summed up. This includes high-power equipment, common household appliances and lighting fixtures. For some owners, this list may be supplemented with warm electric floors.
All necessary information can be found in the technical data sheet, which is attached to each device. Some devices are marked accordingly. The most powerful units come first, and then all other equipment, as power decreases.
For calculations, take an automatic washing machine with a power of 2600 W, an electric water heater - 1900 W, an iron - 1500 W, a vacuum cleaner - 1000 W, a microwave oven - 800 W, a computer and office equipment - 600 W, lighting fixtures (with economy lamps) - 400 W , refrigerator – 300 W, TV – 100 W. The final result is 9200 W and must be converted to kilowatts. To do this, 9200 W is divided by 1000, resulting in 9.2 kW, which will be the estimated electricity consumption.
One phase can handle this power, but in private homes more powerful equipment is installed, for which it is better to use 380V networks. In this case, the uninterrupted functioning of heating and water heating boilers, pumps, electric motors and other units is guaranteed.