This is an email posted to nesdev by Ki a while back.  I have removed one
line at the end regarding the B flag of the cpu(the information was 
incorrect, which Ki noted in a later email).

--------------------------------------------------------------------------------

 By reading Brad's NESSOUND document, we know that there is a
"frame counter" in the NES/FC APU.  I would like to post
some more on this.

  The frame counter is reset upon any write to $4017.  It is
reset at system power-on as well, but is NOT reset upon
system reset.

  Thanks to Samus Aran, we now know the exact period of the
PPU's single frame.  In another words, we are now sure that
the NMI occurs on every 29780 2/3 CPU cycles.

  However, the APU's single frame is NOT 29780 2/3 CPU cycles.
What I mean by "APU's single frame" here is that it is the
number of CPU cycles taken between the frame IRQs.

  The APU's single frame seems to be:

    1789772.727... / 60 = 29829 6/11  [CPU CYCLE]

  Below is a simple diagram which shows the difference
in periods of the PPU's single frame and the APU's.


    RESET         29780 2/3 CPU CYCLES          NMI
PPU   |------------------------------------------|
      |           29829 6/11 CPU CYCLES          IRQ
APU   |----------|----------|----------|----------|


  Note that if you write $00 to $4017 on every NMI, the frame
IRQ would NEVER go off even if it is enabled.  This is because
the the period of NMI is slightly shorter than the period of
the frame IRQ.  This causes the frame counter to be reset
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             