Low-voltage PWM controller on a microcontroller with indication. Power regulator on ATtiny2313 microcontroller - Power regulators - Power supplies

Health to all readers of Muska!
Thanks to this wonderful site, I got a lot of useful things and knowledge and in response I decided to write the first report on the newly developed device. During the development of the device, I encountered a number of problems and successfully resolved them. Perhaps, for some of the newcomer colleagues, the description of some solutions will help in creativity.
For the manufacture of printed circuit boards, he acquired a micro-drill and a stand for it, which turns the drill into a micro-drilling machine. The need for this arose after a bunch of broken 0.5-1mm drills when used in a screwdriver and a Chinese dremel. But, as it turned out, it is impossible to use such a tool without a speed controller. The regulator decided to do it on his own, gaining new knowledge along the way.

I have little experience in amateur radio. As a child, based on Borisov's book, he assembled several receivers, and blinkers on multivibrators. Then came other hobbies and activities.
And then, on occasion, I noticed Arduino, famously sculpted models of weather stations, robots, and I wanted to automate everything that I could reach with the help of microcontrollers. The sizes of the controllers went in descending order of size and ease of embedding - Arduino UNO, Arduino Pro Mini, then a handful of ATMega328P, and for the smallest and simplest devices, I purchased ATtiny85.
Tinky bought more than a year ago and they were lying and waiting for their turn.

Order screenshot


(there was also a heat shrink in the order, because the total price is higher)


MK arrived as usual in a package with a little bubble wrap, themselves in a bunch in a separate plastic bag. It would be better, of course, in a hard box or in foam, but even so nothing was bent and all the workers.

At first, I soldered schematics on breadboards, but after reading about LUT, I realized that it was quite realistic and much more convenient to assemble everything on normal printed circuit boards.
I also gradually began to collect a useful tool, among which was an MD-3 microdrill with a collet chuck and a machine for drilling small holes. It would be possible, of course, to buy only a collet, and pick out the engine from somewhere, but I decided to purchase it ready-made at a local store.

We print on a laser printer a drawing on Lomond glossy photo paper for inkjet printing. But it was dumb to put paper that was not intended for it at all into a brand new printer. Found warnings on the net that the glossy finish of the inkjet paper can melt, stick to the oven and ruin the printer. To be sure, I conducted an experiment - I rolled a soldering iron heated to 200C on the surface of this paper (I didn’t find the exact temperature of the stove, but about that), the paper warped a little, but nothing melted and didn’t stick - so it’s possible in the printer.

I ironed the drawing on the board, washed off the paper. A very high-quality pattern of conductors and an adhered glossy layer of paper remained on the board. The author of the technology recommended removing it with a not very sticky electrical tape, but no matter how hard I tried, either the gloss was not removed at all, or the conductors came off with it. The inscriptions also immediately switched to electrical tape. Having suffered, he took an awl, and, having scratched between the conductors, tore off almost all the gloss. It's a delicate and tedious thing, you have to invent something. Then, when making the second and third boards, I was looking for a way to get rid of the damned gloss, but printing neither on a magazine page nor on a self-adhesive basis did not give such a quality picture, the tracks blurred or fell off. But on the other hand, I realized that it was not necessary to clean off the gloss of photographic paper to zero - it was enough to scratch at least a little between the tracks for the solution to access the copper, and in some places it was etched without scratches, through the gloss.

I decided to pickle copper with a solution of hydrogen peroxide and citric acid as the most accessible composition. Possible options for etching chemistry with calculations can be viewed here

I took peroxide from the first aid kit, it was bought about 3 years ago, the expiration date came out about 2 years ago, I thought it was already exhausted and will not work at all. However, I was mistaken, the board was pickled very cheerfully - in about three minutes. Here is the result:

One track suffered from scratching with an awl, it was restored with a bitten-off resistor terminal. Plus minor holes from trying to use electrical tape. It is necessary to acquire a suitable marker, but for now, where I could, I smeared it with varnish.

I tinned the board with a soldering iron using a braid. Soldered the details.




High brass racks screwed into each other on both sides of the board through mounting holes are a handy thing, you can put the board without a case on the table during installation and debugging on either side without fear of crushing or shorting anything.

Of the most time-consuming, it was to crawl and solder the output LEDs from the side of the conductors. I decided to use the soldering side as the front side, because. on it, the height of the parts is much less, and passing the variable resistor shaft through the board reduces its length to the desired one.

Capacitor C2 in the diagram connected to Reset did not solder, because. although it increases the reliability of starting the device, it can get mad when flashing the MK.

The microcontroller was soldered last, after connecting the board to the PSU and making sure that nothing would burn out right away and the stabilizer would give out regular 5V. Nothing smoked and therefore we connect the programmer to the ICSP pins and fill in the test firmware.

We will write the firmware for the device in the Arduino programming environment familiar to many, after adding support for ATtiny microcontrollers to it, downloading and unpacking them into the Arduino / hardware folder.

The test sketch (I don’t see the point) simply read the states of the input signals and displayed them on the available outputs with the LEDs connected. Because we have 4 input channels, and only 2 output channels, we had to check in several stages.

Everything worked as expected, except for one thing - the button connected to one channel with a green LED was not readable, and the LED was noticeably brighter than red. Measurements by the tester showed that in the PB0 state, more than 20mA flows as an output through the LED and only 2.1V drops on it. And in the input state with an internal pull-up on the leg, only 1.74V when the button is released and 0.6V when it is pressed. It is not surprising that 0 is constantly read. The low-voltage green LED, without even glowing when a microampere current was flowing, squandered the voltage on the leg. Now it’s clear why in the original article 2 LEDs were connected in series.

But putting a second LED to shine inside the box stupidly as a ballast (and 2 identical ones on the front panel are also not needed) seemed to be a somewhat crooked solution. I thought about how else you can raise the voltage in the LED circuit and remembered the CVC of the zener diode. If we connect in series with the LED opposite to it a 2V zener diode (to work properly, on the reverse branch of the CVC), then we get exactly what we need. When the LED is on at a current of 10mA, the zener diode breaks through and does not interfere with the flow of current, but only stabilizes the voltage falling on it at a given level. It is only necessary to replace the current-limiting resistor, on the basis that it is already necessary to suppress the voltage Ures=5V-2.1V-2.0V=0.9V by 10mA, i.e. R=90 Ohm. And when the leg is switched to the input with a pull-up - due to the steepness of the CVC branch until the breakdown of the transition, the zener diode is equivalent to a high-resistance resistor and it will drop again about 2V, raising the voltage on the MK leg when the button is released to 4V, which is already read as TRUE. When the button is pressed, the leg will be pulled up to 5V by an internal resistor with a resistance of about 40KΩ (according to my calculations), and to the ground by a 5KΩ resistor (which will shunt the LED circuit), i.e. it will have the same 0.6V and is considered FALSE.
I soldered the zener diode with a canopy in series with the resistor and the button worked as it should.

Now it's the turn to check the operation of the PWM, and here, too, problems arose. The standard Arduino command AnalogWrite(leg, padding) did not want to work. So something is wrong with the tinka library. Useful wool datasheet on the MK and the Internet.

It turned out interesting:
- on pins 5, 6 (PB0, PB1) 2 PWM channels (OC0A, OC0B) can be output, each operating with its own fill setting (but the same frequency) from Timer 0;
- the third PWM channel operating from Timer 1 can be output to pins 2, 3 (PB3, PB4), and a direct PWM signal (OC1B) can be output to leg 3, and its inverse version (/OC1B) can be output to leg 2. But the output goes either only to the 3rd leg, or to both at once. And we need PWM on the 2nd leg, at least inverse (we programmatically invert it back), so we will have to configure the output for 2 and 3 legs, and the signal will not go to 3 just because it is declared an input.

So, as far as I understand, in the ATtiny support package for Arduino, the PWM channel from Timer 1 can only be output to leg 3. Apparently, the output of its inverse version was considered overkill. You will have to configure the timer and PWM yourself (see code, PWM3_init function), instead of using AnalogWrite.

I also noticed that when reconfiguring Timer 1, the work of the millis () function is lost - it turns out that Timer 1 is used by default for the internal clock. But you can reconfigure the time to Timer 0 using macro definitions in the file Arduino\hardware\tiny\cores\tiny\core_build_options. h
/* For various reasons, Timer 1 is a better choice for the millis timer on the "85 processor. */ #define TIMER_TO_USE_FOR_MILLIS 0
Which we will use, since Timer 0 in this project is just completely free.

There was also a question about the speed setting range read from the variable resistor. The author of the original circuit added a 36K constant resistor in series with the 10K variable, apparently on the basis that the ADC code would fit into the range of 0-255. It really turned out 0-230, and the maximum swam. And I would like exactly 0-255 to match the full scale setting with an 8-bit PWM. To do this, I unsoldered the constant and replaced it with a + 5V jumper, the ADC began to read the entire range, and we discarded the 4 least significant bits programmatically. And why was the extra detail needed?

After testing the input/output channels, we load the combat firmware into the microcontroller, written in C in the Arduino environment based on the BASIC sources of the author of the original circuit.

Program text

// Attiny85 at 1MHz // Don't forget to set timer 0 for millis etc! // Arduino\hardware\tiny\cores\tiny\core_build_options.h -> TIMER_TO_USE_FOR_MILLIS 0 #include // Connections #define MODE_LED_PIN PIN_B0 #define MODE_BUT_PIN MODE_LED_PIN #define PWM_LED_PIN PIN_B3 #define AM_PIN PIN_B1 #define SP_PIN A1 #define CUR_PIN A2 // States #define MODE_MANUAL 0 #define MODE_WAITINGSET 1 #define MODE_UP_XX 2 #define MODE_SETUP_MAX 3 #define MODE_START 4 #define MODE_DRILLING 5 #define MODE_STOP 6 // Variables byte Mode = MODE_MANUAL; byte ModeLedVal = LOW; byte SetPoint = 0; int CurrentFiltered = 0; byte CurrentU8 = 0; byteAMButton; byteAMButtonFlt = LOW; static byte ModeButton; static byte ModeButtonFlt = HIGH; // initial value for static byte ModeButtonOld = LOW; // trigger exceptions at startup static byte SetupStep = false; unsigned long BlinkFromMs; unsigned long StartFromMs; unsigned long ModeFromMs; byte W, W0, W1, W2, Wxx, Wmax, Uxx, Uon, Uoff; void PWM3_init() ( // Set up PWM on PB3 (pin 2) using Timer 1 TCCR1 = _BV (CS11) | _BV (CS10); // prescaler /4 GTCCR = _BV (COM1B0) | _BV (PWM1B); // clear OC1B on compare OCR1B = 255; // initial duty cycle 0% (use inverted output!) OCR1C = 255; // PWM frequency = 1kHz (1,000,000 /4 /256) ) void analogWrite_PB3(uint8_t duty_value) ( ​​// analogWrite on PIN_B3 OCR1B = 255-duty_value; // padding 0-255 (0-100%) (use inverted output!) byte ScanButton(void) ( // Read button connected to one output with LED // Faster version with restoring output and no PWM disables byte value,port_bak; port_bak = PORTB; // save output DDRB &= ~(1<interval))( \ outvar = varname;\ )\ )\ else (\ __lastChange_##varname=millis();\ ) // Initialization void setup() ( pinMode(MODE_LED_PIN, OUTPUT); // main state - pinMode indication (PWM_LED_PIN, OUTPUT); PWM3_init(); // restoring settings from EEPROM if they are there if (EEPROM.read(11)==0xAA) ( Wxx = EEPROM.read(0); Wmax = EEPROM.read(1) ; Uon = EEPROM.read(2); Uoff = EEPROM.read(3); ) else ( // default values ​​Wxx = 1; Wmax = 255; Uon = 255; // excludes start before tuning Uoff = 0 ; ) // Smooth acceleration to idle or manual setting if (digitalRead(AM_PIN)==HIGH) W0 = Wxx; else ( W0 = 255- (analogRead(SP_PIN) >> 2); // 0-255, variable resistor we got inverse ) W1 = 0; for(W=0 ; W<=W0; W++) { analogWrite_PB3(W); W1 = W1 + 4; delay(W1); } delay(800); Mode = MODE_WAITING; } // Рабочий цикл void loop() { // Индикация текущего режима морганием switch (Mode) { case MODE_MANUAL: ModeLedVal = LOW; // выключено break; case MODE_WAITING: (ModeLedVal==HIGH) ? ModeLedVal=LOW: ModeLedVal=HIGH; // в полнакала break; case MODE_START: case MODE_DRILLING: case MODE_STOP: ModeLedVal = HIGH; // на полную break; case MODE_SETUP_XX: if ((millis()-BlinkFromMs >400)) ( // rarely (ModeLedVal==HIGH) ? ModeLedVal=LOW: ModeLedVal=HIGH; BlinkFromMs = millis(); ) break; case MODE_SETUP_MAX: if ((millis()-BlinkFromMs > 100)) ( // often (ModeLedVal==HIGH) ? ModeLedVal=LOW: ModeLedVal=HIGH; BlinkFromMs = millis(); ) break; ) digitalWrite(MODE_LED_PIN, ModeLedVal); // Auto/Manual toggle switch, opens in Auto and reads HIGH AMButton = digitalRead(AM_PIN); Debounce(AMButton, AMButtonFlt, 200); // Settings button, read by a special procedure because combined with the LED, when pressed, it reads LOW ModeButton = ScanButton(); Debounce(ModeButton, ModeButtonFlt, 200); SetupStep = (ModeButtonFlt==LOW) && (ModeButtonOld==HIGH); ModeButtonOld = ModeButtonFlt; // Spinner SetPoint = 255- (analogRead(SP_PIN) >> 2); // 0-255, our variable resistor turned out to be inverse // Motor current // Main filter RC-chain 36K + 68nF (time constant 2.5ms, cutoff frequency 65Hz) of order y(i) = y(i-1) + alpha*(x(i)-y(i-1)) // (aka Exponential Moving Average, EMA) // in the filter, instead of float, we use increased precision int, for which we shift left by free 5 bits (the sign will still be useful) // replace the multiplication by the fractional coefficient alpha with a shift to the right // (6 = /64 = *0.016) 100 cycles - 80% of the value, 200 cycles - 96% of the value, 369 cycles - 99.6% value // (5 = /32 = *0.031) 50 cycles - 80% value, 100 cycles - 96% value, 179 cycles - 99.6% value // (4 = /16 = *0.063) 25 cycles - 80 % value, 50 cycles - 96% value, 90 cycles - 99.6% value // (3 = /8 = *0.125) 12 cycles - 80% value, 25 cycles - 96% value, 45 cycles - 99.6% value // period run = ADC 110µs + program = 0.2ms // time constant = 8 * 0.2ms = 1.6ms, cutoff frequency 625Hz CurrentFiltered = CurrentFiltered + (((analogRead(CUR_PIN)<< 5) - CurrentFiltered) >> 3); // for ease of use, cast to 0-255 // (shift back by 5 bits and 2 high bits are discarded because everything interesting (idle)<1В) CurrentU8 = byte (CurrentFiltered >> 5); // if >1В not to be confused with small ones if ((CurrentFiltered >> 5) & 0x7F00) CurrentU8=255; // State machine switch (Mode) ( case MODE_MANUAL: // Manual control with a twist analogWrite_PB3(SetPoint); if (SetupStep) Mode = MODE_SETUP_XX; if (AMButtonFlt==HIGH) ( // Slow down when switching to the machine analogWrite_PB3(Wxx); StartFromMs = millis(); Mode = MODE_STOP; ) break; case MODE_WAITING: // Wait for the current to rise if (CurrentU8 > Uon) ( // Start StartFromMs = millis(); analogWrite_PB3(Wmax); Mode = MODE_START; ) if (SetupStep ) Mode = MODE_SETUP_XX; if (AMButtonFlt==LOW) Mode = MODE_MANUAL; break; case MODE_START: // Spin up if (millis()-StartFromMs > 300) Mode = MODE_DRILLING; if (AMButtonFlt==LOW) Mode = MODE_MANUAL; break ; case MODE_DRILLING: // Drilling, waiting for the current to drop if (CurrentU8< Uoff) { // Тормозим analogWrite_PB3(Wxx); Mode = MODE_STOP; } if (AMButtonFlt==LOW) Mode = MODE_MANUAL; break; case MODE_STOP: // Тормозим и ждем пока выйдем на ток ХХ if (CurrentU8 < Uon) { // Замедлились if (millis()-StartFromMs >300) // safe Mode = MODE_WAITING; ) else ( StartFromMs = millis(); ) if (AMButtonFlt==LOW) Mode = MODE_MANUAL; break; case MODE_SETUP_XX: // Idling setting Wxx = SetPoint; analogWrite_PB3(Wxx); if (SetupStep) ( Uon = byte(1.1 * CurrentU8); EEPROM.write(0,Wxx); EEPROM.write(2,Uon); Mode = MODE_SETUP_MAX; ) break; case MODE_SETUP_MAX: // Setting the max. RPM Wmax = SetPoint; analogWrite_PB3(Wmax); if (SetupStep) ( Uoff = byte(1.1 * CurrentU8); EEPROM.write(1,Wmax); EEPROM.write(3,Uoff); EEPROM.write(11.0xAA); // Brake analogWrite_PB3(Wxx); StartFromMs = millis(); Mode = MODE_STOP; ) break; default: Mode = MODE_WAITING; return; ) )


We connect a 5 watt 2.2 ohm resistor as a shunt. To protect the circuit from inductive surges of voltage on the trailing edge of the PWM, we connect an SS34 Schottky diode in parallel with the motor, and to suppress interference from switching windings, a 100nF capacitor. And we begin testing to control the motor of the drill.

Immediately pulls out the furious howl of PWM at 4KHz (1MHz / 256). We add the /4 divider setting - it immediately felt better, although the squeak has not gone away, but for some reason 1KHz is much easier to tolerate even with prolonged operation.

In manual mode, the motor speed is normally regulated by 0-100%, and in the automatic ADC of the feedback circuit it reads the MAX value all the time and nothing works. Along the way, I notice that the board beeps loudly even when the motor is turned off. wtf?

We take a tester, dig out an oscilloscope and begin to study what we give out and what we get. And we drop our jaws. On the shunt, instead of gently sloping current waves through the inductance at the beginning of the PWM pulses, we see needles of tens of volts. This means that a pulsed current of ten amperes flows through the shunt! And even with the engine off. Not surprisingly, the board rang. But what closes the circuit without an engine? Tiny 100nF Capacitor! It can and will suppress interference when switching windings, but for now it arranges a short-term short circuit at each PWM period! Conclusion - the noise suppression capacitor is not compatible with PWM control and control using a shunt, it must be removed.

And then it dawns on me that these high-voltage surges go almost directly to the ADC of the tinka (because there is an amplitude detector, the capacitor on the leg is charged to the maximum voltage in the needle and safely stores it, because the discharge is only through a diode leakage) . Tinka doesn’t seem to be going to die yet, but what about her leg? The instruments show a constant voltage on the leg of 5.2V, higher than the supply voltage, but where did the rest go? We recall that to combat surges, it has specially trained diodes for “+” and “-” power supplies, which bleed the excess into the PSU. But the built-in diodes are frail and you should not count on them much.

We remove the damn capacitor, measure the voltage with our foot - it works! Reliable MK makes Atmel! Apparently it saved that the capacitance of the capacitors was low, they pumped a little charge.

Without a capacitor, the needles disappeared, the board stopped playing music, the leg seems to really measure the amplitude of the PWM pulse current. We start the setup procedure and try to drill. It seems that everything is as it should - it adds revolutions under load, and resets it when the drill exits. But not only - several times a minute it spontaneously accelerates and slows down without load. Why it is not clear, the instruments do not show anything. Either the leg is burnt, or the capacitance of the wires generates invisible needles like that conder, or interference from the same collector climbs.

Then I decided to deal with the problem radically, because I noticed that the peak detector is not used in any other scheme. On the contrary, the integral value of the current passed through the RC filters is controlled everywhere. And such measurements are just insensitive to interference in the form of single emissions. We change the diode to a resistor - and the amplitude detector turns into a low-pass filter.

The voltage changed by the ADC dropped immediately by an order of magnitude - the operating voltage is much lower than the amplitude in the case of a signal in the form of gentle waves with pauses between them. We had to catch a voltage of about 0.2 V. Of course, it was possible to increase the resistance of the shunt, but was it for this purpose that we fenced the PWM in order to warm the atmosphere. And with a large PWM filling and a load on the motor, you can get an overvoltage. Therefore, you will have to work with low U idle.

The response to the load seems to have slowed down too. Acceleration starts in about half a second, but I don’t see a big problem in this - just the drill will set up and pass through the copper at low speeds. And no more false starts. You can work.

The final scheme of the device:


The device was mounted in a housing, which was a hermetically sealed electrical installation “Tuso plastic wiring box without glands 120x80x50 mm, IP55 gray 67052 Ruvinil Russia”. I wanted to find a flatter one, but I didn’t find anything like 110 * 60 * 30. In order not to plant garlands on the table, I twisted the regulator with the PSU into a single whole. The brick turned out to be noble, but we can’t even carry it in our pocket. And although after drilling a couple of dozen holes, there was no noticeable heating of the key field, shunt and stabilizer, I drilled a little ventilation at the bottom and back wall.







Since then, the machine with the regulator has participated in the creation of 2 more boards (you can see how many it took to drill according to the words "AVR Fusebit Doctor". I am very pleased with his work.

I also want to note that carbide drills with Ali have a shank of 3.2 mm, and the collets were only 3.0 and 3.5 - they don’t fit into one drill, but they don’t clamp into the other. I wound copper wire on the drill and somehow inserted it into 3.5 mm, but it was ugly. If anyone has met a collet at 3.2 with a diameter of 6 mm (everywhere except for Dremel, with a tail ground down to 5 mm), tell me.

When changing drills, the adjustment procedure has to be repeated - apparently, the different moment of inertia of a “skinny” conventional drill and a carbide drill with a thickened shank affects the motor current. But this is done quickly and does not bother. Those who wish can add the saving of drill profiles to the firmware :)

Repeatedly met the advice to drill boards under a layer of water, so as not to breathe glass filings. I could not get. Precisely position the drill when it is high, refraction in the water interferes, the eye skews. And when the drill enters the water, ripples begin to go and nothing is visible at all. Is it necessary to set the stopped drill, and then turn it on? As a result, I simply put a bowl of water next to it and periodically dip the board into it - to moisten and wash off the sawdust. In this case, the sawdust is damp and does not fly either, it is collected in a cone over the hole.

And one more lyrical digression, about small fasteners.

I decided to put a power connector of the type “DS-225, Power socket on the panel” into the device. For its fastening, screws with nuts with a thread of 2.5mm were required. Nothing suitable was found in the closet, and then I remembered that 2mm screws were required in another item. So it’s worth replenishing the collection of fasteners so that next time you don’t fly to the other end of the region for the sake of a nut. In construction stores, nothing less than the M3 came across, so you need to look for specialized ones.

The first relatively convenient store was a chain
Inside, the eyes fled from all kinds of usefulness, but that's bad luck - the smallest screws were only M2.5 of the same length, but there are no nuts and washers for them and never happens! I was impressed by the sale of nuts by the piece for 2r / piece and pouring everything bought into one bag-shirt (there were no small bags for different sizes). Again, it is unprofitable to take in reserve different sizes.

Rescued by another fastener store -
Here there is really everything in stock, from M1.6, with different slots and heads, sold by the piece and by weight, and at a price an order of magnitude lower than the previous competitor. But you just need to immediately go to the warehouse store on Plekhanov Street, otherwise I first went to the store near the Perovo metro station and was very surprised at the announced price. And it turned out that they only have stainless steel, and for the usual fasteners you have to go to the industrial zone on the crossbars.

I plan to buy +67 Add to favorites Liked the review +76 +152

There are a huge number of classic thyristor and triac controller circuits, but this controller is made on a modern element base and, moreover, was a phase one, i.e. it does not pass the entire half-wave of the mains voltage, but only some of it, thereby limiting the power, because the opening of the triac occurs only at the desired phase angle.

When the circuit is switched on for the first time, the figure 0 lights up on the segment indicator. Switching on and off is carried out by simultaneously pressing and holding two microswitch buttons. Adjustment more or less - each press individually. If you do not press any of the toggle switches, then after the last pressing, after two hours, the regulator will turn off on its own, the indicator will blink until then at the stage of the last working level of power consumption.

At the moment the device is disconnected from the network, the last level of output power is stored, which will be automatically set the next time it is turned on. Adjustment is carried out in the range from 0 to 9 and further from A to F. That is, there are 16 adjustment steps in total.

The radiator in the photo above is quite large, the design allows you to put a smaller option, but I didn’t have another one. When I turned on the device for the first time, 0 blinked on my display, the circuit did not react to pressing the buttons. Replacing the power supply capacitor with a nominal value of 1000 microfarads, the problem disappeared.

The printed circuit board in the format and the firmware of the microcontroller are placed in one archive at the link above.

The circuit is used for smooth power control in the load. The control method is based on the triac phase control method. Its essence lies in skipping part of the half-cycle of the alternating mains voltage. The current supplied to the load is proportional to the integral of the received signal. The basis of the design is the PIC16F1823 microcontroller.

The device supports active (incandescent lamp, heater) and inductive loads. The microcontroller is clocked from an internal oscillator. The synchronization signal with the network comes from the rectifier bridge to the input of the internal comparator of the microcontroller through a filter on R10, C5, R9, R8, C3. The reference voltage of the comparator comes from the internal DAC of the microcontroller and is about 0.6 V, which is set during the MK configuration. Diode D6 is used to eliminate the influence of capacitance C6 on synchronization. The indication is made on the E30561 with a common cathode.

Structurally, the device is assembled on two printed circuit boards. On one are the indicator and control buttons, and on the other MK, power supply and triac. The boards are connected with MGTF wire.

With triac heatsink (HS-135-38) as shown in the figure, the maximum load power is about 500W. Accordingly, a seat on the printed circuit board is made for this radiator.

The firmware for the MK is made in the MPLAB environment in the C language for the HI-TECH PICC 9.83 compiler. You can download printed circuit boards, firmware and the MPLAB project from the link above.

The design is regulated using a triac type BT138. The management of which is carried out through the MK. The digital LED display shows how many percent the triac is open at the current time. The logical part of the circuit is powered by a power supply, the basis of which is a voltage regulator DA1 7805.

This circuit is perfect for separately adjusting the output power for two different loads, for example, heaters, lamps, electric motors. The maximum load power depends on the type of keys that switch it. In the diagram below, KT819 transistors act as such, but there may be other options, depending on the required power of both loads. The device generates pulse signals that go to any of the power switches.

The device generates pulse signals, the width of their pulses can be adjusted in 256 equal degrees. To control the circuit, variable resistances are used, connected to the RV3 and RV4 ports of the MK, which work with the ADC. The ATtiny13 measures the value of the variable resistor and sets the pulse width of the output pulse signal following the switch that controls the power to a particular load. That is, by turning the variable resistance knob, the power is adjusted. Such an adjustment, compared with the setting with the "less" and "more" buttons, is more convenient to use, thanks to its speed. There is an ISP6 connector for programming the device. When programming, we set the fuses by default, working with an internal clock RC generator at a frequency of 9.6 MHz. The archive with the source code of the firmware, we take it from the link above.

Adjusting the speed of electric motors in modern electronic technology is achieved not by changing the supply voltage, as was done before, but by applying current pulses of different duration to the electric motor. For these purposes, they serve, which have recently become very popular - PWM ( pulse-width modulated) regulators. The circuit is universal - it is also a motor speed controller, and the brightness of the lamps, and the current strength in the charger.

PWM controller circuit

The specified scheme works fine, attached.

Without altering the circuit, the voltage can be raised to 16 volts. Set the transistor depending on the load power.

Can be assembled PWM regulator and according to such an electrical circuit, with a conventional bipolar transistor:

And if necessary, instead of the composite transistor KT827, put the field IRFZ44N, with a resistor R1 - 47k. Polevik without a radiator, with a load of up to 7 amperes, does not heat up.

PWM controller operation

The timer on the NE555 chip monitors the voltage on the capacitor C1, which is removed from the THR pin. As soon as it reaches a maximum, the internal transistor opens. Which shorts the DIS pin to ground. In this case, a logical zero appears at the output OUT. The capacitor begins to discharge through the DIS and when the voltage across it becomes zero, the system will switch to the opposite state - at output 1, the transistor is closed. The capacitor begins to charge again and everything repeats again.

The charge of the capacitor C1 follows the path: “R2->upper arm R1 -> D2”, and the discharge along the path: D1 -> lower arm R1 -> DIS. When we rotate the variable resistor R1, we change the ratio of the resistances of the upper and lower arms. Which, accordingly, changes the ratio of the pulse length to the pause. The frequency is set mainly by the capacitor C1 and also depends a little on the value of the resistance R1. By changing the charge/discharge resistance ratio, we change the duty cycle. Resistor R3 provides a pull-up output to a high level - so there is an open collector output. Which is not able to set a high level on its own.

You can put any diodes, capacitors of about the same value as in the diagram. Deviations within one order of magnitude do not significantly affect the operation of the device. At 4.7 nanofarads set in C1, for example, the frequency drops to 18 kHz, but it is almost inaudible.

If, after assembling the circuit, the key control transistor heats up, then most likely it does not open completely. That is, the transistor has a large voltage drop (it is partially open) and current flows through it. As a result, more power is dissipated for heating. It is desirable to parallel the circuit in output with large capacitors, otherwise it will sing and regulate poorly. In order not to whistle - pick up C1, the whistle often comes from him. In general, the scope is very wide, especially promising will be its use as a dimmer for high-power LED lamps, LED strips and spotlights, but more on that next time. The article was written with the support of ear, ur5rnp, stalker68.

Very often it is necessary to be able to regulate the current flowing through lamps or heating elements. Since they have a resistive load, the easiest solution is to assemble a small PWM (from English PWM - pulse-width modulation) regulator. Since simple circuits based on NE555 timers were not of interest, it was decided to develop and assemble our own, somewhat similar to.

The circuit, despite the presence of the PIC18LF2550 microcontroller, is very simple to repeat and can be conditionally divided into 3 parts:

PWM generator

The microcontroller generates clear pulses of the desired shape and duty cycle, which greatly simplifies the circuit. There are two buttons to increase and decrease power. They go to pins 3 and 5 of the PIC18LF2550 chip. Depending on the pulse width - the LED blinks more slowly or faster, so you can visually assess the duty cycle. If the LED shines completely - the power is 100%, and if it goes out, then the duty cycle is 0%.

microcontroller power supply

The MK stabilizer is 3.3 volts, therefore, depending on the output transistor, you can use a power source from 3.7 to 25 volts. The switching frequency is 32 kHz, and the pulse width is divided into 256 steps, including full on and off.

Load switch

The driver for the MOSFET transistor is the usual 2N3904. The power transistor itself can be any suitable N-channel MOSFET, not necessarily as in the 80NF55L circuit.

This version of the 4-channel 8-bit PWM controller is designed using the ATmega16 microcontroller. The device contains an RS232 interface for computer control, an interface for a 12-button keyboard and 4 analog 10-bit channels for connecting potentiometers. To display the current operating modes and parameters, there is a 4-line LCD display. Additionally, the PWM controller has: 4 LED outputs for indicating control modes (can be used as general-purpose outputs), 3 general-purpose outputs.

The device has very flexible settings. For example, the parameters of the PWM channels can be controlled by commands from a computer, by means of analog controllers (potentiometers) or using a keyboard (with a user interface displayed on an LCD indicator). The LCD indicator itself can also be controlled via RS232, the display of current settings and modes is possible in numerical or graphical format.

The main characteristics of the device:

  • 4-channel PWM, resolution 8 bits, PWM frequency - 31 kHz;
  • RS232 interface for PC control and monitoring;
  • simple circuit design with a minimum number of external elements;
  • 12-button keypad;
  • the possibility of analog adjustment;
  • up to 7 general purpose output lines;
  • 4-line LCD display;
  • LCD display control via serial interface;
  • user menu;
  • flexible settings;
  • software implementation of FIFO buffers to speed up work.

General-purpose outputs (including LED indicators) are controlled from a computer (RS232), the user also has the ability to read the history of keystrokes on the keyboard (the last 32 keystrokes, or immediately after pressing any key).

Thanks to such flexible settings, by choosing the appropriate setting, the PWM controller can be used in various applications and as a standalone device. The design uses the ATmega16 microcontroller, the minimum number of external elements, since all control and management is performed by the microcontroller itself. It is possible for the user to use only the necessary components, for example, the LCD indicator, if it is not needed, can be omitted.

The logic diagram of the device.

Schematic diagram of the device

The circuit design is very simple. An 8 MHz quartz resonator was selected for clocking the microcontroller, a +5.0 V power supply was assembled on an integrated stabilizer LM7805, an inductance of 10 μH and a capacitor of 100 nF form a filter that prevents the penetration of interference when switching in analog circuits. The MAX232 logic level converter is used to implement the serial interface. LCD-indicator based on the Hitachi chipset (HD44780) with a resolution of 20x4 or 40x2. The indicator backlight control unit is implemented on the MJE3055T transistor (it is possible to use a cheaper analogue). Keyboard matrix, standard, 4×3.

After power on, the microcontroller sets the last saved parameters in EEPROM: PWM channel control modes (analog control, serial interface control, keyboard control), parameter display format on the indicator (serial interface control, PWM value display, analog value display), as well as the state of general-purpose output lines, the state of the display backlight.

PWM generation is always present on all four channels after power-up. The user can set all the parameters of the PWM controller using the serial interface by sending control commands, and then save all the settings made in the EEPROM of the microcontroller. A complete list of commands and values ​​is given below in the appendix. The serial interface can also be used to send the current values ​​of analog control channels (on request).

On the indicator, when the supply voltage is applied, a greeting is displayed (the user can change the greeting), and then, in accordance with the current settings, displays the current parameters and values ​​of the PWM outputs, the values ​​of analog channels.

For an example of the practical implementation of the device and PWM control of various external devices, the following diagram is given. This example shows circuit solutions for connecting to 4 PWM channels of a fan motor, a powerful LED of the family, a PWM-to-voltage converter on an LM358 operational amplifier. And also for the possibility of testing general-purpose output lines, LEDs are connected.

An example of the implementation of the output stages of the PWM controller

Loading...Loading...