humpy
Newbie level 2
how to create remote control fan regulator
Hi,IanP
I tried to find out the zero crossing point.I used a 0-18v transformer.I rectified it with bridge rectifier and i gave this rectified voltage to the base of BC547.Base resistor=10k,collector resister=4.7k.The collector pin is connected to the RB0 pin of pic16f876a.I treid to read the time interval between two zero crossing(it must be 10ms right?)using timer1 with out using any prescaler.But i am getting the timer value as 19937.Ie that much microsecond instead of 10 ms.So where is the problem?Is threr any thing wrong with the programe or design?.
Here is the program in HI-Tech for finding the time period.
I used 4Mhz crystal.
#include <pic.h>
unsigned char first,second;
unsigned short x;
__CONFIG(WDTDIS & XT & UNPROTECT & PWRTDIS & BORDIS & LVPDIS );
/*************************************************************/
static void interrupt isr()
{
if(INTF)
{
GIE=0;
if(first)
{
TMR1ON=1; //First zero crossing timer value=0
first=0;
}
else if(second)
{
TMR1ON=0; //second zero crossing,Read timer1 in to x
x=TMR1H;
x=x<<8;
x=(x| TMR1L);
first=1;;
TMR1H=0;
TMR1L=0;
x=0;
}
}
INTF=0;
GIE=1;
}
void main(void)
{
T1CON=0b00001000;
TMR1H=0;
TMR1L=0;
first=1;
second=1;
TRISB=0b00000001;
INTF=0;
INTEDG=0;
INTE=1;
GIE=1;
while(1)
{
PORTB=0; //Nothing to in while loop
}
}
IanP said:For test purposes you will need a small transformer (or a resistor, bridge and an optocoupler, example 4N25) to create isolated zero-crossing reference ..
If you go for a small transformer (5-6Vac) connect a bridge to recify voltage and this will give you 100Hz. From this signal you will need to creat short pulses as clos to 0V as possible. This can be done by connecting a npn transistor to this signal (base resistor ≈10kΩ) and getting almost square wave at its collector. This signal can be fed to PIC microcontroller as reference for phase angle calculations ..
Once you have this reference you can continue testing this circuit using isolated PIC circuit (assuming that you use MOC to provide isolation from the triac's gate) ..
Regards,
IanP
Hi,IanP
I tried to find out the zero crossing point.I used a 0-18v transformer.I rectified it with bridge rectifier and i gave this rectified voltage to the base of BC547.Base resistor=10k,collector resister=4.7k.The collector pin is connected to the RB0 pin of pic16f876a.I treid to read the time interval between two zero crossing(it must be 10ms right?)using timer1 with out using any prescaler.But i am getting the timer value as 19937.Ie that much microsecond instead of 10 ms.So where is the problem?Is threr any thing wrong with the programe or design?.
Here is the program in HI-Tech for finding the time period.
I used 4Mhz crystal.
#include <pic.h>
unsigned char first,second;
unsigned short x;
__CONFIG(WDTDIS & XT & UNPROTECT & PWRTDIS & BORDIS & LVPDIS );
/*************************************************************/
static void interrupt isr()
{
if(INTF)
{
GIE=0;
if(first)
{
TMR1ON=1; //First zero crossing timer value=0
first=0;
}
else if(second)
{
TMR1ON=0; //second zero crossing,Read timer1 in to x
x=TMR1H;
x=x<<8;
x=(x| TMR1L);
first=1;;
TMR1H=0;
TMR1L=0;
x=0;
}
}
INTF=0;
GIE=1;
}
void main(void)
{
T1CON=0b00001000;
TMR1H=0;
TMR1L=0;
first=1;
second=1;
TRISB=0b00000001;
INTF=0;
INTEDG=0;
INTE=1;
GIE=1;
while(1)
{
PORTB=0; //Nothing to in while loop
}
}