skimask:
Let’s see the code…
void onchange(){
_change=!_change;
if (!_change) onup();else ondown();
}
void onup(){}
void ondown(){
long itime=micros();
timeus=itime-time; //get a full periode on down:_┌─┐_______┌─┐_
time=itime;
// avoid overflow
if (usi<SAMPLES){
us[usi]=(timeus)/1000.0;
usi++;
}
...
}
...
void setup(){
...
// bind ardware interuption on pin 2
attachInterrupt(0,onchange,CHANGE);
....
}
void loop(){
//clean buffer
usi=0;
time=0;
//measure 1s
_sample=true;
digitalWrite(P_SENS, HIGH);
delay(1000);
digitalWrite(P_SENS, LOW);
delay(2);
#ifdef CC_DEBUG
// vref 5V=5.0/1024.0=0.0048828, 3.3/1024.0=0.0032226
Serial.print(" SAMPLES: ");
for (int i=2;i<(usi);i++){
Serial.print(us[i],4);
Serial.print(" ");
}
Serial.println();
#endif
....
The average of 200[microseconds] is in fact the sum of 8 samples that composes the 250[ms]. I took a picture of the deviation between the 168 and the 328p. One other thing interresting, the deviation is about 200[us] [u]but there is no relevant deviation between two 328p board[/u].Mee_n_Mac:
What’s the standard deviation of timing for each processor ?
What is the formula to get the delta from the ppm?Philba:
At first I thought it was because of resonators but both boards appear to use crystals. Still, there is always going to be some error and .12% is a bit out of spec for typical crystals (actually, it could be 0.0625%, one high and the other low). It would be strange if they both agreed to the microsecond. 50 ppm crystals could yield up to a difference of 25 microseconds.
thank you very much for helping!!!
– olivier