Go Down

Topic: Measure Zero Crossing (Read 405 times) previous topic - next topic

nabin1994

Apr 14, 2016, 09:34 am Last Edit: Apr 25, 2016, 07:32 am by nabin1994
I want  to  start and stop timer whenever I want.and then I need to calculate the time duration.I will put a full wave ac signal to the analog pin.and want to calculate the time duration of first zero crossing to next zero crossing of that signal.please help me

Coding Badly


Please do not hijack.  Thread split.


nabin1994

#2
Apr 19, 2016, 08:32 am Last Edit: Apr 25, 2016, 07:31 am by nabin1994
suppose continuous data is coming through the analog pin.I want to store those data in a array.like data are 0 1 2 3 4 5 6 7 8 9 10 11 10 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 10 11 10 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 10 11 10 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 10 11 10 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 10 11 10 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 10 11 10 9 8 7 6 5 4 3 2 1 0....................................................................................... I want to store these data spited like [0 1 2 3 4 5 6 7 8 9 10 11] [0 1 2 3 4 5 6 7 8 9 10 11] [0 1 2 3 4 5 6 7 8 9 10 11] and after that I want to find the maximum value from individual array. please give me the code.  

rw950431

If all you want is to find a peak value (and you dont care about when or anything else)

Code: [Select]

setup()
{
  max=0
}

loop()
{
  v=analogRead(pin)
  if (v>max) {
     max=v
  }
  if (v==0) { // or maybe a bit higher to allow for noise
    Serial.println(max)
    max=0
  }
  //maybe delay a bit here
}


nabin1994

#4
Apr 25, 2016, 07:38 am Last Edit: Apr 25, 2016, 08:00 am by nabin1994
how the above code able to calculate the time duration of 1st to next zero crossing????

rw950431

maybe something like this?
Code: [Select]


setup()
{
  max=0
  last=0
}

loop()
{
  v=analogRead(pin)
  if (v>max) {
     max=v
  }
  if (v==0) { // or maybe a bit higher to allow for noise
    now=millis()
    duration=now-last
   
    Serial.print(max)
    Serial.print(",")
    Serial.println(duration)


    max=0
    last=now
  }
  //maybe delay a bit here
}



Obviously the first duration wont be accurate and you will probably have to do some checks on the value of duration to ensure its not too low because you read zero on consecutive readings

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