Discussion in "Project Doubts" started by    bagusdj    Jan 23, 2013.
Fri Feb 08 2013, 08:02 pm
#11
is it the right way to create delay 1ms using timer, then triac on, and delay another 1ms and then triac off? i use inductive load. but then voltage measured seems too far than it should be. it's around 17X V rather than 20X V. is it because my load is inductive? i have RC snubber in my triac circuitry.
#include<reg52.h>

 sbit triac=P3^0;
 void initint0(void);
 sbit intr0=P3^2;



void initINT0(void)
 {
 IT0=1;
 EX0=1;
 EA=1;
 }



void external0_isr(void) interrupt 0
{
TL1=0x66;    // delay 1mS
TH1=0xFC;    //
TR1=1;     //start Timer1
  while(!TF1){;}   //wait for timer1 overflow
TR1=0;     //stop timer1
triac=0;  //triac on
TF1=0;     //clear timer1 flag

TL1=0x66;    // delay 1mS
TH1=0xFC;    //
TR1=1;     //start Timer1
  while(!TF1){;}   //wait for timer1 overflow
TR1=0;     //stop timer1
triac=1;  //triac off
TF1=0;     //clear timer1 flag
								
}
 
 void main(void)
 {
  intr0=1;
  triac=1;
  initINT0();
  TMOD=0x10;
 
}


[ Edited Fri Feb 08 2013, 08:31 pm ]
Sun Feb 10 2013, 04:37 am
#12
usually you do not need to turn off TRIAC as it automatically turns off when AC signal crosses zero level. why are you adding this delay for?
Sun Feb 10 2013, 07:03 am
#13


usually you do not need to turn off TRIAC as it automatically turns off when AC signal crosses zero level. why are you adding this delay for?

Ajay Bhargav



it is reference from a friend who used avr for lamp dimmer. i tried the code like this but Vrms always 220-215.

#include<reg52.h>

 sbit triac=P3^0;
 void initint0(void);
 sbit intr0=P3^2;
unsigned int i,a;
void delay_triac();

void delay_triac()  // Function to provide time delay in 1 msec.
{
TMOD = 0x10;				// Mode1 of Timer1
	TH1= 0xFC;  				// FC66 evaluated hex value for 1millisecond delay
	TL1 = 0x66;
	TR1 = 1;   				// Start Timer
	while(TF1 == 0); 			// Using polling method
	TR1 = 0; 				// Stop Timer
	TF1 = 0;
}

void initINT0(void)
 {
 IT0=1;
 EX0=1;
 EA=1;
 }



void external0_isr(void) interrupt 0

{

for(i=0;i<5;i++)
delay_triac();
triac=0;



}
 
 void main(void)
 {
  intr0=1;
  triac=1;
  initINT0();
  }
Sun Feb 10 2013, 08:04 am
#14
well for dimmer the logic is simple....

1. wait for zero cross
2. after zerocross, wait for time some time.. and then fire triac
3. loop to 1

e.g. if your AC frequency is 50Hz then you can calcualte time of 1/4 cycle time and after zero cross wait for 1/4 time and fire triac. you should see half power getting transmitted to device.
Sun Feb 10 2013, 07:07 pm
#15


well for dimmer the logic is simple....

1. wait for zero cross
2. after zerocross, wait for time some time.. and then fire triac
3. loop to 1

e.g. if your AC frequency is 50Hz then you can calcualte time of 1/4 cycle time and after zero cross wait for 1/4 time and fire triac. you should see half power getting transmitted to device.

Ajay Bhargav



i know about the ralation between the delay and the angle. from that i know the Vrms. i think in my code i just do like that; when zero cross edge is falling (this is my interrupt trigger), i delay at certain time, then fired triac. i just dont get what it should be.

i interface moc3021 and triac as on its datasheet. also for ZCD (i use ic 4n26). i use inductive load and interfaces it as on its data sheet.i just dont get it, how the code should be?
Mon Feb 11 2013, 03:00 pm
#16
your code looks ok.. but your main function is missing while(1) loop...
Tue Feb 12 2013, 12:14 pm
#17


your code looks ok.. but your main function is missing while(1) loop...

Ajay Bhargav



#include<reg52.h>

 sbit triac=P3^0;
 void initint0(void);
 sbit intr0=P3^2;
unsigned int i,a;
void delay_triac();


void delay_triac()  // Function to provide time delay in 10 usec.
{
TMOD = 0x10;				// Mode1 of Timer1
	TH1= 0xFF;  				// FFF6 evaluated hex value for 10 microiseconds delay
	TL1 = 0xF6;
	TR1 = 1;   				// Start Timer
	while(TF1 == 0); 			// Using polling method
	TR1 = 0; 				// Stop Timer
	TF1 = 0;
}

void initint0(void)
 {
 IT0=1;
 EX0=1;
 EA=1;
 }



void external0_isr(void) interrupt 0

{

for(i=0;i<500;i++) // delay 4ms.
delay_triac();

triac=~triac;

}
 
 void main(void)
 {
  intr0=1;
  triac=1;
  initint0();
  while(1)
  {}
  }


i tried this code, but the output is around 140-130-120. i expect to get less than 110 since zero cross take around 0.5mSec roughly. i would like to ask, the initial triac pin in mcu is high. in my isr i set ~triac. so when in interrupt triac=0; but will the triac=0 all the time? so next isr will be ~triac (triac=1 again)? or after ~triac, triac will be set into initial condition?


[ Edited Tue Feb 12 2013, 12:19 pm ]
Wed Feb 13 2013, 01:02 am
#18
try this

void external0_isr(void) interrupt 0

{
triac=1;
for(i=0;i<500;i++) // delay 4ms.
delay_triac();

triac=0;

}
Wed Feb 13 2013, 11:01 am
#19


try this

void external0_isr(void) interrupt 0

{
triac=1;
for(i=0;i<500;i++) // delay 4ms.
delay_triac();

triac=0;

}

majoka



hi majoka, thanks for replying. i think if i do it that way, it will change triac value from initially 1, into 0 forever. since triac=1; is stated in main, but not looping. placing triac=1; in the routine seems doesnt work.

if initially i states triac=1; what would be happened if in isr i states triac=~triac? will triac return to initial value? of forever 0?
Wed Feb 13 2013, 11:49 pm
#20
@ bagusdj
the logic behind the firing angle is simple
make pin high in main outside the while(1)
it is supposed that opto coupler conduct on low logic
so at high logic no triggering pulse is provided to triace
when zero cross generate interrupt make sure pin is high
it means triace is off although if you not do this trica automatically off
when zero cross comes then it need again a triggering pulse
now in interrupt simply load values of timer and exit from interrupt
when timer generate interrupt give a triggering pulse to make pin low

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Dulcehet
Fri May 10 2024, 04:22 pm
ElvasKl
Fri May 10 2024, 04:54 am
RonaldNak
Thu May 09 2024, 07:45 pm
Jamescon
Thu May 09 2024, 12:52 pm
RobertSkats
Thu May 09 2024, 10:23 am
hvCar
Thu May 09 2024, 05:53 am
DJGlido
Wed May 08 2024, 09:28 pm
migCar
Wed May 08 2024, 04:48 pm