Triac Firing Angle for dimming AC Lamp

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I want to build AC lamp dimmer circuit using ATmega8535. I've build the zero crossing circuit but now I have a problem with Triac firing angle. The complete circuit is shown in the attachment. That simulation result is before the MOC3021 connected to the MCU.

This is my code,

#include 
#include 

interrupt [EXT_INT0] void ext_int0_isr(void)
{
    PORTD=0x02;     // Output delay
    delay_ms(1);
    PORTD=0x00;
}


void main(void)
{
    DDRD=0x02;      // PORTD pin1 as output
    DDRB=0x01;      // PORTB pin0 as TRIAC input (MCU output)
    
    GICR|=0x40;     // Interrupt at PORTD pin2
    MCUCR=0x01;
    MCUCSR=0x00;
    GIFR=0x40;


#asm("sei")

PORTB = 0X01;       // initially triacs off

while(1)
{
while(PORTD.2 == 1) // zero crossing detected
{
PORTB = 0x01;
delay_us(500);
PORTB =0x00;
}
while(PORTD.2 == 0) // half cycle of ac reached
{
PORTB = 0x01;
delay_us(500);
PORTB = 0x00;
}
}
}

Can anybody tell me what's wrong here? and what should I do?

Plus, proteus says timestep too small when I startthe simmulation.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The 330R Resistor, needs to be lowered (180R to 220R),
because the MOC3021 emmiter needs from 15mA to 60mA (absolute maximum).
Also the 10k Resistor on the output seems to big to me.
What triac is the output one?
Are we talking about 230V or 115V AC circuit?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For starters, have they changed how the terminals of a TRIAC are symbolized? I'm used to the gate terminal being depicted as a diagonal line emerging from the same side of the TRIAC as "main terminal 1", which is (or should be) the common terminal between the firing and load circuits. Triggering current should flow into the gate, through some junctions in the TRIAC, and out through main terminal #1. You've shown an optoisolated TRIAC as completing a circuit between main terminal #1 and the gate, so that if you fired the opto triac, it would clamp the gate down to within a volt or so of main terminal #1. When the opto-triac is OFF, zero current flows through it and therefore zero triggering current flows in the main triac. When the opto-triac is ON, it will short the gate-to-MT1 junctions of the power TRIAC to a low voltage, and, again, no triggering current will flow, and the main power triac will stay OFF in that condition too. To my eye, you've drawn a very expensive, microcontroller-aided open circuit.

But maybe TRIAC symbology has changed while I wasn't looking, so that they're drawing gates as coming from the MainTerminal #2 side nowadays. In that case, R7 is far too wimpy at 10Kohms. It should only be 150 to 300 ohms or so.

Also, your zero-crossing detector has R1, R3, and R4 all in series. No purpose that I can see is served by this; you'd be better off to lump them all into one 14.8K resistor. But the tolerances for this sort of thing are extremely loose anyway, so I'd just keep the 10Kohm R1 and remove R4. The 4.7Kohm resietor R3 you could keep to encourage the U2 optoisolator's LED to turn off when the AC supply goes low enough that the bridge rectifier's diodes go high-impedance, but you should connect it across the terminals of U2's LED instead of in series with the LED.

Observations about the code:

You should not be putting a busy-wait loop (the "delay_ms(1)" call) inside an interrupt service routine. At least, I think your first routine is intended as an interrupt-service; I'm not familiar with its syntax.

And why bother with an interrupt service routine for the zero-crossing signal anyway, given that your main() routine constantly polls that pin?

The rest of the code looks like it's built to generate narrow (however long it takes your compiler how to figure out what state the zero-crossing signal is in) LOW pulses on Bit 0 of PortB, at a 2KHz rate. That's only if the zero-crossing signal is HIGH, of course; otherwise, the program generates short LOW pulses on Bit0 of PortB at a 2KHz rate (exactly the same behavior as when the zero-crossing signal was High, in other words).

The interrupt seems to be set up so as to suspend (gobbling up all the CPU time) these otherwise-constant 2KHz pulse streams for one millisecond after any change in the zero-crossing status.

If the wiring of the TRIACs actually is such as to allow U1 and U4 to fire, then I apologize for having mis-characterized the circuit as an expensive way (relative to just unscrewing it) of NOT putting current through a lightbulb. Instead, it's an expensive way (relative to flipping a light-switch to ON) of having it be ON all the time.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Levenkay wrote:
I think your first routine is intended as an interrupt-service; I'm not familiar with its syntax.

interrupt [EXT_INT0] void ext_int0_isr(void) 

The code is written in codevision, it defines interrupts handlers like that.

Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Levenkay wrote:

And why bother with an interrupt service routine for the zero-crossing signal anyway, given that your main() routine constantly polls that pin?

The rest of the code looks like it's built to generate narrow (however long it takes your compiler how to figure out what state the zero-crossing signal is in) LOW pulses on Bit 0 of PortB, at a 2KHz rate. That's only if the zero-crossing signal is HIGH, of course; otherwise, the program generates short LOW pulses on Bit0 of PortB at a 2KHz rate (exactly the same behavior as when the zero-crossing signal was High, in other words).

The interrupt seems to be set up so as to suspend (gobbling up all the CPU time) these otherwise-constant 2KHz pulse streams for one millisecond after any change in the zero-crossing status.

I cannot transfer what you say into code, can you pls give me the code for triac firing angle? Maybe from code we can discuss part by part..