first commit
This commit is contained in:
42
EMONLIB_TRY_TIME/EMONLIB_TRY_TIME.ino
Normal file
42
EMONLIB_TRY_TIME/EMONLIB_TRY_TIME.ino
Normal file
@@ -0,0 +1,42 @@
|
||||
volatile unsigned long time1;
|
||||
volatile unsigned long time2;
|
||||
unsigned long time3;
|
||||
volatile float ps;
|
||||
volatile boolean data_available = false;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println();
|
||||
pinMode(A3,INPUT);
|
||||
pinMode(A5,INPUT);
|
||||
attachInterrupt(A3,in1,RISING); //enable ISR1 for voltage signal at rising from zero crossing
|
||||
attachInterrupt(A5,in2,RISING); //enable ISR2 for current signal at rising from zero crossing
|
||||
interrupts();
|
||||
}
|
||||
void in1()
|
||||
{
|
||||
time1=micros(); //measure time in micro second for first zero crossing ISR1
|
||||
}
|
||||
void in2()
|
||||
{
|
||||
time2=micros(); //measure time in micro second for first zero crossing ISR2
|
||||
data_available = true;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (data_available == true)
|
||||
{
|
||||
time3=time2-time1;
|
||||
ps = ((time3*360.0)*50/1000000); //calculate the phase shift from measured time difference
|
||||
Serial.print("Time1=");
|
||||
Serial.println(time1);
|
||||
Serial.print("Time2=");
|
||||
Serial.println(time2);
|
||||
Serial.print("Phase Shift = ");
|
||||
Serial.println(ps,6);
|
||||
Serial.print("degree\n\n");
|
||||
data_available = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user