PWM Circuit explanation

For the discussion of Arduino related topics.

Moderator: phalanx

Post Reply
fivenine
Posts: 3
Joined: Tue Nov 07, 2017 5:08 pm

PWM Circuit explanation

Post by fivenine » Tue Nov 07, 2017 5:49 pm

If someone could please provide me a little explanation on the workings of this circuit and how these components are used to integrate with the code.

I have this code and project I want to implement for school but to be honest I lack a bit of knowledge on it and would like to understand it first instead of just buying components, wiring and downloading the code.

I don't know if this was the right place to post this but it is an Arduino based project so that was my thinking.
Any help appreciated thanks.

Image

Code: Select all

intledPin = 3;
void setup()
{
Serial.begin(9600);
Serial.println(“Serial connection started, waiting for instructions…n0 = Offn1 = 25%n2 =50%n3 = 75%n4 = 100%”);
}

void loop ()
{
if (Serial.available()) {
char ser = Serial.read(); //read serial as a character

switch (ser)
{
case ‘0’:
analogWrite(ledPin, 0);
break;

case ‘1’:
analogWrite(ledPin, 64);
break;

case ‘2’:
analogWrite(ledPin, 128);
break;

case ‘3’:
analogWrite(ledPin, 192);
break;

case ‘4’:
analogWrite(ledPin, 255);
break;
default:
Serial.println(“Invalid entry”);

}
}
}

n1ist
Support Volunteer
Posts: 1032
Joined: Wed Mar 22, 2006 11:02 am

Re: PWM Circuit explanation

Post by n1ist » Wed Nov 08, 2017 9:38 am

Be real careful; that design is NOT isolated from the AC line, and could kill you if you are not careful. The 33k and 22k resistors will run warm - make sure you choose them appropriately. I'd also go for a higher voltage bulk cap (C2).

If you are just doing this for a school project, I would power it from a low voltage (12 or 24VAC) transformer with the appropriate lightbulb and resistor changes. It would be much safer.

As for how it works, it is trying to dim the light by PWM'ing the 50Hz AC at about 500Hz. So for each cycle of the AC waveform, the output will be broken into segments and will be on for more or less of each segment. Imagine drawing a sine wave with a dashed line. The PWM level will control the length of each dash as compared to the space between the dashes. 500Hz may be a bit slow, so you will likely get flicker.

Traditional dimming is done by synchronizing to the AC line and turning the light on for some fraction of each cycle. This would require some more hardware to detect the zero cross.

As for the circuit, the FET is a DC device; that's why the bridge rectifier is needed. When the FET is off, the light is off. When the FET is on, the light is also on. The opto drives the gate of the FET and provides isolation between the arduino and the computer for safety. The rest of the parts form a low voltage low current power supply to provide a voltage to turn on the FET gate.
/mike

Valen
Support Volunteer
Posts: 1743
Joined: Wed Dec 22, 2010 2:05 am

Re: PWM Circuit explanation

Post by Valen » Wed Nov 08, 2017 9:47 am

Major warning!!!!

With your knowledge level I seriously advice AGAINST building this circuit! It is powered by live mains power. If you make a mistake in wiring, or if you attempt to build this on a breadboard, this circuit you could short-circuit itself and start a fire! Or worse, touching the bare components or wires in the wrong place you can electrocute yourself! Any teacher should have pointed that out to you!

N1ist does the explanation better.

fivenine
Posts: 3
Joined: Tue Nov 07, 2017 5:08 pm

Re: PWM Circuit explanation

Post by fivenine » Sun Nov 12, 2017 10:18 am

n1ist wrote:
Wed Nov 08, 2017 9:38 am

The 33k and 22k resistors will run warm - make sure you choose them appropriately. I'd also go for a higher voltage bulk cap (C2).
Can I ask how you go about determining this. What calculations are involved?
If you are just doing this for a school project, I would power it from a low voltage (12 or 24VAC) transformer with the appropriate lightbulb and resistor changes. It would be much safer.
I have been advised this as well, definitely looking into it thank you.
As for how it works, it is trying to dim the light by PWM'ing the 50Hz AC at about 500Hz. So for each cycle of the AC waveform, the output will be broken into segments and will be on for more or less of each segment. Imagine drawing a sine wave with a dashed line. The PWM level will control the length of each dash as compared to the space between the dashes. 500Hz may be a bit slow, so you will likely get flicker.
Is the actual AC signal that undergoes PWM, or is it the DC signal from the bridge rectifier?
As for the circuit, the FET is a DC device; that's why the bridge rectifier is needed. When the FET is off, the light is off. When the FET is on, the light is also on. The opto drives the gate of the FET and provides isolation between the arduino and the computer for safety. The rest of the parts form a low voltage low current power supply to provide a voltage to turn on the FET gate.
So the DC from the bridge rectifier is responsible for switching the FET on and off? Which in turn, switches the lamp on and off, after it is converted back to AC, is that correct in my understanding?

Slowly getting my head around the working of this, thanks for your time!

jremington
Support Volunteer
Posts: 2269
Joined: Fri Jun 15, 2007 9:41 pm
Location: Eugene, Or

Re: PWM Circuit explanation

Post by jremington » Sun Nov 12, 2017 6:01 pm

What calculations are involved?
Ohm's Law (V = IR) and power (Watts) = VI
Is the actual AC signal that undergoes PWM, or is it the DC signal from the bridge rectifier?
Both.
So the DC from the bridge rectifier is responsible for switching the FET on and off?
No, the microprocessor, via the optocoupler.

Here is a much safer circuit for experimentation (use a 12V automotive lamp):
Image

From post at http://bildr.org/2012/03/rfp30n06le-arduino/

n1ist
Support Volunteer
Posts: 1032
Joined: Wed Mar 22, 2006 11:02 am

Re: PWM Circuit explanation

Post by n1ist » Sun Nov 12, 2017 6:37 pm

Looking at the right side of the opto, there are two different circuits

One is a 10V power supply. This consists of D6 (as a rectifier), R3, R4, and R5 as a current limiter, D1 as a regulator, and C1 and C2 as storage caps. It is used to provide power so the optoisolator can turn on the FET.

Current in R3, R4, and R5 is ((1.414 * 230)-10)/(33k+33k+220R) = 4.8mA
Dissipation in R3 or R4 is 4.8ma*4.8mA*33k = 634mW so you would use a 1W resistor for these. As for why they used R3 and R4 in series, it's to limit the voltage across either. This way, you will get about 158V across each instead of 316V across one. R5 is to limit inrush when C2 first starts to charge. Note that C1 must be big enough to keep the power on even during times when the FET is on (effectively shorting out the input to the power supply section)

The other circuit is the switch. It consists of the transistor side of the optoisolator, the FET, and bridge. For this part of the circuit, don't look at the bridge as a device to convert AC to DC. Look at it as diodes.

When the FET is off, no current will flow between the two AC terminals as each pair of diodes D2, D3 and D4, D5 contains two diodes in opposite direction.

When the FET is on, think of it as a short between the positive and negative terminals of the bridge (that's close enough; it really is a low value resistor). When this happens, current will flow from the right AC input, through D2, the FET, and D5 back to the load during one half cycle, and D3, the FET, and D4 the other half cycle. In both cycles, however, the current flowing through the FET itself will always be in the same direction.

The optoisolator keeps the high voltage on the right side of the circuit separate from the low voltage stuff on the left. That includes your computer (if hooked up to the PIC with a programmer or serial port), and you (if there are buttons or controls hooked up to it). It, and the proper PC board layout, is there for safety.

fivenine
Posts: 3
Joined: Tue Nov 07, 2017 5:08 pm

Re: PWM Circuit explanation

Post by fivenine » Mon Nov 13, 2017 9:58 am

Thank you for the in dept explanation. Its given me a lot to read over and understand.

I'm still trying to grasp how PWM controls the intensity of the lamp. In the code, a range from 0 to 255 is provided from pin 3 of the Arduino, how is this translated back to an AC value to control the brightness?

Post Reply