I use a resistor as zero detect, 1 meg from phase straight into the port, I then have a 470K resistor on the pin next door to it and swing the bias in an opposite direction to the mains ie:
GPIO.5 is the output pin with the 470K on it - trigger is GPIO.4 which is connected upto the 1M which goes straight to phase. The triac is triggered by a BC327 and i trigger by turning pic from high impedance to low by changing from input to output.
LowSide: 'look for trigger points and trigger triac
IF trigger = 1 Then lowside 'wait for phase to go low
GPIO.5 = 0 'weight input to sense zero crossing
PauseUs dim 'wait for dim period
Output triac 'fire triac
triac = 0
PauseUs 400
Input triac
HighSide:
IF trigger = 0 Then HighSide
GPIO.5 = 1
PauseUs dim
Output triac
triac = 0
PauseUs 400
Input triac
GoTo start
Bookmarks