raghurocks
Member level 1
- Joined
- Jul 3, 2012
- Messages
- 33
- Helped
- 2
- Reputation
- 4
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- India,Gujarat
- Activity points
- 1,568
#include<reg51.h>
// LED Pin
sbit LED = P2^0; // Pin P2.0 is named as LED
//Function declarations
void cct_init(void);
void InitINT0(void);
void delay(int );
// Main function
void main(void)
{
cct_init(); // Make all ports zero
InitINT0(); // Intialize INT0 interrupts
while(1)
{}
}
// Init CCT function
void cct_init(void)
{
P0 = 0x00; // Make all pins zero
P1 = 0x00; // Make all pins zero
P2 = 0x00; // Make all pins zero
P3 = 0x00; // Make P3.2 (INT0) pin high only
}
// External INT0 pin interrupt init function
void InitINT0(void)
{
IT0 = 1; //Edge triggered interrupt mode (Neg Edge)
EX0 = 1; //Enable external interrupt INT0
EA = 1; //Enable global interrupts
}
// INT0 ISR
void external0_isr(void) interrupt 0 //zero detection interrupt routine
{
//LED = ~LED; // Toggle LED pin
if(P1==0x00)
{
LED=0;
}
else if(P1==0x01)
{
LED=1;
delay(20);//trigger immediately after the zero detection
LED=0;
}
else if(P1==0x02)
{
LED=0; //delay angle before which the triac triggers
delay(50);
LED=1;
delay(20);//this delay is for the trigger pulse for the triac ~100us
LED=0;
}
else if(P1==0x03)
{
LED=0; //delay angle before which the triac triggers
delay(100);
LED=1;
delay(20);//this delay is for the trigger pulse for the triac ~100us
LED=0;
}
else if(P1==0x04)
{
LED=0; //delay angle before which the triac triggers
delay(150);
LED=1;
delay(20);//this delay is for the trigger pulse for the triac ~100us
LED=0;
}
else if(P1==0x05)
{
LED=0; //delay angle before which the triac triggers
delay(200);
LED=1;
delay(20);//this delay is for the trigger pulse for the triac ~100us
LED=0;
}
else if(P1==0x06)
{
LED=0; //delay angle before which the triac triggers
delay(250);
LED=1;
delay(20);//this delay is for the trigger pulse for the triac ~100us
LED=0;
}
else if(P1==0x07)
{
LED=0; //delay angle before which the triac triggers
delay(300);
LED=1;
delay(20);//this delay is for the trigger pulse for the triac ~100us
LED=0;
}
else if(P1==0x08)
{
LED=0; //delay angle before which the triac triggers
delay(350);
LED=1;
delay(20);//this delay is for the trigger pulse for the triac ~100us
LED=0;
}
else if(P1==0x09)
{
LED=0; //delay angle before which the triac triggers
delay(400);
LED=1;
delay(20);//this delay is for the trigger pulse for the triac ~100us
LED=0;
}
else if(P1==0x0A)
{
LED=0; //delay angle before which the triac triggers
delay(450);
LED=1;
delay(20);//this delay is for the trigger pulse for the triac ~100us
LED=0;
}
else if(P1==0x0B)
{
LED=0; //delay angle before which the triac triggers
delay(500);
LED=1;
delay(20);//this delay is for the trigger pulse for the triac ~100us
LED=0;
}
else if(P1==0x0C)
{
LED=0; //delay angle before which the triac triggers
delay(510);
LED=1;
delay(20);//this delay is for the trigger pulse for the triac ~100us
LED=0;
}
else if(P1==0x0D)
{
LED=0; //delay angle before which the triac triggers
delay(520);
LED=1;
delay(20);//this delay is for the trigger pulse for the triac ~100us
LED=0;
}
else if(P1==0x0E)
{
LED=0; //delay angle before which the triac triggers
delay(530);
LED=1;
delay(20);//this delay is for the trigger pulse for the triac ~100us
LED=0;
}
else if(P1==0x0F)
{
LED=0; //delay angle before which the triac triggers
delay(540);//the maximum for 50hz signal
LED=1;
delay(20);//this delay is for the trigger pulse for the triac ~100us
LED=0;
}
}
void delay(int n)
{
int i;
for(i=0;i<=n;i++);
}
The tricky part included in this is I am getting the output exactly as I desire in the Proteus emulator but I don't know why I am not getting the desired output in the hardware
I don't know where is the wrong in the hardware . I think the triac trigger circuit is fine as it is typical application circuit I think my microcontroller is not triggering .Exactly at which place you're finding problem with your hardware ?
upto which section circuit is working?
and what output at where makes the problem
& what output at that place you're getting in proteus ?
in first just check your i/p circuit (upto the interrupt pin of controller),
in second by feeding an interrupt check your o/p to know whether the program is working or not &
in third try to debug your o/p circuit.
#include <pic.h> //triac light dimmer
#define _XTAL_FREQ 20000000
#define TRIAC1 RB3
#define UP RB7
#define DWN RB6
#define MAX_TIME 3500
#define MIN_TIME 1
int k=0,dly=0;
void interrupt isr()
{
/////////////////////////////////////
if(INTF)
{
INTF=0;
while(!RB0);
dly=k;
while(dly--);
TRIAC1=1;
#asm
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
nop;nop;nop;nop;nop;nop;
#endasm
TRIAC1=0;
}
}
/////////////// MAIN //////////////////////
void main()
{
TRISD=0x0; TRISB=0xF1;
k=300;
INTE=1; INTEDG=1; PEIE=1;GIE=1;
while(1)
{
if(!UP)
{
__delay_ms(100);
if(!UP)
{
if(k>=MAX_TIME) k=MAX_TIME; k++;
dly=k;
}
}
else if(!DWN)
{
__delay_ms(100);
if(!DWN)
{
if(k<=MIN_TIME) k=MIN_TIME; k--;
dly=k;
}
}
}
}
/////////////////////////////////////////////////
Hi Jigar,
So only way I may go wrong is that either I may go wrong in the triac circuit or I may be wrong in the coding to my uC in case of triac triggering, which I am unable to know
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?