Re:Light Dimmer circuit ..Lamp flickers at higher firing angles(for period 4ms to 10ms)

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

Dear freaks

As i am working with light dimmer circuit intrfaced to attiny 45.Using an external interrupt for zcd and delay through one of the GPIO.As per the observation light is flickering @4ms to 10 ms.For 1ms to 3ms of time period light is stable.I am seeing the dimmness between(1ms -10ms)but after 4ms of delay light is flickering more.Can any one guide me to rectify the problem.

#define F_CPU	8000000UL
#include <avr/io.h>
#include <avr/interrupt.h>


/*****************Function Declaration**********************/
void InitPort(void);
void Extint0(void);
void InitTimer0(void);
void StartTimer0(void);
void Delay(unsigned int );
void InitTimer1(void);
void StartTimer1(void);


void InitPort(void)
	{
	
		//set PB1 &PB2 as output
	
		DDRB|=(1<<PB3);  //Delay
		DDRB|=(0<<PB2);  //EXt int
		PORTB|=(1<<PB2);
		PORTB&=~(1<<PB3);
		SREG |= 0x80;
		
	
	}
//Initialize Timer0 for 4ms
void InitTimer0(void)
	{
	
		
		//OCR0A = 125;     	//for4ms
		TIMSK|=(1<<OCIE0A);	// enable CTC interrupt
			

	}
void StartTimer0(void)
	{
	
		TCCR0A=0x82;			// Configure timer0 for CTC mode
		TCCR0B|=0x80;			// Start timer at Fcpu /256
	
	}
void InitTimer1(void)
	{
		OCR1A=250;				// 250us , with a prescalar of8
		TIMSK|=(1<<OCIE1A);
	}
void StartTimer1(void)
	{
		TCCR1|=0x80;	
	}
		
void Extint0(void)
{
	MCUCR|=(0<<ISC00);	    //  logical change on Falling edge INT0 generates an interrupt request.
	MCUCR|=(1<<ISC01);    //  logical change on Falling edge INT0 generates an interrupt request.
	GIMSK|=_BV(INT0);    // Enable INT0*/
	GIFR|=(0<<INTF0);

}
	
void Delay(unsigned int n)
	{
		unsigned int i, j;
		for(i=0;i<n;i++)
		for(j=0;j<1000;j++);
	}


ISR(TIMER0_COMPA_vect)
	{
		
		

			
		
			TCCR0B|=(0<<CS02);  //Timer0 off
			OCR0A=0;
			TCNT0=0;  //Timer0 count to 0
			PORTB|=(1<<PB3);
			
			TCCR1|=(1<<CS12); //Timer 1 on
	}  //end of ISR
	
ISR(TIMER1_COMPA_vect)
{
	
		PORTB&=~(1<<PB3); 
		OCR1A=0;	
		TCNT1=0;  //Timer1 count to 0
		TCCR1|=(0<<CS12); //Timer1 off
		
}  //end of ISR		
int main(void)
	{
		InitPort();
		Extint0();
		InitTimer0();
		StartTimer0();
		InitTimer1();
		StartTimer1();
		
		while(1)
		{
			Delay(1);
		}
	}

ISR(INT0_vect)
{
	
	TCCR0B=0x00;

	TCCR0B|=(1<<CS02);  //Enable timer0 on
	
}


 

Attachment(s): 

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

Welcome to AVRFreaks.

 

This is (for the moment anyways) a site dedicated to Atmel's AVR products, so your schematic showing a PIC device will cause some confusion. Would you care to tell us what you are really using and provide its schematic please?

 

Cheers,

 

Ross

 

Ross McKenzie ValuSoft Melbourne Australia

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

Dear Valusoft,

 

 

sorry for the mistaken i have used ATTINY 45 (Not PIC).rest of the components are same.

Last Edited: Mon. May 30, 2016 - 12:57 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

60 Hz AC has a zero crossing every 8.3 ms. Are you running the avr at 1 Mz or 8 MHz? How about a couple of 'brighter dimmer' buttons?

 

Imagecraft compiler user

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

Hi-

like said bob, control the pulse after zero crossing but see if your triac has enough gate current, if flashing  seam at triac not trigg all the time.

if mosfet, must be wrong timing.

 

 

Thierry Pottier

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

Maybe the load isn't enough to 'hold' the triac? Try a 40 or 60W incandescent light bulb. Don't try a led or fluoro.

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

Dear Bob,

 

i am running AVR at  8MHz frequency.AC 230v,50Hz.

 

 

Regards

samatha

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

dear freaks

 

Thank you for the replies.I am using 60W Bulb as load

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

How is your code supposed to work? Why the two timers? You should only need 1 timer.

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

Dear Kartman,

 

i am using timer0 for delay for (1ms-10ms),and timer1 for to 250us (microseconds)enough to triac has turned on.Kindly guide me how to use 1timer.

 

 

 

Regards

Samatha

 

 

Last Edited: Tue. May 31, 2016 - 10:56 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You do not have enough gate current

Thierry Pottier

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

Dear TPE,

 

can you please guide me to rectify the problem.

 

 

cheers

samsan

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

Google has all your answers. Try avr dimmer

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

the current gate depand of cadran you are working and triac spec.

show schema with value . 

difficult to explain without schema. 

if your pulse is 250us it is long enough if current is high enough,

Thierry Pottier

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

dear TPE

 

I am using Optocoupler with MOC3021 AND photocoupler  4N35 and TRIAC BT-139 600E.

 

regards

san

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

well do not see me a lot , what is the gate drive? do you have enougth current to the MOC. , what sort resistor for the gate? 

I guess at the 4N35 is for zero crossing. 

Thierry Pottier

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

by the way, trist to make dimmer with triac today.... 

My Last project with triac must be 20 years away ( for ligth).

Thierry

Thierry Pottier

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

Dear TPE,

 

I am using 670 ohm(1/4watt).

 

 

regards

san

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

ok why do you not share and must ask all the time,.

670R ? where gate? ( if gate it is high enough with 330R - 470R but not out the range. BT139-600E need at least 25mA if T2- G+; max for triac mean 100% trigging but the typical will meat your test lab.)

I think without see your schema, the problem can be on the diode side for MOC.

try to increase the gate pulse 500us and 750us and see if it is some changing,

 

Thierry Pottier

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

Dear TPE,

 

I have increaed gate pulse 500us and  tried with 750us (Timer1

#define F_CPU	8000000UL
#include <avr/io.h>
#include <avr/interrupt.h>

/*****************Function Declaration**********************/
void InitPort(void);
void Extint0(void);
void InitTimer0(void);
void StartTimer0(void);
void Delay(unsigned int );
void InitTimer1(void);
void StartTimer1(void);

void InitPort(void)
	{

		//set PB1 &PB2 as output

		DDRB|=(1<<PB3);  //Delay
		DDRB|=(0<<PB2);  //EXt int
		PORTB|=(1<<PB2);
		PORTB&=~(1<<PB3);
		SREG |= 0x80;

	}
//Initialize Timer0 for 8ms
void InitTimer0(void)
	{

		OCR0A = 250;     	//for 8ms
		TIMSK|=(1<<OCIE0A);	// enable CTC interrupt

	}
void StartTimer0(void)
	{

		TCCR0A=0x82;			// Configure timer0 for CTC mode
		TCCR0B|=0x80;			// Start timer at Fcpu /256

	}
void InitTimer1(void)
	{
		OCR1A=250;				// 500us , with a prescalar of 16
		TIMSK|=(1<<OCIE1A);
	}
void StartTimer1(void)
	{
		TCCR1|=0x80;
	}

void Extint0(void)
{
	MCUCR|=(0<<ISC00);	    //  logical change on Falling edge INT0 generates an interrupt request.
	MCUCR|=(1<<ISC01);    //  logical change on Falling edge INT0 generates an interrupt request.
	GIMSK|=_BV(INT0);    // Enable INT0*/
	GIFR|=(0<<INTF0);

}

void Delay(unsigned int n)
	{
		unsigned int i, j;
		for(i=0;i<n;i++)
		for(j=0;j<1000;j++);
	}

ISR(TIMER0_COMPA_vect)
	{

			TCCR0B|=(0<<CS02);  //Timer0 off
			OCR0A=0;
			TCNT0=0;  //Timer0 count to 0
			PORTB|=(1<<PB3);

		    TCCR1|=((1<<CS12)|(1<<CS10)); //Timer1 on
	}  //end of ISR

ISR(TIMER1_COMPA_vect)
{

		PORTB&=~(1<<PB3);
		OCR1A=0;
		TCNT1=0;  //Timer1 count to 0
		TCCR1|=(0<<CS12); //Timer1 off

}  //end of ISR
int main(void)
	{
		InitPort();
		Extint0();
		InitTimer0();
		StartTimer0();
		InitTimer1();
		StartTimer1();

		while(1)
		{
			Delay(1);
		}
	}

ISR(INT0_vect)
{

	TCCR0B=0x00;

	TCCR0B|=(1<<CS02);  //Enable timer0 on

}

) .which is giving more brightness for 8ms delay(Timer0).

 

 

Regards

San

Last Edited: Thu. Jun 2, 2016 - 08:20 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok. well but it was the problem. it is stable?

Thierry Pottier

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

Dear TPE,

 

Thank you so much,Yes its stable now.

 

Regards

san

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

Dear TPE

 

Kindly guide me  how to reduce the brightness @8ms without flickering

 

regards

san

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

if 50hz and pulse 500us or max 750us than make brigtness to 9,250ms ( if trigger 750us)

Thierry Pottier

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

Dear TPE,

 

if 50hz and pulse 500us or max 750us than make brigtness to 9,250ms ( if trigger 750us) ..Can you please elaborate..

 

 

Regards

San

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

one halv periode is 10ms ( 50hz)

minimum brigtness meet if you have less conduction to the triac. that means 10ms - pulse trigger = 9,25ms if pulse trigger is 750us.

 

 

Thierry Pottier

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

Dear TPE

 

still Bulb is flickering (not continously)but flickering is happening

 

Regards

San 

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

You need to turn the opto off around 500us before zero crossing to allow the triac to turn off, otherwise it stays on next cycle.

Last Edited: Fri. Jun 3, 2016 - 09:24 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Katman.. well if zero crossing is right , you do not need 500us. 

the current in the triac must be higher than hold current to switch on that give you some us after zero crossing . this it is the main EMC problem for heater regulator they wait to long to start the triac after 0V sinus.

but agree with you for a dimmer to have some safe zone and max 9,5ms with end of trigger pulse. 

 

San.

you do  not share all your information.

flickering --> when. just try to increase the max timer and like Katman said, get a safe periode. 

I am sure at your schema has some wrong value , pulse drive for the moc or the zero crossing. 

I guess you have not scope to control your pulse? 

periode of zero crossing, periode of pulse 

Thierry Pottier