Hi Vlad, Correct, your code example is the traditional way to keep track of elapsed time without long-term rounding error, although it's usually not attributed to Bézier.
Not sure if you've been following the whole thread, though -- the problem with timer interrupt code is that it can, and will on rare occasion, conflict with 1PPS rising edge pin interrupts. On a microcontroller, for best precision, the solution is to get rid of the timer interrupts, or get rid of the 1PPS interrupts, or both. Secondly, you cannot share multi-byte variables between interrupt level and main level without synchronization or arbitration. Your code snippet is a good example of what is subtle and dangerous, and dare I say, wrong. You are updating long t_besier in an interrupt handler. Any main level code using t_besier faces byte carry corruption in the multi-byte value of t_besier. True, this works fine on a 32- or 64-bit cpu, but not on an 8- or 16-bit cpu. /tvb ----- Original Message ----- From: "d0ct0r" <[email protected]> To: <[email protected]> Sent: Thursday, April 10, 2014 10:12 AM Subject: Re: [time-nuts] First success with very simple, very low cost GPSDO, under $8 > > I am not sure about Arduino, but probably it too has so-called "timer > overflow interrupt". If so, then its possible to use that other > interrupt and some "long" (lets say 32-bit) RAM variable to accumulate > real value of counter. > > In one of my project I was using timer overflow and Besier method to > make good 1 minutes intervals. > > volatile signed long t_besier = 12000000L; > > interrupt void TPM2OV_ISR(void) > { > TPM2SC = TPM2SC; > if (TPM2SC_TOF) > TPM2SC_TOF=0; > t_besier -= 65536L; > if(t_besier < 0) { > t_besier += 12000000L; > t_time++; > } > } > _______________________________________________ time-nuts mailing list -- [email protected] To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts and follow the instructions there.
