View previous topic :: View next topic |
Author |
Message |
deperkin
Joined: 04 Feb 2009 Posts: 83 Location: PA
|
zero crossing detector 2VAC |
Posted: Wed Aug 11, 2010 3:51 pm |
|
|
Hello.
I have built a zero-crossing detector using an HCPL-3760.
I am using my 5v supply for the chip from the uC supply.
for an output i get 2VAC at 60hz...
how can I interrupt on this low of a voltage when my reference voltage is still 5V ??
i dont seem to get any interrupt.
I am using a PIC18F4550 and INT2 for this detection.
Thank you all |
|
|
jbmiller
Joined: 07 Oct 2006 Posts: 73 Location: Greensville,Ontario
|
|
Posted: Wed Aug 11, 2010 4:36 pm |
|
|
If you're saying the AC input to the optocoupler is only 2 V AC, then it will never work. The datasheet clearly staes a MINIMUM of 3.7 volts for the device to work...
If you're saying the output to the PIC is only 2 Volts, then I suggest a different load resistor between the output transistor(pin 6) and Vcc( which you say is 5 volts).
Hope this helps
Jay |
|
|
deperkin
Joined: 04 Feb 2009 Posts: 83 Location: PA
|
Load Resistor |
Posted: Wed Aug 11, 2010 5:25 pm |
|
|
I am saying the output is 2VAC...
I did try different load resistors between Vcc and Vo (10k, 20k, 220ohm, 180ohm, and 4.7k)... these are what i had on me.
It seems that they all gave me an output voltage that varied from about 1.8Vac to 2.1Vac.
Can the output ever get up to 5Vac from this optocoupler?
Thanks again.
here is my simple interrupt... which never displays:
#INT_EXT2
void AC_isr(){
disable_interrupts(int_ext2);
lcd_gotoxy(1,1);
printf(lcd_putc,"AC:%u",input(pin_B2));
}
[img]C:\HCPL-3760_PIC.jpeg[/img] |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Wed Aug 11, 2010 5:43 pm |
|
|
Quote: |
Can the output ever get up to 5Vac from this optocoupler?
|
It should. According to the datasheet:
Quote: |
The high gain output stage features an open collector output providing both TTL compatible saturation voltages and
CMOS compatible break down voltages.
|
the output should swing at TTL levels and with the load resistors tested it should have done it. I would double
check if you are aplying enough input voltage to overcome the threshold level that is close to 4V in the
programmable sense voltage.
Humberto |
|
|
deperkin
Joined: 04 Feb 2009 Posts: 83 Location: PA
|
input voltage |
Posted: Wed Aug 11, 2010 5:49 pm |
|
|
i have checked the input voltage, which is 116V on the AC side, and I measure 5V on the DC side (Vcc)...
I do get a good output signal on the scope (60hz) but it is only 2Vac.
i am connecting 120Vac (L) to pin3 with a 20K resistor and 120Vac (N) with a 20K resistor to pin1.
my image doesnt seem to upload...
I am also connecting Vcc (pin 8) to 5V supply and Vo to INT2.
I am connecting a load resistor (10k at the moment) from Vo to Vcc as well... and using a common ground.
it is really similar to the wiring i found here:
http://www.edn.com/archives/1998/042398/09di.pdf
(check the last article) |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Wed Aug 11, 2010 5:58 pm |
|
|
Try to test with 1 resistor (20K) only. |
|
|
deperkin
Joined: 04 Feb 2009 Posts: 83 Location: PA
|
1-resistor |
Posted: Wed Aug 11, 2010 6:03 pm |
|
|
I will try this as soon as I can get back to the circuit (it probably wont be tonight)... THANKS.
you dont think this could cause too much current if i take away the 20K resistor on my LINE voltage (pin 3) ?? or alternatively my neutral (pin 1)... |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Wed Aug 11, 2010 6:07 pm |
|
|
I do not think so, its only a few mA.
Code: |
Input Current
Average 50 mA
Surge IN 140 mA
Transient 500 mA
|
To test it, take out the resistor connected to Neutral.
Be carefull !!!
Humberto
Last edited by Humberto on Wed Aug 11, 2010 6:13 pm; edited 1 time in total |
|
|
deperkin
Joined: 04 Feb 2009 Posts: 83 Location: PA
|
thanks |
Posted: Wed Aug 11, 2010 6:12 pm |
|
|
thanks again...
my plan is also to connect 120VAC to a 30W motor (~10A) as well.
and use another optocoupler to try to control the speed accurately.
so i plan on reading in the zero-crossing and pulsing out to another opto which is connected to a triac.
I appreciate the inputs... |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Wed Aug 11, 2010 6:20 pm |
|
|
I assume we are talking of a regular single phase AC motor, to control the speed you need to change the phase
of each winding or the frequency, and this is not a piece of cake...
Humberto |
|
|
deperkin
Joined: 04 Feb 2009 Posts: 83 Location: PA
|
motor |
Posted: Wed Aug 11, 2010 6:26 pm |
|
|
yes it is single phase...
the plan is to wait for a H_to_L which should be just before the AC crosses to negative and wait some time then output low to the opto, then wait for a L_to_H and output high ...
to essentially get the correct wave output through the triac.
I have the speed control working now, without using a zero-crossing detection, but I get some odd vibration due to being randomly out of phase.
also I am just doing a PWM on the opto coupler... i know this is not correct, but it does change the speed pretty well, it is just not linear at all and not a good way of doing it.
I figure that if i can accurately detect the zero-crossing then i can just output highs and lows to get the correct output from the triac.
I know this is difficult, but it is more difficult to purchase a VFD or auto-transformer... |
|
|
jbmiller
Joined: 07 Oct 2006 Posts: 73 Location: Greensville,Ontario
|
|
Posted: Thu Aug 12, 2010 8:14 pm |
|
|
Didn't Microchip have a PIC burnt for this purpose several years ago called the MTE1122 (energy management control system) ?
I recall an app note...maybe an599,600....something like that, been awhile..... |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Aug 12, 2010 11:35 pm |
|
|
You don't give sufficient information. What do you mean with "2 VAC"? To understand what's going on, it's important to know the absolute voltage levels. What's the observed waveform?
Did you connect the HPCL-3760 input the same way as suggested in the design example, using pin 1 and 3? |
|
|
deperkin
Joined: 04 Feb 2009 Posts: 83 Location: PA
|
2VAC |
Posted: Mon Aug 16, 2010 9:35 pm |
|
|
I am measuring it with a multimeter and getting a 2 VAC output from the HPCL, which I believe is not enough to detect zero-crossing.
Yes I have wired it just like it is shown in the design example.
I have tried adjusting the resistor values (many combinations) and I don't feel this is the right approach either.
I have also tried wiring the 120VAC (L) straight into the PIC using a 1Mohm resistor. I still don't seem to get the proper interrupts this way.
I have a RTC wired up as well and take a count every second and am only getting about 20 counts on the interrupt every second. When I measure the frequency at this input it is 60Hz however.
Do I need to add a full-wave rectifier in order to get the correct count? (and if so are there any suggested P/N's?)
I am confident that the simplest method is to use just a resistor, and I have modified a secondary processor (18F2550) to just detect zero crossing, this way I am not taking wasting valuable time for interrupts.
I have 4 inputs from my main PIC to provide a speed control.
here is the code for the secondary PIC:
Code: |
/////////////////////////////////////////////////////////////////////////////////////
#include <18F2550.H>
#include <STDLIB.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, NOPUT, NOLVP, NOMCLR
//#use delay(clock = 4000000)
#ocs 500 kHz
int16 fanL;
int8 fanspeedinput[4], fanspeed;
void CheckFanSpeed();
int8 bin2bcd(int8 binary_value);
#INT_EXT
void AC_isr(){
disable_interrupts(int_EXT);
output_low(PIN_C2);
delay_us(fanL);
output_high(PIN_C4); //LED
}
void main() {
delay_ms(1000);
SET_TRIS_A(0xFF); //PINS A0-A7 are inputs
SET_TRIS_B(0x00); //PINS B0-B7 are inputs
SET_TRIS_C(0x00); //PINS B0-B7 are inputs
while(TRUE){
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
output_toggle(PIN_C4);
delay_ms(500);
CheckFanSpeed();
switch(fanspeed){
case 10:fanL=0;break;
case 9: fanL=58;break;
case 8: fanL=1515;break;
case 7: fanL=2272;break;
case 6: fanL=3030;break;
case 5: fanL=3788;break;
case 4: fanL=4545; break;
case 3: fanL=5303;break;
case 2: fanL=6060;break;
case 1: fanL=6818;break;
case 0: fanL=7576; break;
default: fanL= 0; break;
}
*/
}
}
void CheckFanSpeed(){
fanspeedinput[0]=input(PIN_A0);
fanspeedinput[1]=input(PIN_A1);
fanspeedinput[2]=input(PIN_A2);
fanspeedinput[3]=input(PIN_A3);
fanspeed = bin2bcd(strcat(strcat(fanspeedinput[3],fanspeedinput[2]),
strcat(fanspeedinput[1],fanspeedinput[0])));
delay_ms(25);
}
int8 bin2bcd(int8 binary_value) {
BYTE temp;
BYTE retval;
temp = binary_value;
retval = 0;
while(1)
{
// Get the tens digit by doing multiple subtraction
// of 10 from the binary value.
if(temp >= 10)
{
temp -= 10;
retval += 0x10;
}
else // Get the ones digit by adding the remainder.
{
retval += temp;
break;
}
}
return(retval);
}
///////////////////////////////////////////////////////////////////////////////////// |
The output in the ISR is sent to an optocoupler which is connected on the opposite side to AC power/snubber network/AC induction motor.
Something is wrong (not just in my programming skills).
When I look with an oscilloscope I don't seem to get any change in the output of the optocoupler...
I may have a bad chip (I will test this in the morning) since I cannot now seem to get it to light up an LED at all (on pin C4).
My idea is just to take a nib as input that gives me a speed (0% to 100%) and depending on the percent I break up ~8ms of time and drive it Low (pin_C2) and run it high the remaining time.
I have seen applications that show another large resistor and diode connected to T0CKI... do you think I would need this as well? I am not sure about the code for this if I do... Again, this secondary PIC will just be used for controlling the speed of an AC fan.
Thank you all for the help by the way, I am overloaded with frustration on this project. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Tue Aug 17, 2010 2:59 am |
|
|
Fvm, has made the important point.
2VAC, means very little. Is this RMS?. What is the peak voltage?. What is the minimum voltage.
The output of this opto, will be going down to a few mV above 0v, and up to nearly 5v. If you have a 50:50 mark space ratio, and then measure this with a tru RMS voltmeter, you would see about 1.77v AC. With a cheaper voltmeter, you might well see a value like 2v. This is completely correct, and is _fine_ to detect the zero crossing.
Measuring digital waveforms, with an AC meter, is basically pointless....
You will notice that the manufacturer, gives no 'AC' specifications for the output.
Since you appear to be wanting to work from both zero crossing points, you will need to use either one of the INT_RB interrupts, or change the interrupt edge in the handler. Otherwise you will only see one edge.
You need to get rid of the delay in the interrupt handler. Program a timer instead. Have 'fanL', contain 65536, minus the count wanted for a particular timer, load this in the edge interrupt, clear the timer interrupt, enable it, invert the detection edge, then exit the edge detection interrupt. When the timer interrupts, set C4, and disable the timer interrupt. Currently, you have long delays in the main code, and delays used in the interrupt, so interrupts _will_ be disabled in the external delays, and interrupts missed...
Sort your code out. The opto, is probably working fine.
Best Wishes |
|
|
|