Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PWM help for Pool lamp...

Status
Not open for further replies.
I just found this...
now can somebody help me to alter this as per my "specific" requirement?? Basically this is implementing a digital POT type thing instead of our old analog (and the easy one too)...

But I need the following::
Switch ON> Wait for 2sec>slowly glow and make full ON in around 2 sec. But this is auto... I mean I'll turn on the main power of the entire ckt... it will get VCC and on the power on, the uC will get power, the AC line will be connected through relay, the dimmer will start to work and the light will light up...

once I cut the power off... it's just plain power cut from the relay for 220V, and so the uC. (Here relay is just for fed the 12VAC through an isolation transformer)

Mishu~
 

Attachments

  • Digital dimmer using atmega8 _ AVR microcontroller projects.pdf
    53.7 KB · Views: 206

hi..
12VDC----100R/1W------LED
Now as I can't throw DC there, cable is 100ft long, and making some small rectifiers is not a matter for me... (Trust me...) now i just want a soft start for the AC part...
Let’s reformulate again: you start chasing a dead horse.
Using 12VDC or 12VAC, same situation, there are equal resistive losses in the power cables.
 

Your attached picture could work after reducing the value of R3 which can be calculated as follows:
The safest value (highest value):
R3_hi = Vpeak / Iopto_max
where:
Iopto_max = 1A
Vpeak = Vrms * 1.414 (Vrms is the possible maximum voltage of the AC supply)

Using the value R3_hi will let the trigger peak current much less than 1A due to the forward voltages of:
V_led ≈ 2.5V (since the current is rather small, spread to many LEDs)
V_rect ≈ 1.3V (of the full wave bridge)
V_sat ≈ 2V (of the opto triac)
V_be ≈ 0.8V (the input junction of the power triac)
Their sum:
V_fwd = V_led + V_rect + V_sat + V_be = 2.5 + 1.3 + 2 + 0.8 = 6.6V
Therefore the lowest limit of R3 could be:
R3_lo = (Vpeak - V_fwd) / Iopto_max

Let us suppose the maximum of Vrms = 14V
R3_hi ≈ 14*1.414 / 1 = 19.8 Ω
R3_lo ≈ (14*1.414 - 6.6 ) / 1 = 13.19 Ω

It seems that R3 = 15 Ω is a good choice.
So far, we walked 25% of the path to the final solution.

Important: Since the AC voltage is rather low, adding an optocoupler is not really necessary... What do you think?

The next step is to find the smallest trigger phase of the circuit (that is the highest controlled power or brightness).
This step needs two new values:
The minimum AC voltage, unless we assume it 12Vac as an average.
The power triac sensitivity (Ig), that is the minimum gate current by which the triac is turned on in quadrant I and III (that is V_A2A1 and V_GA1 have the same polarity).

---------- Post added at 01:36 ---------- Previous post was at 01:09 ----------


You are right.
So the only reason I have in mind for why AC is preferred, is its availability since the current is rather high (due to the installation constraints).

==========================================================================

Sorry I missed your post #21, please ignore what I wrote so far :-|

---------- Post added at 01:44 ---------- Previous post was at 01:36 ----------

About the zero cross detector you may like to have a look at:
https://www.edaboard.com/threads/213123/#post901109
 
Last edited:

Let’s reformulate again: you start chasing a dead horse.
Using 12VDC or 12VAC, same situation, there are equal resistive losses in the power cables.

okey, i'll throw a 12VDC again to check... but i'm sure... it wont work... but i checked and got confirmed that 12VAC worked... All I need is working... because the thing have to run... that's my goal... now if i have to chase a dead horse and an ultra fast elephant, doesn't matter...

To [KerimF] Sir,

Well, that I found... but i think I will have to re design the whole thing again... As low voltage issue, 50Hz, then a TRIAC is okey... (that part I missed and messed). Now I can give output to the TRIAC (just like old dimmers, but uC based PWM here)... all there I need is the frequency. I have choosen 100Hz (and thus i have to find out the proper XTAL and prescaler for PWM Freq.).
Next thing I will need is the zero cross detection just to make a phase match for perfect soft start. And this is the most tough thing for me... still I tried to find a out how the things work... tried to find some codes... but most codes are in C. I'm familier with microBasic. And there is no help in microBasic. Bascom just crashed and I lost the complete Bascom compiler.

Well, for 0 cross detection, i am planning to use a method of my own... as the uC is running, it will scan a pin (whatever, int0 or any pin) for 0. thus at level 0 of the sine, it will catch that 0. and it will start running just after that. (because I need to find the zero cross only once, the very beginning of the running to match the phase only.... as it will do a soft start, not a variable pwm based on push button)... what you think??

Mishu~

and KerimF sir,
I have seen this... the zero detector... seems nice... so I can use a standard bridge rectifier also right?? and at level zero, the uC will see 0 at it's pin or 1 at it's pin??

Also I liked the simulation software... can i know from where I get this?? this will help me a lot...
 
Last edited:

Before take any action you need to do a simple test, in order to find the line resistivity.
Apply a 12Vdc power supply (min 100W) at the point where you intend to have the power connected and connect the end of line a resistor (better a 12V car lamp). Measure the voltage end of the line. Compare with the voltage applied on the input line. If the value are quite high, you need to compensate by reducing the resistors on the last LEDs. (This may be done by using a second resistor in parallel. The necessary value depend on the line power losses measured during the test).

Finding the test resistor.
For a series of 30 LEDs in parallel at 90mA each -> up to a 2.7Amps on the power lines.
So: 12V/2.7A= 4.44 ohms /53W, (but that’s the worst case scenario)
The appropriate standard resistor = 4.7ohms/50W, or may use a car headlight of 55 watts.(In practice you may use any 12V lamps between 25-55W).


See the attached simulation for the cable losses (1.5 ohms/100 feet and 1 ohm/100 feet) and the necessary additional resistors to compensate.
 

Attachments

  • test lines.GIF
    test lines.GIF
    274.4 KB · Views: 72
Last edited:

You are right "aq_mishu" about the zero cross detection, I forgot that your triac will run on a low AC voltage (12V) so a rather simple detector is needed.
On the other hand, I am afraid that the conventional PWM won't work when using a triac. As you know, when a triac is triggered and turns on, it will stay in this ON state (assuming the load current is not too small) till the end of the half cycle (actually till its current be close to zero). The frequency is fixed (100Hz), so the starting dead phase (or angle) only could be changed.

About the circuit simulator, you have many choices... In my case, I use a professional and free one called LTspice. There is also a friendly Yahoo group for it with plenty of examples.
 

Dear KerimF Sir,
Thanks for the reply... well if a triac is not working in that way, then how the dimmers work?? I have seen those RC dimmers... and they are doing this job... the fan regulators... so I am looking for the same, a fan regulator, that will increase the voltage gradually... like if I twist the knob gradually...

idea??

because it is like first i want to pass 10% of the both cycles, then 20% and so on till 100% of the both cycles...
 

... because it is like first i want to pass 10% of the both cycles, then 20% and so on till 100% of the both cycles...

This is good... so where is the problem? I guess you get an interrupt at each cross zero. In the interrupt routine you set a timer counter for the on time (actually 65536-OnTimeDelay). When the MCU is interrupted by this timer (say after 1ms), the triac is turned on (though I prefer trigger the triac by a negative current for which the gate sensitivity is better but this is not important here). After this, you will have many choices to turn off the output:
(1) By including in the timer interrupt a delay loop (say for 20us or more) then the output is turned off.
(2) By reloading the same timer counter with on pulse width time (after which the output is turned off). In this case, you need two flags at the entry of the timer interrupt to distinguish between the two stages.
(3) By setting, in the zero cross interrupt, another timer counter for a longer time (the difference will be the pulse width at the output).

Notes:
For narrow or wide output on-pulse, the triac output current, unlike of a transistor, will (should) turn off at the end of the half cycle.
But if the gate current is turned off while there is no sufficient current in the triac load, the triac will be turned off again and this is not desirable.

So while triggering a triac by a relatively narrow pulse in each half cycle saves power, the triac may miss to turn on completely in all half cycles. This could happen if the load is inductive for example and the pulse is near the zero cross hence the AC voltage is small on the inductive load. And even the triac may be able turn on in one half cycle, the lagging (inductive) current after the next zero cross will add a delay time to turn it off in which the new narrow pulse could be missed (in this case the triac acts as a half wave rectifier).

In your case I recommend (without going to details to explain why) to use the widest pulse as possible. For example the off time delay could be set always to be 9ms or 9.5ms (if 50Hz) after zero cross. And you will notice that the LED brightness will not be linear with on time delay (starting for example from 1ms) but this is also not very important here.
I think you will be able to decide on your final values, after testing only.

Added:
There is a time offset to take care of which is the time difference between the edge of the interrupt signal and the AC zero cross. This difference will likely change if the AC voltage which drives the detector input, changes.

Kerim
 
Last edited:

Dear Sir,
I have an exam today and I just started to study from last night... thus i'll read and discuss on it later in detail... meanwhile, all I can say is zero cross detection is a nightmare for me... and this is one big reason still i can't solve one of my previous issue of project of calculating freq... however, that's not part of it...

for pwm, i can use a method from mikrobasic, called inverted pwm. This will create the pwm from the opposite side... like normally pwm is created from zero to half cycle of the duty, from left... but using this inverted mode, it will create from right... and will move to left... I think I can use that as triacs need to be cut off at zero crossing.

for zero cross, using timer means nightmare... instead, i think as i have to read the moment (not timing) of zero crossing just for once for phase matching, i can use a simple i/o machanism, where say i/o pin PB1 is goes low (due to MOC low at sine zero or vice versa as per ctk), i can read as follows...

duty = 255 '100% duty
set_pwm = inverted

if PORTB.1 = 0 then
while TRUE 'forever loop
for i=5 to duty step 5
do_pwm(duty)
delay_ms(timing)
next i
loop
end if
/////////

or each time i need to read the zero and then to do pwm with incr of duty than before?? I think each time...

let me do some ground work after the exam... i think i'm missing something and probably i'm thinking of just one half cycle, instead of the cycles... let me do some pencil sketch...
 

guys,
got some idea...

As i need the thing like this picture... where it will gradually increase..., my goal is to use the PWM first (if i fail, then natural 100Hz-some_time for on state...). I'm using mikroBasic for AVR. It has a PWM function for inverted PWM. Where the duty 25% cycle starts not from the zero, but from the last. This means actually the duty starts at (100-25) and stays till 100. and incase of increment, it increases from left. thus a duty=x means the pulse starts at (100-x) duration.

Now I i need to have this waveform (attached file) for the triac output, I think this will help me. Because Triacs fired, and thus it remains ON till next zero crossing. So my plan is now as follows::

Code:
Step 1: Set duty=5
Step 2: Detect Zero Cross
Step 4: if zero cross not detected, return to step 2.
Step 5: Zero cross detected. Init PWM with duty in inverted mode
Step 6: PWM on for duty for first half cycle
Step 7: PWM on for duty for next half cycle
Step 7: increment duty to duty+5
Step 8: Goto Step 2 until duty=255
Step 9: PWM with full duty
Step 10: Goto Step 9

This way, I will have to check the zero cross for each cycle... (not half cycle). And once the duty is full, it will be ON forever. I just will have to add some delay for a nicer glow effect in the steps, thatI need to figure out... but not a tough thing I hope... may be some big loops (cascaded loops)

Planning to use MOC for zero cross and also MOC for TRIAC. Freq is 100Hz, but i'm not sure which XTAL to take... thinking of taking 3.9 MhZ instead of plain 4. And need to tune up the timing incase of a phase miss (due to freq) with adding some small uS delay based on the reading of Line freq and uC freq.

Mishu~

Mishu~
 

Attachments

  • New Bitmap Image.bmp
    845 KB · Views: 93

Are you familiar in implementing a delay using a timer interrupt?

Since I can't get any high language compiler, I used to write my uC firmware in assembly always but this helps me to get exactly what I look for. So I have no idea on the functions provided by mikroBasic for example. In assembly, firing a triac is rather simple. Two times are needed after zero cross; delay before ON and delay before OFF (in each half cycle), the OFF delay is longer than the ON delay. And since the zero cross edge may not occur exactly at 0 volt, a time offset will be added to (or substrated from) the two delays.
Example:
"On delay" can be varied from 1ms to 8.5ms (+/- zeroOffset)
"OFF delay" could be made fixed as 9ms (+/- zeroOffset)
The exact values are not important.
By using a higher crsytal frequency, one can get higher time accuracy.

Edited:
Sometimes I may have a 50Hz interrupt only. In this case, when serving the ON delay interrupt I reload its timer to get a delay of 10ms (with the hope that the mains is exactly 50Hz) for the next ON timing. I do the same when serving the OFF delay interrupt.
 
Last edited:
dear sir,
the actual Timer of AVR (int0) is a nightmare for me...

instead normally i use to sense a signal, then i just call the delay (which halts the execution) for a certain time instead of a timer counter. (this is one big reason I still am not able to calculate frequency in AVR).

Thus i am planning to use zero cross detection in the case of IF ZERO CROSS DETECTED, then go for next step. There i'll try with PWM first... but dafinitely if I fail, then I will use the plain timing delay to on and off (i call manual software pwm)... and in this case, I just need the internal 4MHz oscillator, not even an external XTAL. EXT XTAL is needed only when I want to do the hardware PWM.

I have understood, I need to first calculate the timing, get some sample from the oscilloscope of the 220VAC scaled down to 12VAC. then analyze and then get the timing for ON/OFF and then do zero cross... incase of a little correction required, I will need to drift the ON time. For gradual increment of voltage at AC side, i can just reduce the ON time Delay... (which is a wider wave in pwm)

I think i am right... am I?
Mishu~

PS. I need one BIG help from you... lateron, I'll require some help on calculating frequency... (as i am very poor in timer int)
 

So you prefer waiting for the zero cross signal (level change) using a small loop.
Then you enter another loop and at its end you output the on pulse.
Again you enter another loop so at its end you turn of the output pulse.
This will be for one half cycle.
Am I right?

Added:
The first step is to design a simple zero-cross detector driven by the 12V AC source.
To work properly, we need to know first the possible range of the AC source. It will likely follow the mains voltage. But we have to decide on the voltage range to take it into account while designing the detector. Let me try helping you... For example your mains voltage could vary from 180V to 240V and the LED AC source is 12V (rms) @220Vac. In this case the range would be:
V_hi = 12 / 220 * 240 = 13.1 V
V_lo = 12 / 220 * 180 = 9.8 V
Please correct the example values using your real conditions. Could you?
 
Last edited:

hellow sir,
in general, the voltage is pretty much stable there... but well, i'm considering the range you given... because that's for sure, it will be within this...

and yes... each half cycle... once zero detected, on time, pulse... then off on a specific constant time... (because triacs only need to trigger ON). Then for next half cycle, again the same thing... This means I'll make this run faster than 100Hz...

Mishu~
 

hellow sir,
... then off on a specific constant time... (because triacs only need to trigger ON).

Yes a triac needs only to be trigged on.
It is better to remember that if the ON pulse is relatively narrow and during which the load current is not enough to keep the triac on, it turns back to the off state during the rest of the half cycle.

So it seems it is hard for you to measure the actual ratio (Vout/Vmains) of your AC power supply.
Sorry for asking you many questions but this is how I use to think when working; the end design cannot be more accurate than the given data.

Kerim
 

it's okey sir... now i am approaching step by step... the very first thing for me is to making the zero cross detector... so i have checked your ctk for 50hz. but it's working on direct 220 right?? instead if i want to use a 12V transformer stepped down, then i think this will be better as 220v is not at the PCB. So can you suggest me what alter i need to do in your ckt for this to operate in 12VAC? And I really have to measure 0v there as even 1v will tell the uC that it is zero. Basically any voltage below 2.5 will tell a zero state... (I am not using int0 counter... that's a nightmare for me...) thus i have to reach upto 0 instead of 2.5. ADC is a good option, but I prefer pin state as that one is much faster... so idea on zero crossing detection by mega8 with 12VAC??

Mishu~
 

The attached solution is a practical circuit using a transistor instead of an opamp.

An initial delay of about 1.1ms is not long. But you can decrease C1 to let it shorter.
R4 is included if both edges generate a trigger so letting them at the same distance from zero volt may be convenient. R4 can be removed and the time difference is compensated in software instead.
Obviously the output of this simple circuit is sensitive both to Vac and temperature (because of Q1 Vbe).
 

Attachments

  • ZC-12V_01.png
    ZC-12V_01.png
    115.5 KB · Views: 71
Last edited:

can I use optocoupler instead of a the transistor?? and also can I use 2N2222A for Transistor??
 

can I use optocoupler instead of a the transistor?? and also can I use 2N2222A for Transistor??

You can use an optocoupler and 2N2222A is also good.

If the cathode of the triac (wrong terminal name but it is easier to understand if we look at the triac being a thyristor :smile: ) is not connected to the controller circuit (also by using an optocoupler between the power triac and the circuit output), it is obvious that another optocoupler should be used for the zero-crossing detector. These two optoisolators are important in case the AC supply has a relatively high voltage (as 110V or 220V). So in case of 12 AC voltage, there is no need for electrical isolation but... :wink: Since I have no sure idea if your controller has a common node (called reference or ground) with the 12V AC supply or not, I cannot give you the final solution for both the input and output.

Kerim

Note: Did you install a simulator?
The one I use is "LTspice", it can be downloaded for free and there is a Yahoo group for help (with a large archive for models and examples since it is for amateurs and professionals)
 
Last edited:

Dear sir,
sorry for the late reply... i was at the hotel site for the job... i still did not get chance to work on it after the last post... i'll start work soon...

meanwhile, well... still thinking if i should use 220/12vac... i'll try with both. and i'll try to use opto-isolator as that's i think best. I already have the LT-Spice. Will install it soon and will start working on it. seems nice to me this...

I'm i think will go towards 220v direct for triac and zero cross... but 300V must be scaled down to 5V for opto isolator zero cross detection. Triac will get direct 220v and from there, it will go to transformer. Because if I use the 12V at triac, then the amp on the pcb will be high and i will need damn thick traces.

Mishu~
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top