Jump to content
Sign in to follow this  
Clashlab

Interfacing To Power Lines

Recommended Posts

Hi,

 

I would like to know if I can use the method described in AN521 to detect the power line zero crossing (that is using only a resistor) on a 16F88 using portB pin 7.

I don't see the diodes on the datasheet schematic for that pin so I am wondering if I have to put them outside the pic.

The reason I choose portB pin 7 is because I need an interrupt on change.

 

Thanks

Share this post


Link to post
Share on other sites
Hi,

 

I would like to know if I can use the method described in AN521 to detect the power line zero crossing (that is using only a resistor) on a 16F88 using portB pin 7.

I don't see the diodes on the datasheet schematic for that pin so I am wondering if I have to put them outside the pic.

The reason I choose portB pin 7 is because I need an interrupt on change.

 

Thanks

 

The diodes are part of the ESD protection.

I think generally they are not drawn on the block diagram, their presence is assumed.

Have a look at other datasheets.

I think they have been drawn on the portA diagrams of the 16f88 to illustrate that RA5 does not have a diode to supply (you wouldnt be able to set Vpp if a diode was present)

The best thing you can do is to ask Microchip at

http://support.microchip.com/scripts/slxwe...e=webticketcust

They are fairly fast at responding and should give an accurate answer.

Share this post


Link to post
Share on other sites

They did answer me:

That method was really just for the PIC16C54, and actually operated the device outside of its specifications. It was possible to get away with it on older devices, and was designed into a number of earlier products (at the users risk) and worked well, which is why the appnote was created about 10 years ago. Please note that the existance of an application note does not guarantee suitability, particularly for other devices.

 

The diodes are desgined for intermittent operation only for ESD protection. The specifications to use the device state that you can not exceed 0+Vdd and Vss-0 (given as Vdd and Vss) - see the Electrical characteristics section Vih and Vil values. The values for 0.3V past Vdd and Vss are part of the Absolute Maximum Ratings. The device is not guaranteed to operate correctly when out of spec, even if within AMR values. However, not exceeding AMR means that you should not expect permanant device damage.

 

If you plan to connect an AC signal to the device, you will need to limit it externally, such as with an external zener or other similar option. The an521 is old and requires revision. There should be a note stating that this is at the users own risk and violates the letter of the specification. It should also state that it was only used on older devices (PIC16C54 for example) where no ill effects were observed at the time. However, newer devices are prone to more problems when implementing this.

 

Further, the ESD diodes may not fail immediately when using this note, but become weaker and weaker over time. This means that ill effects could be observed immediately, or possibly after considerable time. If you consider implemeting this, it would be best to just meet the input current specification (+/- 1uA) - say 5 uA or so. The less current conducted by the diodes the better. However, if you desire your design to be within specification, you should use external clamping to prevent from exceeding Vdd and Vss.

 

While I have noted the best conditions here to make this work, please note this can not be interpreted as a guarantee or recommendation from myself or Microchip.

So I will not use that method. Instead I will connect the power line thru a resistor to a NOT gate (which allows exceeding the voltage specifications as long as the current specification is meet, i.e. SN74AHC1G04) and connect that output to the pic (also thru a resistor).

Share this post


Link to post
Share on other sites

Jebus! Its like a Dilbert story.

 

The ap note refers to a product they no longer promote and they say it should have various warnings.

 

Have you thought about total galvanic isolation, ie use a transformer or an optoisolator, its a little more inconvenient but less inconvenient than death.

Share this post


Link to post
Share on other sites
Jebus! Its like a Dilbert story.

 

The ap note refers to a product they no longer promote and they say it should have various warnings.

 

Have you thought about total galvanic isolation, ie use a transformer or an optoisolator, its a little more inconvenient but less inconvenient than death.

 

 

I agree.

 

What the ap note fails to mention is that for the method to work, the power line neutral would need connecting to the PIC's ground line. Expect that someone somewhere will get the hot and neutral lines crossed - the circuit ground is now at 120V or worse...

Share this post


Link to post
Share on other sites

Since you want this zero crossing detector to trigger an interrupt, I'm guessing you are trying to get a very accurate 50Hz or 60Hz timebase for a clock and not trying to do high frequency networking on the power line. If so you should take Picxie's advice and use an isolation transformer. Most folks use an AC wall wart to get 9 VAC then make a local power supply with diodes and a simple linear regulator or a switcher. You then can tap off the input to the bridge rectifier and get a low voltage and safely isolated signal that you make a simple resistor zener protection circuit and then shove the output into a schmidt trigger input. Instead of looking for zero, look for one and you will only get 50 or 60 rising edges/second. Nice and clean.

 

People have been doing this for more than 20 years. It is pretty solid and will survive power surges and most nearby lightning strikes!

 

I used to make my students calculate the value of the resistor using a 5.1 V zener that would allow the circuit to work over the widest range of input voltages without burning up the diode.

Share this post


Link to post
Share on other sites

Well, what I wanna do is control a triac for light dimming. So I need to know when the power line crosses zero.

 

I don't need a very high accuracy, 100 µs delay will be ok.

But I don't want the interrupt to occur at the peak value of the sine curve nor the interrupt occurring at very different times if the sine curve is going down or up.

 

So using a transformer to get a 9v sine curve is not acceptable because (50Hz) :

Going from 0 to 1 needs 2v (TTL) => t = arcsin( 2 / 9 )/( 2 * pi * 50 ) = 0.7 ms later

Going from 1 to 0 needs 0.8v (TTL) => t = arcsin( 2 / 9 )/( 2 * pi * 50 ) = 0.3 ms earlier

This leads to a 1 ms different between two interrupts, on a 50Hz signal that is 10%, it's too much.

Share this post


Link to post
Share on other sites

I suggest you skip the digital technique and use the A/D converter. You can either set up a timer to read the A/D result then start the next conversion or just do a spin loop of starting, waiting, reading and waiting till you see the voltage go from above a threshold (1V) to below another threshold (0.02V) and only detect the falling zero crossing. You may have to tune the low threshold as there may be some noise or offset in the system that prevents you from seeing zero. You could still use the zerner diode and resistor setup I described. Doing a little simple DSP (average samples in time) should get you very good results. I think the A/D converter can give you an answer in 10us. 8 bits is more than enough accuracy so just grab the upper 8.

Share this post


Link to post
Share on other sites

My Bad. I meant to say zener diode. Here is some lovely ASCII art. I did it with trial and error. Not real easy to do for some reason.

 

 
	 o---/\/\/\/\/---+--------| AN0
		   1K		|
				   /----/
					 /\	  5.1 V
				   /---\
					 |
					 |
				   -----
					---
					 -

 

Shove 9 VAC in on the left and AN0 will see a clipped sine wave that goes from about -0.6 V to about 5 V. If you are running your PIC at 3V get a lower voltage zener diode.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...