[time-nuts] First success with very simple, very low cost GPSDO, under $8

d0ct0r time at patoka.org
Thu Apr 10 16:52:47 EDT 2014

> 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.

My bad ! I messed up Bezier and Bresenham line algorithm, which I was 
using for generating one average timed period from any other timed 
period (like the PIC timer0 overflow period, for example).

> 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.

I am not familiar with Arduino. STM32, for sure, has interrupt priority. 
But than it will not be 8$ project. ;-)  The best results I achieve 
using DMA. Timer updating the buffer variable(s) in background and its 
not using interrupts for it. So, I could read the current value of 
counter any time. At least I got good results for this approach when I 
connect MCU clock to GPSDO and tried to measure the signal from external 
OCXO. I got perfect 10 Mhz at that time.

> 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.


> ----- Original Message -----
> From: "d0ct0r" <time at patoka.org>
> To: <time-nuts at febo.com>
> 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 -- time-nuts at febo.com
> To unsubscribe, go to 
> https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
> and follow the instructions there.



More information about the time-nuts mailing list