Smart Voltage Stabilizer Using PIC16F877A
Voltage stabilizers are used for many appliances in homes, offices and industries. The mains supply suffers from large voltage drops due to losses on the distribution lines en route. A voltage stabilizer maintains the voltage to the appliance at the nominal value of around 220 volts even if the input mains fluctuates over a wide range.
Here is the circuit of an automatic voltage stabilizer that can be adapted to any power rating. Its intelligence lies in the program on PIC16F877A—a low-cost microcontroller that is readily available. The circuit, when used with any appliance, will maintain the voltage at around 220V even if the input mains voltage varies between 180V and 250V.
Here the circuit is shown for a 5A stabilizer. It acts within 100ms to produce a smoothly varying output whenever input mains voltage changes. (Servo stabilizers move a variable contact on a toroidal auto transformer to adjust the output when input goes up and down, which takes seconds.)
The PIC16F877A is an RISC (reduced instruction set computer) microcontroller with 35 instructions, and hence program development with it is rather tough. But, there are good support programs.
Circuit description:
The circuit is divided into two sections as it is easy to test them separately: voltage stabilizer controller and voltage stabilizer buck-boost. The sections can be joined easily.
Here is the circuit of an automatic voltage stabilizer that can be adapted to any power rating. Its intelligence lies in the program on PIC16F877A—a low-cost microcontroller that is readily available. The circuit, when used with any appliance, will maintain the voltage at around 220V even if the input mains voltage varies between 180V and 250V.
Here the circuit is shown for a 5A stabilizer. It acts within 100ms to produce a smoothly varying output whenever input mains voltage changes. (Servo stabilizers move a variable contact on a toroidal auto transformer to adjust the output when input goes up and down, which takes seconds.)
The PIC16F877A is an RISC (reduced instruction set computer) microcontroller with 35 instructions, and hence program development with it is rather tough. But, there are good support programs.
Circuit description:
The circuit is divided into two sections as it is easy to test them separately: voltage stabilizer controller and voltage stabilizer buck-boost. The sections can be joined easily.
Voltage stabilizer controller section:
This part of the circuit is built around the PIC microcontroller (see Fig. 1). The 5V supply for the microcontroller is derived from a small iron-core mains step-down transformer having 9-0-9V, 300mA rating, two diodes (1N4007) and a 1000μF capacitor followed by the 7805 regulator.
The ADC input channel 0 at port-A pin 2 of IC2 is used as shown in Fig. 1. Here potentiometer VR1 is connected to +5V and ground through a jumper connection. For the purpose of testing, you can vary VR1 to adjust the voltage from 0 to 5V. The reset circuitry at pin 1 (MCLR) has capacitor C1 and resistor R1. Pin 30 (port-D bit 7) gets a signal (marked as ‘D’) derived from the mains supply. Pins 17 and 16 (CCP1 and CCP2) provide the actual pulse output signal that helps in stabilizing the mains power. The signal is a set of equally spaced pulses at about 8 kHz for a 12MHz crystal.
The pulses from pins 16 and 17 are buffered using a pair of inverter gates of high current
driver IC ULN2003. Note that the gates in this chip need pull-up resistors Fig. 1: Circuit of voltage stabilizer controller section at the output pins. So at points marked ‘A’ and ‘B’ we get two pulse trains from the microcontroller. Synchronization with the mains supply is achieved by the square wave (50Hz mains derived) on port-D bit 7 (pin 30).
Transistor T3 (BC547) produces a rectangular pulse from the half-wave rectified low voltage (9V) from the transformer (9V-0-9V, 300mA). Using 50 Hz as reference for positive and negative half cycles of the mains supply, it produces the pulses at A and B points in turn. These pulses change in width and are hence called pulse width modulated. The width varies in accordance with the voltage to be produced for compensating the voltage from mains supply.
After wiring the circuit, program the chip with the given Assembly program. Insert the chip into the board and apply power supply. The chip has two PWM pins, 16 and 17. Adjust the shaft of pot-meter VR1 (10-kilo-ohm) to the bottom position for zero voltage. Also, ground pin D. The PWM pulse is now available from pin 17 of IC2, while pin 16 is low. If the shaft of the potmeter is moved to the top position when ‘D’ is connected to ground, pulses will be available from pin 16. Taking pin D to 5V reverses the above sequence. After checking this part of the circuit, the circuit shown in Fig. 2 may be tested.
In manual position of input selection switch S1 (Fig. 1), the analogue input voltage from pot-meter VR1 is used. In this position, the circuit functions as a variac that varies the output voltage from 180V to 250V as the pot-meter is varied.
In auto position of S1, the circuit acts as a stabilizer. For this, transformer rectified supply derived from the mains provides a proportional voltage to the ADC of the chip.
Point E in the voltage stabilizer controller circuit gives a voltage that varies with mains voltage. At exactly 220V mains, the 9V transformer (X1) gives a peak voltage of 9√2 =12.7V and subtracting 10V using zener diode ZD1 gives 2.7V at point E. It increases to 5V when the mains voltage rises to 259V and drops to zero when mains drops to 172V in effect, giving 0 to 5V over this range.
Using this voltage at point E, you can assess variation in the mains voltage and thereby control the PWM based sine voltage for adding (boost) or subtracting (buck) from mains. Point E is connected to the ADC input pin (point C) of the PIC in auto position (Fig. 1).
The buck-boost principle:
Voltage stabilizers buck (subtract) the mains voltage if it is higher than 220V and boost (add to) the mains voltage if it is lower than 220V. For this purpose, you need to produce a small voltage to do addition or subtraction. In Fig. 3, the mains voltage waveform is shown in the top left corner, with two voltages of smaller amplitude (about 30V) shown below it. One of these two voltages is in the same phase as the mains voltage, while the other is out of phase. By adding any of the two voltages, you can boost or buck the mains voltage.
For this purpose, ordinary voltage stabilizers generate a small voltage using a transformer with one or more taps. They connect the small voltage in series with the mains supply so as to add or subtract from it. A changeover relay is used to switch to buck/boost, while another relay selects between voltages from the two taps.
This method does not produce a smooth voltage change due to relay switching and the voltage from tap produces a fixed value (instead of a finely-variable voltage). In this project, the additional voltage of about 30V in phase or out of phase with the mains voltage is finely variable because of PWM. So it produces a smoothly varying output.
A typical PWM concept is shown in Fig. 4. The microcontroller produces pulse-widths, as required, for generating the voltage to be added or subtracted from the mains. The pulses from points A and B (refer Fig. 1) are fed to the transformer shown in Fig. 2. The secondary winding of this transformer gives the adding voltage. In this case, there is no relay switching; the buck or boost is done smoothly by changing the phase of the adding signal instantly. So it is a continuous voltage stabilizer. Depending on how much the input varies from 220V, pulse width is generated so as to adjust the output voltage by adding or subtracting from it. This is a feed-forward control.
Points marked ‘com’ common points in Figs 1 and 2 are not the ground and should not be connected to the neutral line.
Take care while checking the buck/boost circuit, as all the points are ‘hot’ and will give electric shock if touched, and also when interconnecting the voltage stabilizer control and buck-boost circuits.
Pulse-drive circuit and the transformer:
Fig. 2 shows the circuit to buck/boost the mains voltage using a buck-and-boost transformer. The iron core transformer used here is the same as used in voltage stabilizers. There is no tap on the secondary winding and the primary winding is center-tapped.
As with most transformers, the stampings used for this transformer are made of 4mm thick silicon steel. These are E-I type Stalloy/CRGO stampings. The size of the stampings depends on the rating. A toroidal winding transformer gives better performance and is smaller in size.
Here, we have used a 250V-0-250V, 500mA primary to 50V, 5A secondary transformer. The windings’ number of turns depends on the core size used.
Pulses from A and B of the voltage stabilizer controller circuit are fed to the gate pins of MOSFET power transistors (IRF840) via 10k series resistors. There are also 100-kilo-ohm grounding resistors connected to the transistors’ gates. The drains (D) are connected to the winding ends of transformer X2. The center tap of the primary winding is connected to the rectified DC supply from the mains. (This rectified voltage is not filtered; it is just unfiltered, rectified sine wave at point P.)
The power transistors (IRF840) switch the rectified sine voltage supply at the PWM frequency produced by the microcontroller. To smooth out the pulse switching, a 2.5μF, 400V AC fan capacitor is connected across the primary winding of transformer X2. The voltage induced in the secondary winding is a sine wave whose amplitude depends on the width of pulses at points A and B. The program changes the PWM width, and thus the amplitude of the sine wave, to adjust the mains voltage to 220V level.
We thus get a sine wave of the mains frequency. By serially adding the secondary voltage to the input mains voltage we get the stabilized voltage at the output of the unit.
On alternate half cycles, pulses at points A and B arrive to make either of the two transistors T1 and T2 conduct and allow the current to flow through the primary winding. A 2.5μF, 400V AC capacitor is required across the primary winding of transformer X2. Otherwise, only the pulses from A will pass through and buck and boost cannot be obtained.
In manual position of the switch, when potmeter VR1 is varied from bottom to top (0 to 5V), the voltage across the secondary decreases, crosses zero and then increases again. This means the secondary voltage varies with the potmeter position. Check the variation in secondary voltage by using a voltmeter, or a multimeter set to 50V AC range. The voltage should increase on either side of the mid-point of VR1. In auto position, combining the secondary output voltage of transformer X2 with the mains voltage gives you the stabilized output.
Testing:
Measure the AC voltage across the secondary output of transformer X2. Vary VR1 in the
controller section and check whether the voltage output at the secondary of X2 varies.
A CRO can be used to observe this secondary voltage. It should be 50Hz sine wave, but if
it has a break, it means the half cycles are not synchronized.
In Fig. 1, at point E, we have included a lag circuit comprising variable resistor VR2 (5 Kilo-ohm) and capacitor C5 (10μF). Adjust preset VR2 until the waveform is a smooth sine wave.
There may be small ripples in the first half of each cycle, but these do not matter and will
anyway be present due to PWM switching. Capacitor C7 (2.5μF) across the primary winding of transformer X2 filters them out.
The secondary voltage of transformer X2 should decrease and then increase as VR1 is raised from 0V position. Then check voltage regulation after changing over to auto position in Fig. 1. Adjust VR1 to the center position precisely. In the center position, there will be no pulse and therefore no adding voltage in the secondary winding. So the value of the zener diode used in the rectifier circuit should be changed in order to get 0V for 220V input. A variac is useful for varying the input voltage and checking the output.
Capacitor C6 (0.1μF) at the output terminals of X2 removes minor ripples, if any, in the waveform.
The optional input voltage display circuit consists of three common-anode, seven-segment LEDs (each LTS542) shown in Fig. 5. The seven-segment LED displays are driven from port-B of the chip in a multiplexed manner. The anode selections are made through bits 0 through 2 from port-D via transistors T4 through T6, respectively.
This part of the circuit is built around the PIC microcontroller (see Fig. 1). The 5V supply for the microcontroller is derived from a small iron-core mains step-down transformer having 9-0-9V, 300mA rating, two diodes (1N4007) and a 1000μF capacitor followed by the 7805 regulator.
The ADC input channel 0 at port-A pin 2 of IC2 is used as shown in Fig. 1. Here potentiometer VR1 is connected to +5V and ground through a jumper connection. For the purpose of testing, you can vary VR1 to adjust the voltage from 0 to 5V. The reset circuitry at pin 1 (MCLR) has capacitor C1 and resistor R1. Pin 30 (port-D bit 7) gets a signal (marked as ‘D’) derived from the mains supply. Pins 17 and 16 (CCP1 and CCP2) provide the actual pulse output signal that helps in stabilizing the mains power. The signal is a set of equally spaced pulses at about 8 kHz for a 12MHz crystal.
The pulses from pins 16 and 17 are buffered using a pair of inverter gates of high current
driver IC ULN2003. Note that the gates in this chip need pull-up resistors Fig. 1: Circuit of voltage stabilizer controller section at the output pins. So at points marked ‘A’ and ‘B’ we get two pulse trains from the microcontroller. Synchronization with the mains supply is achieved by the square wave (50Hz mains derived) on port-D bit 7 (pin 30).
Transistor T3 (BC547) produces a rectangular pulse from the half-wave rectified low voltage (9V) from the transformer (9V-0-9V, 300mA). Using 50 Hz as reference for positive and negative half cycles of the mains supply, it produces the pulses at A and B points in turn. These pulses change in width and are hence called pulse width modulated. The width varies in accordance with the voltage to be produced for compensating the voltage from mains supply.
After wiring the circuit, program the chip with the given Assembly program. Insert the chip into the board and apply power supply. The chip has two PWM pins, 16 and 17. Adjust the shaft of pot-meter VR1 (10-kilo-ohm) to the bottom position for zero voltage. Also, ground pin D. The PWM pulse is now available from pin 17 of IC2, while pin 16 is low. If the shaft of the potmeter is moved to the top position when ‘D’ is connected to ground, pulses will be available from pin 16. Taking pin D to 5V reverses the above sequence. After checking this part of the circuit, the circuit shown in Fig. 2 may be tested.
In manual position of input selection switch S1 (Fig. 1), the analogue input voltage from pot-meter VR1 is used. In this position, the circuit functions as a variac that varies the output voltage from 180V to 250V as the pot-meter is varied.
In auto position of S1, the circuit acts as a stabilizer. For this, transformer rectified supply derived from the mains provides a proportional voltage to the ADC of the chip.
Point E in the voltage stabilizer controller circuit gives a voltage that varies with mains voltage. At exactly 220V mains, the 9V transformer (X1) gives a peak voltage of 9√2 =12.7V and subtracting 10V using zener diode ZD1 gives 2.7V at point E. It increases to 5V when the mains voltage rises to 259V and drops to zero when mains drops to 172V in effect, giving 0 to 5V over this range.
Using this voltage at point E, you can assess variation in the mains voltage and thereby control the PWM based sine voltage for adding (boost) or subtracting (buck) from mains. Point E is connected to the ADC input pin (point C) of the PIC in auto position (Fig. 1).
The buck-boost principle:
Voltage stabilizers buck (subtract) the mains voltage if it is higher than 220V and boost (add to) the mains voltage if it is lower than 220V. For this purpose, you need to produce a small voltage to do addition or subtraction. In Fig. 3, the mains voltage waveform is shown in the top left corner, with two voltages of smaller amplitude (about 30V) shown below it. One of these two voltages is in the same phase as the mains voltage, while the other is out of phase. By adding any of the two voltages, you can boost or buck the mains voltage.
For this purpose, ordinary voltage stabilizers generate a small voltage using a transformer with one or more taps. They connect the small voltage in series with the mains supply so as to add or subtract from it. A changeover relay is used to switch to buck/boost, while another relay selects between voltages from the two taps.
This method does not produce a smooth voltage change due to relay switching and the voltage from tap produces a fixed value (instead of a finely-variable voltage). In this project, the additional voltage of about 30V in phase or out of phase with the mains voltage is finely variable because of PWM. So it produces a smoothly varying output.
A typical PWM concept is shown in Fig. 4. The microcontroller produces pulse-widths, as required, for generating the voltage to be added or subtracted from the mains. The pulses from points A and B (refer Fig. 1) are fed to the transformer shown in Fig. 2. The secondary winding of this transformer gives the adding voltage. In this case, there is no relay switching; the buck or boost is done smoothly by changing the phase of the adding signal instantly. So it is a continuous voltage stabilizer. Depending on how much the input varies from 220V, pulse width is generated so as to adjust the output voltage by adding or subtracting from it. This is a feed-forward control.
Points marked ‘com’ common points in Figs 1 and 2 are not the ground and should not be connected to the neutral line.
Take care while checking the buck/boost circuit, as all the points are ‘hot’ and will give electric shock if touched, and also when interconnecting the voltage stabilizer control and buck-boost circuits.
Pulse-drive circuit and the transformer:
Fig. 2 shows the circuit to buck/boost the mains voltage using a buck-and-boost transformer. The iron core transformer used here is the same as used in voltage stabilizers. There is no tap on the secondary winding and the primary winding is center-tapped.
As with most transformers, the stampings used for this transformer are made of 4mm thick silicon steel. These are E-I type Stalloy/CRGO stampings. The size of the stampings depends on the rating. A toroidal winding transformer gives better performance and is smaller in size.
Here, we have used a 250V-0-250V, 500mA primary to 50V, 5A secondary transformer. The windings’ number of turns depends on the core size used.
Pulses from A and B of the voltage stabilizer controller circuit are fed to the gate pins of MOSFET power transistors (IRF840) via 10k series resistors. There are also 100-kilo-ohm grounding resistors connected to the transistors’ gates. The drains (D) are connected to the winding ends of transformer X2. The center tap of the primary winding is connected to the rectified DC supply from the mains. (This rectified voltage is not filtered; it is just unfiltered, rectified sine wave at point P.)
The power transistors (IRF840) switch the rectified sine voltage supply at the PWM frequency produced by the microcontroller. To smooth out the pulse switching, a 2.5μF, 400V AC fan capacitor is connected across the primary winding of transformer X2. The voltage induced in the secondary winding is a sine wave whose amplitude depends on the width of pulses at points A and B. The program changes the PWM width, and thus the amplitude of the sine wave, to adjust the mains voltage to 220V level.
We thus get a sine wave of the mains frequency. By serially adding the secondary voltage to the input mains voltage we get the stabilized voltage at the output of the unit.
On alternate half cycles, pulses at points A and B arrive to make either of the two transistors T1 and T2 conduct and allow the current to flow through the primary winding. A 2.5μF, 400V AC capacitor is required across the primary winding of transformer X2. Otherwise, only the pulses from A will pass through and buck and boost cannot be obtained.
In manual position of the switch, when potmeter VR1 is varied from bottom to top (0 to 5V), the voltage across the secondary decreases, crosses zero and then increases again. This means the secondary voltage varies with the potmeter position. Check the variation in secondary voltage by using a voltmeter, or a multimeter set to 50V AC range. The voltage should increase on either side of the mid-point of VR1. In auto position, combining the secondary output voltage of transformer X2 with the mains voltage gives you the stabilized output.
Testing:
- First, test the controller circuit (Fig. 1) for pulse width modulated signals at points A and B. Check changeover from A to B by applying 0V and 5V at point D.
- Check the circuit for a square wave of 5V amplitude at point D during positive half cycles of AC mains. This square wave is generated by the transistor fed with the unfiltered low voltage DC from transformer X1.
- Vary the pot-meter in manual position of the switch. Using a CRO, you can see variation in the pulse-width (see Fig. 4).
- As VR1 is adjusted beyond the mid position, pulses at points A and B toggle.
Measure the AC voltage across the secondary output of transformer X2. Vary VR1 in the
controller section and check whether the voltage output at the secondary of X2 varies.
A CRO can be used to observe this secondary voltage. It should be 50Hz sine wave, but if
it has a break, it means the half cycles are not synchronized.
In Fig. 1, at point E, we have included a lag circuit comprising variable resistor VR2 (5 Kilo-ohm) and capacitor C5 (10μF). Adjust preset VR2 until the waveform is a smooth sine wave.
There may be small ripples in the first half of each cycle, but these do not matter and will
anyway be present due to PWM switching. Capacitor C7 (2.5μF) across the primary winding of transformer X2 filters them out.
The secondary voltage of transformer X2 should decrease and then increase as VR1 is raised from 0V position. Then check voltage regulation after changing over to auto position in Fig. 1. Adjust VR1 to the center position precisely. In the center position, there will be no pulse and therefore no adding voltage in the secondary winding. So the value of the zener diode used in the rectifier circuit should be changed in order to get 0V for 220V input. A variac is useful for varying the input voltage and checking the output.
- Activate the buck-and-boost circuit by closing stabilizer switch S2 (Fig. 2).
Capacitor C6 (0.1μF) at the output terminals of X2 removes minor ripples, if any, in the waveform.
The optional input voltage display circuit consists of three common-anode, seven-segment LEDs (each LTS542) shown in Fig. 5. The seven-segment LED displays are driven from port-B of the chip in a multiplexed manner. The anode selections are made through bits 0 through 2 from port-D via transistors T4 through T6, respectively.