I don't understand much here
10 pps => 10 pulses per second?
1 pps then is 1 pulse per second?
i have worked thru the code with more comments.. under the assumption that 1pps is 1 pulse per second.
if(incomingByte == 'x')
{
incomingByte = 0;
for (uint32_t i=c; i>0; i--) // what is 'c' - old code it is 1.
pulseIn(freq, HIGH);
delayMicroseconds(freqdelay);
digitalWrite(CTB, HIGH); // what does this write to CTB do?
delay(5);
digitalWrite(CTB, LOW); // again... what?
pulseIn(pps, HIGH, 2000000);
fds = micros(); // end of last pulse
pulseIn(freq, HIGH);
fde = micros(); // end of next pulse
freqdelay =
(3000 + // what is the magic number 3000?, 3ms means what
adj) // what is adj, apart from an integer?
-
(fde - fds); // this is the time for a cycle, in mico seconds.
// at 10 pulse per second approx 100,000
// at 1 pulse per second approx 1,000,000
// integer - 1,000,000 => approximately - 1,000,000
// If freqdelay is still an integer, then the results should be low 16 bits of the value.
// The low 16 bits may not have an easy meaning to understand, but the are not random (was my first thought); but the part of the freqdelay modulo 65,536.
// how stable is the source of the pulses, maybe the variation (order of 2 milliSecs) is
// what the hardware achieves?
Serial.println(freqdelay);
}
ps
your first code had a bug in saving the adj value
EEPROM.write(2,c); should have been in > 0 branch as well.
Earlier screwy comments --
pulseIn(pps, HIGH, 2000000);
2,000,000 is bigger than an integers maximum value.
2000000L would get you what you think is happening maybe?Sorry - no 2000000 is interpreted as a long value correctly - the compiler is smarter than I am.