ATtiny1616 -> Zerocross Detection Circuit using AC1/DAC1/FVR

Go To Last Post
30 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Hello all,

 

I've a zero-cross circuit for low Hz (<200Hz) but potentially higher voltage (80v) which is working well in terms of reading a signal but less so in terms of phase.

 

Originally the circuit was modelled in LTSpice using a LM2901 with a little additional hysteresis. Since lower value zeners tend to have a bit of capacitance the resistor R5 would bleed this off. My first question is whether when it comes to the AVR comparator this is needed as the hysteresis isn't modelled in current but appears to be a voltage injection (10mV/25mv/50mv). Obviously it has some impedance but it's not specified. I can't see it being a traditional resistor from the output when specified in mV because the output voltage is unknown (Vdd).

 

The second question is to do with phase. I'm attempting to get a measurement but I can already tell by the way it controls another circuit that it's not cutting in or that close to the zero cross point (absolute accuracy isn't required). As I see it the D31 and Z2 have some capacitance which I can't do much about. I can take R7 down quite a bit without violating the Z2 rating but that leaves R5 again.

I'm wondering if I can take R5 completely. The hysteresis shouldn't be required as anything remotely <0.55v dac value/ref is fine to be considered as a zero-cross.

 

Attachment(s): 

Last Edited: Wed. Oct 14, 2020 - 12:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

See Tip #1 for how to have the picture visible in the post:

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is the zener for? Overvoltage protection? If so, don’t use a zener, use two diodes in series rail to rail to form a clamp circuit.
Note that because you trigger at a voltage above the actual zero cross, you’ll get a phase error. This error will vary with the amplitude of the input signal. One method is to use a slicer - have a rc network form a low pass filter to derive the average voltage which ends up being what should be the zero cross point. This becomes the reference for the comparator.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd originally used two diodes in series but the skew of the sluggish 100v diode passed enough reverse current to blow the comparator (in the LM2901) prototype so the zener clamps that at 0.7v.

 

I'm just checking if the Attiny1616 has protection diodes on it's pins (don't see anything in the datasheet), if so omitting the zener would do the same as you suggest, as long as the current is within the protection diode limits. Any drawbacks?

 

The phase shouldn't vary with amplitude, it forms a resistor divider below the zener clamp? There is noise around the 800mV region which now I recall is another reason for the resistor, it takes the zerocross I'm actually using within the 0.55v ref. I can omit it and switch to the 1.1v ref but I'll have to recompute elsewhere (no big deal).

 

The frequency changes so a compensation network won't work - better to not need one in the first place. Can't change from the 1616.
 

Attachment(s): 

Last Edited: Wed. Oct 14, 2020 - 12:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

snoopy33 wrote:
I'm just checking if the Attiny1616 has protection diodes on it's pins (don't see anything in the datasheet), if so omitting the zener would do the same as you suggest, as long as the current is within the protection diode limits. Any drawbacks?

 

Well, there is an appnote that says it's ok to rely on the protection diodes:  http://ww1.microchip.com/downloads/en/AppNotes/Atmel-2508-Zero-Cross-Detector_ApplicationNote_AVR182.pdf

Also, the datasheets for the AVR-Dx, which have an integrated ZCD peripheral, give some suggestions on how to correct for phase.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've already been burnt by PIC16's ZCD in that they don't work well for large voltage ranges, iirc it worked out at 40v so not enough for this application.

 

The reason for the 100v diode is the circuit is powered by the same signal it is monitoring and the bridge which powers this circuit is 30v rated and get's partially cut out on over-voltage (becomes a half-wave), therefore if the 100v diode doesn't exist the reverse pull on the 30v rated part will blow it.

 

I can't find any reference in the datasheet to protection diodes. In PIC16 land it's well documented, I'm a bit worried that assuming they exist is a bad idea. :)

Last Edited: Wed. Oct 14, 2020 - 12:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


snoopy33 wrote:
I'm just checking if the Attiny1616 has protection diodes on it's pins (don't see anything in the datasheet),

It seems the older DS were more complete in this area:

 

Although these diodes exist, it is considered to be good engineering practice to supply external diodes in a ZC application to take the stress this will impart on the AVR chip port pin diodes.

Another consideration, your series current limiting resistor must take into account clearances needed to prevent ARC Flash over, either a TH part is used or multiple SMD resistors in series must be used, and be aware of PCB clearances around any trace carrying line voltage.  Why not use a lower voltage AC signal from a transformer here!

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I doubt what I just posted makes sense, so a fag-packet diagram is attached.

I'm dealing with extremely tight floorspace - no transformers or CPU change.

At present the circuit is working well, I just think the phase is off a bit. I'm setting the scope up to get some measurements now.

Attachment(s): 

Last Edited: Wed. Oct 14, 2020 - 01:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

snoopy33 wrote:
I'm a bit worried that assuming they exist is a bad idea. :)

 

Of course, but you can easily verify they exist with a multimeter (they do).

 

snoopy33 wrote:
I've already been burnt by PIC16's ZCD in that they don't work well for large voltage ranges, iirc it worked out at 40v so not enough for this application.

 

I was not recommending that you used a part with integrated ZCD, but the datasheet may have useful tips to solve the phase problem, even if you use other parts.

Last Edited: Wed. Oct 14, 2020 - 01:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

you've forgotten how to insert a picture already?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What benefit is there over using the zener, other than a little phase?

I'd want to see specs for the 1616 before using the internal ESD's. Microchip rate them as 15mA in PIC's.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

you've forgotten how to insert a picture already?

I never knew, you said "Tip #1" and I couldn't find it. Had a hunt in the WYSIWYG interface and couldn't see it, then moved on.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

snoopy33 wrote:
I can't find any reference in the datasheet to protection diodes.
Very typical for AVR to not have a stated ESD; compare with CMOS SSI and MSI.

snoopy33 wrote:
In PIC16 land it's well documented, I'm a bit worried that assuming they exist is a bad idea. :)
in the qualification report

PCN_GBNG-06LXXH156_Qual_Report

[page 4]

TEST GROUP E – ELECTRICAL VERIFICATION

[ESD CDM and HBM, latch-up]

by entering the CPN at Product Change Notifications | Microchip via Product Change Notification | Microchip Technology

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


I have used the following in a clock project to sync to line ZC.

The diodes used were 1N7002 IIRC.  I used the high to low edge to sync too.

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The bit I'm not getting, without the high diode you have reverse current going through the lower diode. Ground must be connected to the other AC line, that's a reverse pull which potentially builds up to 120v AC on the diode used in that connection. 

 

In other words, it works if the bridge supplying power to the AVR is rated equal to the Line-In voltage. You can see in the diagram posted a bit earlier I don't have that luxury.

 

The benefit to the lack of forward diode it is removes any floating voltage, such as pin capacitance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

snoopy33 wrote:
without the high diode you have reverse current going through the lower diode.

Yes, that is why the high diode exists, to prevent the voltage from rising above the VCC level. (vcc + 0.6v), likewise the lower diode prevents the voltage from going below Vdd level (vdd - 0.6v), keeping the input to the micro with in spec.

http://ww1.microchip.com/downloa...

My circuit adds external diodes to take the load off the internal diodes.  Still it is best to supply the circuit with a lower voltage AC signal, either via a transformer, capacitor, or opto isolation circuit.

Yes it takes some board space, BUT so does providing space for ARC FLASH prevention! As we do not know your experience with HV AC we must caution you to be careful, line voltage can and does kill.

 

Jim

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

snoopy33 wrote:
... to blow the comparator (in the LM2901) prototype ...
Some are more rugged than others.

AoE ZCD has a very similar comparator though with typical EOS suppression, a bit of common-mode current to place the hysteresis, and a bit of positive feedback for hysteresis range.

snoopy33 wrote:
... as long as the current is within the protection diode limits. Any drawbacks?
The very short time duration for ESD suppressors to complete the current division; likely not an issue for ESD though will be for EFT and lightning (so, MOV or such)

 


LM393: Comparator, Dual, Low Offset Voltage | ON Semiconductor (bipolar)

The Art of Electronics 3rd Edition | by Horowitz and Hill

[pages 269 and 270]

4.6.6 Zero-crossing detector

...

+/-350V, max.

...

MAX989 Micropower, Low-Voltage, UCSP/SC70, Rail-to-Rail I/O Comparators - Maxim Integrated (CMOS)

Signal Chain Basics #66: How to interface a 5V transceiver to a 3V controller

by Thomas Kugelstadt

June 27, 2012

[mid-page]

Figure 5. Using a single current-limiting resistor causes damage to the input circuitry.

Redesign Overvoltage Protection to Bolster Reliability and Safety | Electronic Design (GMOV)

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No I get that, but without the 100v forward diode (as I use) then you're relying on the circuits bridge being rated to the line voltage that you're measuring.

 

Anyhow, getting back to the original questions. The comparator must have hysteresis added post output not fed back into the input, I can't see it any other way. This means other than the MCU pin's capacitance I shouldn't have a floating voltage and the 10k is over-kill. I removed the zener and the phase improved dramatically. I then switched the 10k to 2.2M and still have no floating component, and with ref set above the noise it's looking good indeed.

 

Last Edited: Wed. Oct 14, 2020 - 02:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

snoopy33 wrote:
The second question is to do with phase. I'm attempting to get a measurement but I can already tell by the way it controls another circuit that it's not cutting in or that close to the zero cross point (absolute accuracy isn't required).
Try some feedback.

Reason :

ATtiny1614/1616/1617

[page 418]

29. AC - Analog Comparator

...

• Analog Comparator Output Available on Pin

...

Prototype to adjust the AC's common-mode voltage and the feedback.

Evaluate per AC data as min/max has to be wide enough given Microchip's wafer fab process and Microchip's AVR test limits.

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you have a picture of the actual phase error (input  sinewave vs  digital 0 &1 ) of the zero crossing?  How much error are you seeing & what can you tolerate.  Seem like the circuit in #15 is a good way to go....have used that a few times, along with some variations using a 74HC14 schmitt trigger (could tolerate a small phase delay).

The hysteresis shouldn't be required as anything remotely <0.55v dac value/ref is fine to be considered as a zero-cross.

Where is your dac?  What are you saying here? 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That picture above is the actual signal (blue) and AC wave (yellow). It's great now, removing the zener improved it significantly.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That picture above is the actual signal (blue) and AC wave (yellow). It's great now, removing the zener improved it significantly.

Shouldn't the result be a 0/1 signal to compare its phase with the actual zero crossing? Then you can see how tight or jittery things are.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here's where I'm at, and baffled.

 

 

This signal measured on the scope didn't require a ground so I must have a earth loop.

 

The signal is fed into CMP2 and into TMRB which calcs the frequency. It works only when the switch is engaged, otherwise the reads are just very short values (0-2) so noise.

 

Which indicates there's something wrong with the circuit design. Note that half the bridge, from ground is still connected to AC2 (ignore the 30v label). Thus it should be passing exactly what I see on the scope, a half wave to the AVR. 

I'm still using the ZCD schematic shown in the first post, minus the zener and the 10k is now 100k.
 

Last Edited: Fri. Oct 16, 2020 - 01:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

snoopy33 wrote:
This signal measured on the scope didn't require a ground so I must have a earth loop.
Ground is relative, earth is an absolute local, current is differential; so, a differential probe.

A scope can float though do confirm.

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmm, increased the comparator ref to 2.5v. Values should be around 680 (all accurate when bridge switch is enabled). Beginning to get values coming through but must be a lot of noise - thing is it's perfect on the scope!

 

Last Edited: Fri. Oct 16, 2020 - 01:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cooking with gas now. My figures correct?

20mV comparator input offset + 120mV hysteresis max = 0.140mV = 0.15mv with margin.

Using a 470k/33k resistor divider and DAC set as close to 0.15mv I get a switching range (acceptable) of

0.457V to 4.115V

The noise has almost completely been dealt with. I might add a tiny bit of capacitance to act as a filter on the lower resistor if it doesn't skew the phase too much.

It is a shame they don't state in the datasheet what causes the large hysteresis difference. I hope it's heat rather than manufacturing tolerance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

snoopy33 wrote:
I might add a tiny bit of capacitance to act as a filter on the lower resistor if it doesn't skew the phase too much.
That's in the AoE ZCD (time constant of approx 1.8 micro-sec)

snoopy33 wrote:
I hope it's heat rather than manufacturing tolerance.
Later and design as too tight of a tolerance will make for an intolerable failure rate during initial characterization.

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Why do you keep forgetting to show the digital signal?...you want to start with the analog AC & see  0/1 at the final output to verify the zero crossings are happening properly.   Set a pin using a loop or IRQ, so you can see what is going on.

Looking at only one scope channel tells almost nothing--you need to see the final 0/1 result!

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:
Set a pin using a loop or IRQ, so you can see what is going on.
or AC's output :

ATtiny1614/1616/1617

[page 423]

Bit 6 – OUTEN Analog Comparator Output Pad Enable

Writing this bit to ‘1’ makes the OUT signal available on the pin.

 

"Dare to be naïve." - Buckminster Fuller