View previous topic :: View next topic |
Author |
Message |
pilar
Joined: 30 Jan 2008 Posts: 197
|
Zero crossing detector |
Posted: Fri Jan 08, 2010 9:26 pm |
|
|
Hi, I am implementing a program to control an incandescent lamp to 220VAC, for that I am using a TRIAC, which is triggered by an output RB7 of a pic16f88, To do this I need a circuit zero crossing detector, for that I am using a LM741 which to pin RB0 interrupt each semisiclo, which takes the reference voltage of a diode rectifier bridge type, in this configuration everything works OK, this my code is the zero-crossing detector:
Code: | #INT_EXT
void CrucePor0()
{
PasosDimmer=0;
if (j==0){
j=1;
ext_int_edge(H_TO_L);
}
else {
j=0;
ext_int_edge(L_TO_H);
}
} |
Now I want to remove the LM741 and want to connect directly to pin RB0 but I lose one half cycle for each period, as could modify my code to detect the zero crossing without using any other component? |
|
|
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
|
Ttelmah Guest
|
|
Posted: Sat Jan 09, 2010 3:31 am |
|
|
Add AN928 to the list given above.
Remember to consider the failure modes of the resistors. It is (for example), safer to use two series 2.5MR resistors, _both of which_ are mains rated, than a single 5MR resistor for the dropper.
Best Wishes |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Jan 09, 2010 8:37 am |
|
|
Ttelmah wrote: | Add AN928 to the list given above. | I can not find AN928 on the Microchip website. Did you mean AN958: 'Low-Cost Electric Range Control Using a Triac'? |
|
|
Ttelmah Guest
|
|
Posted: Sat Jan 09, 2010 10:53 am |
|
|
No, I meant 928!.
Have an old copy on my HD.
That was why I thought it worth 'adding' to the posted list.
However it appears to have been 'dropped', not appearing on the Microchip site now, and its contents are partially duplicated, with some circuit changes in 958. It is very similar, but using an older chip (16F84).
Looking at the circuit, I'd suspect it was dropped on age, and possibly slight safety doubts....
Best Wishes |
|
|
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
Posted: Sat Jan 09, 2010 11:56 am |
|
|
Ttelmah wrote: | safer to use two series 2.5MR resistors | I think this is a very pertinent point. Never underestimate the importance of safety. Mains voltages can be very deadly if not treated with adequate respect. If your resistors fail, the 'best' that could happen is your chip gets damaged. The 'worst' is someone gets electrocuted! Be careful!!
Rohit |
|
|
pilar
Joined: 30 Jan 2008 Posts: 197
|
|
Posted: Wed Jan 20, 2010 9:12 am |
|
|
Hi, I have problem with the circuit zero crossing detector. I am use the AN938A. The PIC sense the AC using the interrupt the RB0, and also
I use the TMR0 to set time-on of the triac. As you can see in the picture the PIC only can detect the positive half-cycle, but the negative half-cycle is lost.
Here is my code, someone can help me, I need have the pulse trigger to both cycles.
Code: | #include <16F88.h>
#fuses HS,NOWDT,NOPUT,NOLVP,NOBROWNOUT,NOCPD,NOWRT,NODEBUG
#use delay(clock=20000000)
#use fast_io(A)
#use fast_io(B)
#byte PORTA = 0x05
#byte PORTB = 0x06
#byte ANSEL = 0x9B
#byte OPTIONREG = 0x81
#define TRIAC PIN_B1
#define ON output_high
#define OFF output_low
#define Int_Min 50
#define Int_Max 80
#define Periodo 85
int PasosDimmer;
int Intensidad;
int i,j;
#INT_TIMER0
void tempo(){
set_timer0(Periodo);
PasosDimmer++;
if (PasosDimmer==Intensidad){
ON(TRIAC);
delay_us(20);
OFF(TRIAC);
}
}
#INT_EXT
void CrucePor0()
{
PasosDimmer=0;
if (j==0){
j=1;
ext_int_edge(H_TO_L);
}
else {
j=0;
ext_int_edge(L_TO_H);
}
}
void main()
{
set_tris_B(0b11001101);
set_tris_A(0b00011000);
ANSEL=0;
OPTIONREG=OPTIONREG & 0x7F;
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_2);
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_EXT);
ext_int_edge(L_TO_H);
enable_interrupts(GLOBAL);
set_timer0(Periodo);
Intensidad = Int_Max ;
while(1);
}
|
|
|
|
Guest
|
|
Posted: Wed Jan 20, 2010 10:46 am |
|
|
Look up the MOC3032 Triac, or its family.
It will handle the zero voltage crossing for you. |
|
|
Ttelmah Guest
|
|
Posted: Wed Jan 20, 2010 11:14 am |
|
|
First, have you looked at the waveform on the INT_EXT input?. Is it the near square wave it should be?. You possibly have all the symptoms in something 'assymetric' happening here, leading to a narrow detection pulse....
Second comment, change the INT_EXT, to something like:
Code: |
#INT_EXT
void CrucePor0()
{
PasosDimmer=0;
if (input(PIN_B0))
ext_int_edge(H_TO_L);
else
ext_int_edge(L_TO_H);
}
|
This way you base what edge you are looking for, on what signal is currently on the pin.
Third, move the INT_EXT handler in front of the timer handler. Why not disable the timer, once the pulse hs been sent, and re-enable it in the EXT interrupt?. At present, the timer is firing about every 340 instructions, and uses at least seventy instructions every time, and nearer 200, when the triac pulse is fired. Though this should not result in the second edge being missed, it would delay detection....
Best Wishes |
|
|
pilar
Joined: 30 Jan 2008 Posts: 197
|
|
Posted: Wed Jan 20, 2010 11:22 am |
|
|
Yes, I can use the moc3031, but do not want to not use more
components, because I want to make a dimmer. I need the pic doing it. |
|
|
magnoedu
Joined: 29 May 2009 Posts: 11
|
zerocrossing |
Posted: Fri Jan 22, 2010 2:40 pm |
|
|
Hello friend Pilar, I'm trying to make a dimmer also am sending the hardware I'm using might help. I'm having trouble getting the code in C. I'm taking your code and trying to change your code but without success. please help me |
|
|
|