Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Where am I wrong? Light dimmer

Status
Not open for further replies.

sahu

Member
A light dimmer works by essentially chopping parts out of the AC voltage.

Code:
#define tx GPIO.GP5

unsigned TMR1 absolute 0x0E;

char current_dim = 0;
char done_flag = 0;
char Command_code, Device_code;
//preload timer1 value 100%, 90%, 80%, 70% 60%, 50%, 40%, 30% 20% and 10%
unsigned preload_time[10] = {65535,63823,63082,62481,61925,61370,60814,\
60259,59656,58916};

//******************************************************************************
//*** interrupt-on-change when zero-crossing occur, preload timer1 value
//*** turn on timer1 to perform delay before gate trigger
//******************************************************************************
if(INTCON.GPIF)
{
tx = 1;
TMR1 = preload_time[current_dim];//preload_time into Timer1
T1CON.TMR1ON = 1; //start timer1
INTCON.GPIF = 0;
}
//******************************************************************************
//*** perform gate trigger, turn off itself
//******************************************************************************
if(PIR1.TMR1IF)
{
T1CON.TMR1ON = 0; //stop timer1
tx = 0; //turn on triac
delay_us(150);
tx = 1; //turn off triac
PIR1.TMR1IF = 0; //clear interrupt flag
}
}
if(done_flag == 0)
{
if(got_data)
{
Command_code = input_data & 0x7F;
Device_code = input_data >> 7;
if(Device_code == 1)
{
switch (Command_code)
{
case 0x12: if(current_dim > 0) current_dim --;
break;
case 0x13: if(current_dim < 9) current_dim ++;
break;
}
}
done_flag = 1;
}
}

original code is here ..
broken link removed
 
Last edited by a moderator:
I dont like that circuit without an opto for the zero cross detect.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top