[time-nuts] How to properly characterize 32kHz oscillators manually and with a microcontroller?

Bob Camp kb8tq at n1k.org
Wed Jun 29 11:04:44 UTC 2016


Hi

> On Jun 29, 2016, at 5:08 AM, Pete Stephenson <pete at heypete.com> wrote:
> 
> On Tue, Jun 28, 2016 at 12:14 AM, Van Horn, David
> <david.vanhorn at backcountryaccess.com> wrote:
>> 
>> 
>> pete at heypete.com said:
>>> I'm a little concerned about the speed at which the pulses need to be
>>> counted. The 32kHz pulses come in every ~30.5 microseconds, and handling an
>>> interrupt on an ATmega328 running at 16MHz takes about 5.125 microseconds[1]
>> 
>> Huh?
>> 
>> Instruction cycle time is 62.5nS for almost all instructions at that clock.
>> That’s a pretty long ISR by my standards.
> 
> According to the "How long does it take to execute an ISR?" part of
> http://www.gammon.com.au/interrupts, it takes 82 cycles total to
> service an external interrupt (i.e. one triggered by an interrupt
> pin), including the time needed to enter the ISR and to leave it after
> it's done whatever you needed it to do. At 62.5nS for each clock
> cycle, that's 5.125uS just to process the interrupt. That doesn't
> include the time needed to execute whatever code you want it to do.

That all assumes you have turned interrupts off for some reason. Common 
reasons  could be that you are in another interrupt service routine or that
you are executing interrupt related code. 

Bob


> 
>> 1: Reserve a couple of registers for handling data inside ISRs, avoiding push and pop.
>> 2: Reserve a register for holding SREG during the ISR.
>> 
>> ISR:    in STEMP,SREG
>>        At this point you can fearlessly trash SREG and ITEMP and ITEMP2
>>        Do Stuff using ITEMP and ITEMP2.
>>        Do as little as practical in the ISR, letting the non-isr code do the heavy lifting.
>>        Out SREG,STEMP
>>        RETI
>> 
>> Optionally, set a register (I usually call it "ZERO") to 0x00 to speed up 16 bit operations.
>> Keep data you need FAST in registers in the low page, rather than in RAM.
> 
> Thanks! I think that may be a bit beyond my ken for the time being,
> but I'll definitely keep it in mind for when I know more.
> 
> Cheers!
> -Pete
> 
> -- 
> Pete Stephenson
> _______________________________________________
> 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_lists.febo.com mailing list