CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Zero crossing detector

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

Zero crossing detector
PostPosted: Fri Jan 08, 2010 9:26 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Sat Jan 09, 2010 3:27 am     Reply with quote

A single high value resistor connected to the RB0/Int pin can be used in series with the live line. Have a look at the following Microchip app notes:

AN521: http://ww1.microchip.com/downloads/en/AppNotes/00521c.pdf
AN958: http://ww1.microchip.com/downloads/en/AppNotes/00958A.pdf
AN236: http://ww1.microchip.com/downloads/en/AppNotes/00236a.pdf

Rohit
Ttelmah
Guest







PostPosted: Sat Jan 09, 2010 3:31 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jan 09, 2010 8:37 am     Reply with quote

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







PostPosted: Sat Jan 09, 2010 10:53 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Sat Jan 09, 2010 11:56 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 20, 2010 9:12 am     Reply with quote

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








PostPosted: Wed Jan 20, 2010 10:46 am     Reply with quote

Look up the MOC3032 Triac, or its family.

It will handle the zero voltage crossing for you.
Ttelmah
Guest







PostPosted: Wed Jan 20, 2010 11:14 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 20, 2010 11:22 am     Reply with quote

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

View user's profile Send private message MSN Messenger

zerocrossing
PostPosted: Fri Jan 22, 2010 2:40 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group