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.

Incandencent Lamp dimmer using PIC16F877A

Status
Not open for further replies.

Modak

Newbie level 1
Joined
Aug 2, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Microcontroller
Activity points
1,304
I am trying to control Intensity of AC lamp. For this my steps are as follows
1. Initialise ports, timers.
2. wait for zero cross, if detect a zero cross point set a flag.
3. When zero cross flag set,enable timer0 & start timerto overflow after 8msec.
4. wait untill overflow.
5. When overflow, turn ON triac for some duration (may be 600usec) untill it latches.
6. Poll the keys.
7. If key pressed, change timer0 value & repeate a process from step 3.
My program of zero cross & timer0 working OK independently, but when combine both ,
i am not getting expected o/p waveform, but getting extra pulse at each zero cross.
I am trying this from last two weeks, but i am not getting o/p... Plz..plz. help me


/////////////////////////////////////////////////////////////////////////


#include <16F877A.h>

#device ICD=TRUE
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)


//////////////////////////////////////////////////////////////////////////////////////

/**** I/O Ports ****/
/*** Inputs ***/
#define LED PIN_A1
#define ZCD PIN_B4

/*** Outputs ***/
unsigned char ZCD_flag, Dimming_time;



//----------------------------------------------------------------------------
void main (void);
void main()
{
unsigned char dc ;
setup_adc_ports(NO_ANALOGS); /*defines RA0,RA1,RA2,RA3 & RA5 as Digital I/O*/
SET_TRIS_A(0x00); /* Port A with RA0-RA4 as outputs */
SET_TRIS_B(0x11);
output_low(LED);
ZCD_flag=0x00;
Dimming_time=0x00;
ENABLE_INTERRUPTS(GLOBAL); // enable All interrupts

while(1)
{
ENABLE_INTERRUPTS(INT_RB); // enable External interrupt
DISABLE_INTERRUPTS(INT_TIMER0);
if(ZCD_flag==1)
{
ZCD_flag =0;
DISABLE_INTERRUPTS(INT_RB);
ENABLE_INTERRUPTS(INT_TIMER0); // enable Timer0 interrupt
SET_TIMER0(242); // set timer0 reg.to 0
SETUP_TIMER_0(T0_INTERNAL);
SETUP_TIMER_0(T0_DIV_32);
}
}


}




/**** Zero Cross Interrupt ****/
#INT_RB
void ext_int_zerocross()
{
CLEAR_INTERRUPT(INT_RB); /* Clear External Interrupt Flag */
ZCD_flag=1; /* Indicate 10ms Interrupt Occured */
}

#INT_TIMER0
void InterruptHandler_Timer0 ()
{
CLEAR_INTERRUPT(INT_TIMER0); /* Clear the Timer0 Flag */
// DISABLE_INTERRUPTS(INT_TIMER0);
output_high(LED); // invert the state of output
delay_us(500);
output_low(LED); // invert the state of output
}

/*************** END OF PhaseControl ****************************/
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top