Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

TRIAC Lamp dimmer Code Help

Status
Not open for further replies.

Mohamad Syazwan

Newbie level 3
Newbie level 3
Joined
May 16, 2014
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
31
This is my schematic diagram that i'm using
Untitled.png
i cannot dim the lamp correctly
the lamp is flickering
can anyone check my code
thanks!
p/s: i'm using pic16f873a
the RB0 is for external interrupt for zero crossing
and RC0 is for dimmer signal

Code:
unsigned char FlagReg;
int x;
int i;
int maal;
int dimming=128;
sbit ZC at FlagReg.B0;

void interrupt(){
if (INTCON.INTF){ //INTF flag raised, so external interrupt occured
ZC = 1;
INTCON.INTF = 0;
}
}

void delay(int maal){
for (x=1; x< maal; x++) {
delay_us(75);
}
}

void main() {
PORTB = 0;
TRISB = 0x01; //RB0 input for interrupt
PORTA = 0;
ADCON1 = 7; //Disable ADC
TRISA = 0xFF; //Make all PORTA inputs
PORTC = 0;
TRISC = 0; //PORTC all output
OPTION_REG.INTEDG = 0; //interrupt on falling edge
INTCON.INTF = 0; //clear interrupt flag
INTCON.INTE = 1; //enable external interrupt
INTCON.GIE = 1; //enable global interrupt

while (1)
{
for (i=5; i<= 128; i++){
  if(ZC){
dimming=i;
vdelay_ms(dimming);
PORTC.B0=1;
delay_us(250);
PORTC.B0=0;
ZC=0;
delay_ms(10);
}
}
} }
 

Not related to your code, but shouldnt there be a resistor in series with your zero-crossing LED? Maybe its already fried?

Are you still getting a good zero crossing signal at the output?
 

Not related to your code, but shouldnt there be a resistor in series with your zero-crossing LED? Maybe its already fried?

Are you still getting a good zero crossing signal at the output?

When i test it using arduino. It's working perfectly fine
but when using mikroC i cannot get the code right
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top