Analog Timing issue.
this has got me beat. i'm doing time critical measurements , problem. i'm chasing why there large steps in time measurements.
i'm supplying 50 hz signal board. time between cycles 20000 usec.
i'm send serial output once second. in order nice clean signal wait falling edge, rising 1 make sure trigger voltage d goes >200. record time.
i wait falling edge , rising , take next time measurement. i subtract 2 time per cycle.
now question, when add small delay, way below 20000 usec period, why timing measured change , why such odd numbers. timing should not change @ all.
for
delaymicroseconds(1); or no delay
i
20048
20048
for
delaymicroseconds(4);
i
20064
20064
for
delaymicroseconds(20);
i
20080
20080
for
delaymicroseconds(40);
i
20096
20096
for
delaymicroseconds(60);
i
20000
20000
for
delaymicroseconds(70);
i
20016
20016
i'm supplying 50 hz signal board. time between cycles 20000 usec.
i'm send serial output once second. in order nice clean signal wait falling edge, rising 1 make sure trigger voltage d goes >200. record time.
i wait falling edge , rising , take next time measurement. i subtract 2 time per cycle.
now question, when add small delay, way below 20000 usec period, why timing measured change , why such odd numbers. timing should not change @ all.
for
delaymicroseconds(1); or no delay
i
20048
20048
for
delaymicroseconds(4);
i
20064
20064
for
delaymicroseconds(20);
i
20080
20080
for
delaymicroseconds(40);
i
20096
20096
for
delaymicroseconds(60);
i
20000
20000
for
delaymicroseconds(70);
i
20016
20016
code: [select]
unsigned long rpmstarttime = 0;
unsigned long rpmendtime=0;
unsigned long rpmduration=0;
void setup() {
serial.begin(115200); // initialize serial communications:
analogreference(default);
}
void loop() {
while(analogread(5) >= 200){} // wait falling edge
while(analogread(5) < 200) {} // wait rising edge
rpmstarttime=micros();
delaymicroseconds(60);
while(analogread(5) >= 200){} // wait falling edge
while(analogread(5) < 200) {} // wait rising edge
rpmendtime=micros();
rpmduration=rpmendtime-rpmstarttime;
serial.println(rpmduration);
delay(1000);
}
first of all, call waitmicroseconds() should have nothing @ measurement. there time gap of around 10,000 microseconds @ place.
as analogeread() takes 150 error involved in sine-measurements; signal >200 can occur anywhere in time window.
as there implicit averaging between start , stop measurement expected mean delay should around 50 100 us
as analogeread() takes 150 error involved in sine-measurements; signal >200 can occur anywhere in time window.
as there implicit averaging between start , stop measurement expected mean delay should around 50 100 us
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Analog Timing issue.
arduino
Comments
Post a Comment