Microcontroller-controlled triac power controller

Once, for one small home project, I needed a power regulator suitable for adjusting the speed of rotation of an AC electric motor. Such a motherboard based on the STM32F103RBT6 microcontroller was used as the basis . The board was chosen as having an honest RS232 interface and having at the same time a minimum of additional components. There is no slot for a lithium battery on the board to power the watch, but taking it is a matter of fifteen minutes.

So, let's start with the theory. Everyone is familiar with the so-called pulse width modulation, allowing you to control the current in (or, less commonly, voltage across) the load with maximum efficiency. Excess power in this case simply will not be consumed, instead of being dissipated in the form of heat, as with linear regulation, which is nothing more than a complicated version of the rheostat. However, for a number of reasons, such control, being executed “on the forehead”, is not always suitable for alternating current. One of them is the greater circuitry complexity, since a diode bridge is required to power the power unit with MOSFET or IGBT transistors. These shortcomings are deprived of triac control, which is a modification of PWM.

Triac ( TRIACin English literature) is a semiconductor device, a modification of the thyristor, designed to work as a key, that is, it can be either open or closed and does not have a linear mode of operation. The main difference from the thyristor is two-sided conductivity in the open state and (with some reservations) independence from the polarity of the current (thyristors and triacs are controlled by current, like bipolar transistors) through the control electrode. This makes it easy to use the triac in AC circuits. The second feature common with thyristors is the ability to maintain conductivity when the control current disappears. The triac closes when the current between the main electrodes is turned off, that is, when the alternating current passes through zero. A side effect of this is the reduction of noise during shutdown. Thus,

Triac control takes into account the above properties of this device and consists in unlocking the triac on each alternating current half-cycle with a constant delay relative to the zero crossing point. Thus, a “slice” is cut off from each half-period. The shaded part in the figure is the result of this procedure. Thus, instead of a sinusoid, the output will be something that resembles a saw to a certain extent:

AC

Now our task is to unlock the triac on time. We will assign this task to the microcontroller. The diagram below is the result of an analysis of available solutions as well as documentation for optocouplers. In particular, the power unit is taken from the documentation for a triac optocoupler manufactured by Texas Instruments. The circuit is not without drawbacks, one of which is a powerful wire resistor stove, through which an optocoupler is detected, which detects the transition through zero.

schematics

How it works? Consider the figure.

waves

At the positive half-cycle, when the current through the optocoupler exceeds a certain threshold value, the optocoupler opens and the voltage at the input of the microcontroller drops to almost zero (the “ZC” curve in the figure). When the current again falls below this value, one again arrives at the microcontroller. This happens at time instants dz from the zero current. This dz is noticeable, in my case it is about 0.8 ms, and it must be taken into account. This is not difficult: we know the period T and the duration of the high-level pulse h, whence dz = (h - T / 2) / 2. Thus, we need to open the triac through dz + dP from the leading edge of the signal from the optocoupler.

The phase shift dP should be discussed separately. In the case of c PWM DC, the average value of the output current will linearly depend on the duty cycle of the control signal. But this is only because the integral of the constant gives a linear dependence. In our case, it is necessary to proceed from the value of the sine integral. The solution of a simple equation gives us the desired dependence: for a linear change in the average current value, it is necessary to change the phase shift according to the arc cosine law, for which it is enough to enter the table in the control program LUT.

Everything that I will discuss in the future is directly related to the architecture of the STM32 series microcontrollers, in particular, to the architecture of their timers. Microcontrollers of this series have a different number of timers, there are seven of them in STM32F103RBT6, four of which are suitable for capturing and generating PWM. Timers can be cascaded: for each timer, one of the internal events (overflow, reset, level change on one of the input or output channels, etc .; I refer you to the documentation for details) can be declared output and sent to another timer by assigning it to a certain action: start, stop, reset, etc. We will need three timers: one of them, working in the so-called PWM input mode, measures the period of the input signal and the duration of the high-level pulse. At the end of the measurement, an interrupt is generated after each period. At the same time, the phase shift timer associated with this event starts, which operates in standby mode. Upon the overflow event of this timer, a timer is reset, which generates the output control signal to the triac, thus, after each full period of the alternating current, the phase of the control signal is adjusted. Only the first timer generates an interrupt, and the task of the handler is to adjust the phase shift (register ARR of the waiting timer) and the PWM timer period (also register ARR) so that it is always equal to half the period of the alternating current. Thus, all control takes place at the hardware level and the influence of software delays is completely eliminated. Yes, this could be done programmatically, but it was a sin not to take advantage of such an opportunity as cascaded timers.

I don’t see the point of uploading the code of the entire project for review, in addition, it is far from complete. I will give only a fragment containing the algorithm described above . It is completely independent of other parts and can easily be ported to another project on a compatible microcontroller.

And finally, a video showing the device in action:


Also popular now: