Bob, Yes, that is kind of how it works. The timer is only read once per second. After reading it we subtract whatever was the count in the previous sample to get the number of cycles in this last second. There is no accurate way to reset the timer at the start of the second. So we let it run "forever". The 16-bit timer actually over flows many times per second. The maximum value it ever gets to is about 65,536. (actually 2^16 - 1) The counter will never reach 10,000,000. (but actually we count after a divide by 2 so 5,000,000 is the target number)
As it turns out even in a perfect world the counter value every second is some random value between zero and 65535. Because when the overflows happen depend in the exact microsecond I applied power to the system., that is my arbitrary "zero" and I count up from there overflowing back to zero about 76.6 times per second Every second we capture whatever the timer value is and compute "delts cycles" You are right in the I don't even need data cycles. All I want is the error which is 5,000,000 minus the count. this is hopefully zero. This would be easier if we have a 32 bit counter that could be reset to zero each second. In the past I think people have built counters like this but now I can buy a $3.80 Arduino that does the counting, ADC and DAC and computer USB interface. So I put up with a harder to use 16-bit nonresetable counter On Wed, Apr 9, 2014 at 6:33 PM, Bob Stewart <[email protected]> wrote: > Have you considered reading the timer only at PPS? You don't need to keep > track of the actual count. You just need to keep track of the difference > between counts at each PPS. Resolution isn't a problem since the difference > in the lower 16 bits is a fixed number for your purpose. IOW, 10,000,000 is > 0x989680. You're only interested in the 0x9680. If there's a difference in > two successive timer counts of 0x9680, then you know you counted 10,000,000, > unless your oscillator is capable of running at one of the other values that > gives 0x9680 as the lower two bytes. > > Bob > > > >>________________________________ >> From: Chris Albertson <[email protected]> >>To: Discussion of precise time and frequency measurement <[email protected]> >>Sent: Wednesday, April 9, 2014 6:35 PM >>Subject: Re: [time-nuts] First success with very simple, very low cost GPSDO, >>under $8 >> >> >>On Wed, Apr 9, 2014 at 1:04 PM, Tom Harris <[email protected]> wrote: >>> Another point with the software is that your handler for the PPS just reads >>> the counter. This gives an offset between the PPS edge and the value read, >>> as your software takes time to respond to the interrupt and read the >>> counter. In your code, it doesn't matter as you only have one interrupt. >> >>Actually there are two interrupts. One is for PPS and the other is >>for overflow of the 16-bit counter. This over flow happens about 76 >>times per seconds. >>> However, if you have another interrupt enabled, this could run after the >>> PPS pulse but before the handler runs, giving you a very rare jitter. >>> A better way would be to use the input capture feature to read the timer >>> into a capture register. Then the interrupt handler has until the next edge >>> to read the capture register. >> >>Do you know how to do this. I don't see any way to capture the timer >>value other then reading it with software. The timer capture register >>is 16 bits and is set atomically after each timer increment but I >>don't see a way to make an external interrupt pin capture a timer. >> >>The two interrupts do bump into each other about roughly every 100 >>seconds but I can detect that. I think I'll just ignore that second. >> >>-- >> >>Chris Albertson >>Redondo Beach, California >>_______________________________________________ >>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. >> >> >> > _______________________________________________ > 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. -- Chris Albertson Redondo Beach, California _______________________________________________ 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.
