Pages: [1]   Go Down
Author Topic: Zero crossing of the Square wave  (Read 525 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16520
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: March 26, 2013, 11:48:50 pm by retrolefty » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: