Re:Trying to implement zero cross detector on attiny2313 load 230v AC

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

Hi

 

I am working on Trying to implement zero cross detector on attiny2313  load 230v AC,i am using attiny2313 INT0 PIN for external interrupt,and D0 for signal.I am not getting proper output 

Posting the code ,Kindly guide me

/*
 
 *

guide me.

Last Edited: Fri. Sep 11, 2015 - 05:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It would be much nicer if you embedded the picture.  You have 240v AC via 2x 10k resistors into a bridge rectifier then into an opto.  What do you see on the output of the opto using a scope?   

 

David

 

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

 

 

Hi David 

 

Thank you for response

 

please find  attachment  i am attaching output response on  CRO

 

Thanks&Regards

ss

 

* HUGE picture reduced and inlined. Moderator*

* I am sorry Samathasan, I do not know how I became the author of your post. Moderator*

 

 

Ross McKenzie ValuSoft Melbourne Australia

Last Edited: Fri. Sep 11, 2015 - 11:58 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Warning! Connecting an oscilloscope to the line (AC) side of this circuit is incredibly dangerous and may result in injury or death.

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

sjdavies wrote:

Warning! Connecting an oscilloscope to the line (AC) side of this circuit is incredibly dangerous and may result in injury or death.

... and/or destruction of your oscilloscope.

 

Ross McKenzie ValuSoft Melbourne Australia

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

Was 10k the only resistors in the simulator?

A critical spec of an optocoupler is the CTR - current transfer ratio. Since you have a simulator, it is just a click or two to add a scope to measure the led current. What does that tell you?

Try reducing the voltage of the AC source so you get a reasonable pulse width on the output.

Last Edited: Thu. Sep 17, 2015 - 10:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes I agree.   Get a 'wall-wart' power adapter that accepts 230VAC and outputs 12VAC and test all the circuits with 12VAC.

 

  In theory, there will be @16 milliamps going through the opto-coupler.  230v (RMS) is 230v/.707 volts peak.  328v / 20000 ohms = ~16mA.  But  is there still 328V going through the opto-coupler?

 

Have you checked the web for safe and detailed circuits for detecting zero-crossing with a microprocessor?

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

Simonetta wrote:
Yes I agree.   Get a 'wall-wart' power adapter that accepts 230VAC and outputs 12VAC and test all the circuits with 12VAC.
+1

 

Quote:
But  is there still 328V going through the opto-coupler?
No.  The LED in the opto will have a VF of about 1.3 V.  However if the opto is removed from the circuit (or fails), the connection point where it was will have a peak voltage of 328V and an RMS voltage of 230V (ignoring the VF drop of the bridge).  While the resistors will limit the current that could flow, it will still pose a hazard to anyone touching the circuit at the point.

 

However the HV side of the circuit should never be exposed to fingers anyway.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Fri. Sep 18, 2015 - 12:46 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Start with a transformer and step the AC voltage down to something safe, say 7V. Running that into a full-wave bridge will give you a positive pulsing rectified sine signal, peaking around 10V. Let's call this signal Vin.

 

The zero crossing point occurs when Vin = 0. Connecting this to a logic level pin, e.g. INT0, will not give the correct answer as the pin is guaranteed to see a logical 0 when the voltage crosses the logic low threshold. That is, connecting to INT0 will detect Vin < VLTHRESH, not Vin = 0. VLTHRESH is going to be a function of the micro controller supply voltage. Trying to detect an analog voltage with a digital input is a bad idea, you need an analog device.

 

Fortunately the tiny2313 contains an analog comparator. I'd consider connecting the Vin signal to AIN1 (-) and AIN0 (+) to a resistor network trimmable in the range 0-50 uV (microvolts), call this Vset. That is you want the AIN0 pin to be adjusted ever so slightly above ground.

 

The Vin signal has a 10V peak and connecting it directly to a device running at say 5V is a bad idea and will fry the device. The Vin signal needs to be 'clipped' so that it doesn't rise significantly above the microcontroller supply voltage. To do this use a series resistor, say 1k ohm, so that Vin becomes Vsig and than connect a clamp diode between Vsig and Vsupply. A Schottky diode would limit Vsig to Vsupply + 0.2V, a silicon diode has a 0.6V drop. The series resistor is there to limit current into the diode when Vin rises above Vsupply. If you attach a 'scope to Vsig you should see the 'top' of the sine wave gets cutoff at the Vsig + 0.2 point.

 

The rest should be programming. A simple test would be to copy the comparator output to an IO pin. You should get a narrow pulse every time Vsig falls below Vset. I'd use the 'scope to display Vsig on CH1 & the output on CH2. Raising Vset should make the pulse wider (and less accurate). 

Last Edited: Fri. Sep 18, 2015 - 05:49 AM