Hi, I am relatively new to Arduino but not to microcontrollers & electronics. I am a retired EE.
With an Arduino UNO (Ver 3.0) and using PULSIN the pulsin readings are off by -6.8 percent across the board I measured from 20 us to 1 second and all are off by the same percentage. I was expecting better accuracy given the microcontroller's crystal clock source. I can certainly compensate for this in code as shown below but it makes the code less efficient. It seems to me that Pulsin should be more accurate than this.
It would be nice to know the reason for such a huge error ?? Anyone know? Certainly the system clock cannot be off by 6.8 percent ?
For reference, below is my sample code that corrects the error to < 1%. (Might help someone else.)
/*
Pulsin Test
*/int pin = 7;
unsigned long duration;
unsigned long corrected_val;
unsigned long timeout = 2000000;void setup() {
Serial.begin(9600);
pinMode(pin, INPUT);
}void loop() {
duration = pulseIn(pin, HIGH,timeout);
corrected_val = duration + (duration / 147 + 1);
Serial.println(corrected_val);
delay(500);
}