Zero crossing of the Square wave

hi...
i am using arduino due. i want to check the zero crossing of the AC waveform because i want to trigger six pulse thyristor. so i need zero crossing of the AC voltage.For that, i prepared a schmitt trigger which detects the zero crossing of the AC signal which gives me square wave then i put one diode so negative pulse is discard.so i am getting only positive square pulse.this pulse have maximum value is 3.0 volt.i am giving this pulse to analog pin A0.and i have written following code.

int pin2=2,pin3=3,pin4=4,pin5=5,pin6=6,pin7=7;
int sensor=A0;
void setup() {
Serial.begin(115200);
pinMode(pin2,OUTPUT);
pinMode(pin3,OUTPUT);
pinMode(pin4,OUTPUT);
pinMode(pin5,OUTPUT);
pinMode(pin6,OUTPUT);
pinMode(pin7,OUTPUT);
// put your setup code here, to run once:

}
void loop() {

int i,c;
int d[15];
for(i=1;i<=15;i++)
{
d = analogRead(A0);
_ Serial.println(d*);_
_
d[0]= 1023;_
_ c=d-d[i-1];
Serial.println(c);
if (c>0)
{
goto IRFAN;
}*_

}
// put your main code here, to run repeatedly:
* IRFAN:*
* while(1)*
{
* //Serial.println('c');*
* digitalWrite(pin7,LOW);*
* digitalWrite(pin2,HIGH);*
* delayMicroseconds(3333);*
* digitalWrite(pin2,LOW);*
* digitalWrite(pin3,HIGH);*
* delayMicroseconds(3333);*
* digitalWrite(pin3,LOW);*
* digitalWrite(pin4,HIGH);*
* delayMicroseconds(3333);*
* digitalWrite(pin4,LOW);*
* digitalWrite(pin5,HIGH);*
* delayMicroseconds(3333);*
* digitalWrite(pin5,LOW);*
* digitalWrite(pin6,HIGH);*
* delayMicroseconds(3333);*
* digitalWrite(pin6,LOW);*
* digitalWrite(pin7,HIGH);*
* delayMicroseconds(3333);*
* }*
}
i am taking difference of two values d and d[i-1] so i can trigger all thyristor very accurately.but when i am uploading this program, DSO is not showing me exact zero cross. i am not getting pulse at exact zero cross it is slowly moving with respect to AC waveform.so please suggest me what can i do?

Why are you reading the the signal as a analog voltage with a analogRead() statement?

The information from your schmitt trigger device is a digital timing signal and you should be reading it as a digital signal with a digitalRead() statement or using the signal to generate an interrupt.

Lefty

Thanks...
i will try with digitalread() command.