Hey guys M controlling light intensity using zero detector through microcontroller 2051 using moc3041 and traic 136
what m doing is as there will zero detecting pulse after every 10ms. so m doing is m jst making moc off for 8ms and on for 2ms by this i m achieving 20% brightness BUT
THE PROBLEM IS BULB IS ACHIEVING 20%BRIGHTNESS BUT ITS KEEP ON FLICKER HERE'S THE SIMPLE CODE FOR TESTING M POSTING KINDLY HELP
Your ISR has a total delay time of 20 ms. How can you expect that it's triggered each period?
At the very least, you'll want to comment the last delay(2), to get a chance that the ISR is triggered periodically. If the interrupt is triggered every 10 ms, as you mention, the ISR can be finished after the first moc=0, isn't it?
Your ISR has a total delay time of 20 ms. How can you expect that it's triggered each period?
At the very least, you'll want to comment the last delay(2), to get a chance that the ISR is triggered periodically. If the interrupt is triggered every 10 ms, as you mention, the ISR can be finished after the first moc=0, isn't it?
There are actually two problems remaining:
- the ISR code must be finished before the next zero crossing. So delay(2) is definitely wrong, as previously mentioned.
- the triac control must be switched off before the zero crossing. The triac only needs a short trigger pulse.
Try something like this:
Code:
void isr(void) interrupt 0
{
delay(8);
moc=0; // bulb on
delay_100us():
moc=1; // triac is on now, switch off control
}
There are actually two problems remaining:
- the ISR code must be finished before the next zero crossing. So delay(2) is definitely wrong, as previously mentioned.
- the triac control must be switched off before the zero crossing. The triac only needs a short trigger pulse.
Try something like this:
Code:
void isr(void) interrupt 0
{
delay(8);
moc=0; // bulb on
delay_100us():
moc=1; // triac is on now, switch off control
}
I don't believe, that there will be much doubts what delay_100us() means. It's just a placeholder for a short delay that's long enough to trigger the opto triac, below 20 µs according to the datasheet. Most embedded compilers have microsecond delay functions, if not, it's easy to create.
#include <REG2051.H>
int i,j,a;
sbit up=P3^4;
sbit down=P3^5;
sbit moc=P3^7;
void delay();
/*void delay(int x)
{
for(i=0;i<100;i++)
for(j=0;j<x;j++)
;
} */
void delay1(int d)
{
int k;
TL0=0x17;
TH0=0xFC;
TR0=1;
for(k=0;k<d;k++) //will produce dx1ms of delay
{
while(TF0==0)
TF0=0;
TL0=0x17;
TH0=0xfc;
}
TR0=0;
}
void isr(void) interrupt 0
{
delay1(8);
moc=0; // bulb on
delay1(2);
moc=1; // triac is on now, switch off control
}
void main()
{
TMOD=0x01;
//P3=0xff;
//IT0 = 1; // Configure interrupt 0 for falling edge on /INT0 (P3.2)
EX0 = 1; // Enable EX0 Interrupt
EA = 1; // Enable Global Interrupt Flag
while(1)
{
P1=0xA5;
}
}
- - - Updated - - -
HTML:
void delay1(int d)
{
int k;
TL0=0x17;
TH0=0xFC;
TR0=1;
for(k=0;k<d;k++) //will produce dx1ms of delay
{
while(TF0==0)
TF0=0;
TL0=0x17;
TH0=0xfc;
}
TR0=0;
}
as per my calculation the value "fc17" should produce 1milisecond of delay but it is not generating while i checked on keil debugger its producing around 66ms when i call delay1(8) where as it should produce 8ms delay . now tell me where i am wrong.
Please read my previous post. you CANNOT use the MOC3041 in this application becasue it has it's own built in trigger supression circuit that will not allow you to 'fire' it between zero crossing points. The best you can achieve is flickering and that's exactly what you saw. No amount of adjusting delays will help until you change to a different "non-zero crossing" type such as the MOC3021 suggested by FvM.