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

Pete Stephenson pete at heypete.com
Wed Jun 29 05:08:52 EDT 2016


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.

> 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


More information about the time-nuts mailing list