Skip to main content
Revised following further research
Source Link
SlySven
  • 3.6k
  • 1
  • 19
  • 45

For starters though your zero detection circuit will not be producingFor starters though your zero detection circuit will not be producing the signal you expect - the LED in the PC814 will be illuminated for virtually all of one half of a mains cycle, that means the photo-transistor will be conducting and thus pull the pin going to the Raspberry Pi to around VCE(sat) above 0 volts which will be around 0.4 or 0.5 volts I expect. For the rest of the time the input to the Pi will be pulled up via the 33K; to get a pulse around the time of both zero-crossings (i.e. at a 100hz rate) you'll need to feed the PC814 LED via a bridge-rectifier circuit - without a smoothing capacitor. Um, I looked at a datasheet for this device and found that both those diode devices are optical emitters i.e. LEDs, the signalone further from the transistor symbol is not a reverse polarity protection device as I at first thought! That being said the waveform you expectshow as Pic2 is inverted - the LED in the PC814transistor will be illuminatedturned on and saturated for virtually all of onethe cycle half(one of the LEDs is illuminated except for a mains cycle, that meansvery small time around the photozero-transistor will be conductingcrossing) and thus pull the pin going to the Raspberry Pi to around VCE(sat) above 0 volts which will be low except for a very small time around 0.4 or 0.5 volts I expectthe zero-crossing. ForAlso the rest of33KΩ and 3.3 volt supply mean the timepeak Ic for the input totransistor is 0.1mA which is off the Pi will be pulled up viarange that is characterised in the 33K; to get a pulse arounddatasheet I saw, given the timecapabilities of both zero-crossings (ithe Pi's 3.e3V supply I'd drop that resistor to, say 6. at a 100hz rate) you'll need8KΩ to feedraise the PC814 LED via a bridge-rectifier circuit - without a smoothing capacitorcurrent to nearly 0.5mA which just about gets it onto the ranges shown on the graphs in the datasheet.

Having done that, toTo get a controllable power output you must start a timer as soon as you detect a zero crossing with a minimum of around half the width of the pulse (so that ideally you start the timer at the peak of the pulse which neglecting the turn-off time of the photo-transistor in PC814 is the point when the current though the load is passing through zero) and a maximum of a bit less than the half-cycle time (10 mSec for 50Hz mains) less the time you allowed at the start and the time you need for the pulse to turn the output TRIAC on - then when the timer has ended THEN you send that pulse to turn the output on for the time to the end of THAT half-cycle. The longer the delay before sending that pulse the less the power that gets put into the load.

For starters though your zero detection circuit will not be producing the signal you expect - the LED in the PC814 will be illuminated for virtually all of one half of a mains cycle, that means the photo-transistor will be conducting and thus pull the pin going to the Raspberry Pi to around VCE(sat) above 0 volts which will be around 0.4 or 0.5 volts I expect. For the rest of the time the input to the Pi will be pulled up via the 33K; to get a pulse around the time of both zero-crossings (i.e. at a 100hz rate) you'll need to feed the PC814 LED via a bridge-rectifier circuit - without a smoothing capacitor.

Having done that, to get a controllable power output you must start a timer as soon as you detect a zero crossing with a minimum of around half the width of the pulse (so that ideally you start the timer at the peak of the pulse which neglecting the turn-off time of the photo-transistor in PC814 is the point when the current though the load is passing through zero) and a maximum of a bit less than the half-cycle time (10 mSec for 50Hz mains) less the time you allowed at the start and the time you need for the pulse to turn the output TRIAC on - then when the timer has ended THEN you send that pulse to turn the output on for the time to the end of THAT half-cycle. The longer the delay before sending that pulse the less the power that gets put into the load.

For starters though your zero detection circuit will not be producing the signal you expect - the LED in the PC814 will be illuminated for virtually all of one half of a mains cycle, that means the photo-transistor will be conducting and thus pull the pin going to the Raspberry Pi to around VCE(sat) above 0 volts which will be around 0.4 or 0.5 volts I expect. For the rest of the time the input to the Pi will be pulled up via the 33K; to get a pulse around the time of both zero-crossings (i.e. at a 100hz rate) you'll need to feed the PC814 LED via a bridge-rectifier circuit - without a smoothing capacitor. Um, I looked at a datasheet for this device and found that both those diode devices are optical emitters i.e. LEDs, the one further from the transistor symbol is not a reverse polarity protection device as I at first thought! That being said the waveform you show as Pic2 is inverted - the transistor will be turned on and saturated for virtually all the cycle (one of the LEDs is illuminated except for a very small time around the zero-crossing) and thus the pin to the Pi will be low except for a very small time around the zero-crossing. Also the 33KΩ and 3.3 volt supply mean the peak Ic for the transistor is 0.1mA which is off the range that is characterised in the datasheet I saw, given the capabilities of the Pi's 3.3V supply I'd drop that resistor to, say 6.8KΩ to raise the current to nearly 0.5mA which just about gets it onto the ranges shown on the graphs in the datasheet.

To get a controllable power output you must start a timer as soon as you detect a zero crossing with a minimum of around half the width of the pulse (so that ideally you start the timer at the peak of the pulse which neglecting the turn-off time of the photo-transistor in PC814 is the point when the current though the load is passing through zero) and a maximum of a bit less than the half-cycle time (10 mSec for 50Hz mains) less the time you allowed at the start and the time you need for the pulse to turn the output TRIAC on - then when the timer has ended THEN you send that pulse to turn the output on for the time to the end of THAT half-cycle. The longer the delay before sending that pulse the less the power that gets put into the load.

Added note on formal qualification
Source Link
SlySven
  • 3.6k
  • 1
  • 19
  • 45

{FTR: I hold a BEng(Hons) in Electrical & Electronic Engineering}

{FTR: I hold a BEng(Hons) in Electrical & Electronic Engineering}

Source Link
SlySven
  • 3.6k
  • 1
  • 19
  • 45

Well done on including the bare bones of the circuitry you are trying to use!

As @Chris has said your use of the Triac is not correct in that it does not conduct electricity through the main terminals (MT1 <==> MT2 or in this case pins 4 and 6) until a sufficient gate pulse is delivered into the gate terminal - or, in this case, as you have very wisely opted to use a optically isolated one, until a sufficient pulse of current is sent through the LED. It will continue to conduct until the current through it falls to a low enough value that it switches off - this is the simplistic case when the load is mainly resistive but any significant capacitance or inductance will mess with this (i.e. it will a good model for an incandescent light bulb but considerably less so for a motor).

For starters though your zero detection circuit will not be producing the signal you expect - the LED in the PC814 will be illuminated for virtually all of one half of a mains cycle, that means the photo-transistor will be conducting and thus pull the pin going to the Raspberry Pi to around VCE(sat) above 0 volts which will be around 0.4 or 0.5 volts I expect. For the rest of the time the input to the Pi will be pulled up via the 33K; to get a pulse around the time of both zero-crossings (i.e. at a 100hz rate) you'll need to feed the PC814 LED via a bridge-rectifier circuit - without a smoothing capacitor.

Having done that, to get a controllable power output you must start a timer as soon as you detect a zero crossing with a minimum of around half the width of the pulse (so that ideally you start the timer at the peak of the pulse which neglecting the turn-off time of the photo-transistor in PC814 is the point when the current though the load is passing through zero) and a maximum of a bit less than the half-cycle time (10 mSec for 50Hz mains) less the time you allowed at the start and the time you need for the pulse to turn the output TRIAC on - then when the timer has ended THEN you send that pulse to turn the output on for the time to the end of THAT half-cycle. The longer the delay before sending that pulse the less the power that gets put into the load.

You will want to tweak those timings (minimum, maximum and turn-on pulse duration). As for the quality of the timing overall, we are talking a timer being run every 10 milli-Seconds but which does need a fairly low latency to detect the start time to be initiated by the zero-crossing detection; I do not know how good the Pi can be made to respond to the signal, ideally it would be an interrupt input which is not something I had have exposure to on the Pi series.

MAINS ELECTRICITY IS DANGEROUS! - The use of (optical) isolation is vital in this usage case, I'd strongly urge you to put all of the circuitry you have shown on a separate PWB in a separate enclosure (which needs a tool to open it), with at least a 6mm gap between every copper track (and the pads thereon) on the live side and the low-voltage stuff which the Opto devices will straddle. Also a suitably rated fast blow fuse in the Live supply rail before the feed to the Opto-isolator PC814 and to wire the Opto-Triac between the Live supply and the load (so that if the TRIAC fails open-circuit the load is not left pulled up to the Live supply) - though the failure mechanism for TRIACs does seem to be to fail short-circuit in my experience! Remember also to fasten the wiring on both sides of the "Mains Barrier" especially on the Live side so that there is more than one thing holding each wire (as short as possible and not possible to cross the barrier unless with TWO layers of insulation a.k.a. DOUBLE-insulated) in place (a two screw per terminal block OR solder and a tie wrap to the PWB for each conductor) and a Mains Warning label on the outside of the enclosure, etc., etc. ...

Disclaimer: The above constitutes advice only, I accept no liability for anyone taking it and would urge everyone who plans to do something like this to satisfy themselves that they are aware of the risks and responsibilities for them and un-informed others who may come into contact with what they have done.