Go Down

Topic: Zero crossing of the Square wave (Read 1 time) previous topic - next topic

irfanatul

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?

retrolefty

#1
Mar 27, 2013, 05:30 am Last Edit: Mar 27, 2013, 05:48 am by retrolefty Reason: 1
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

irfanatul

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

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy