It is currently Sat Oct 21, 2017 5:19 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: CPU and PPU clock math
PostPosted: Sun Apr 26, 2015 6:28 pm 
Offline

Joined: Sun Apr 05, 2015 7:16 am
Posts: 4
I've read[1] that the NES PPU (NTSC/2C02) is 3 times the speed of the NES CPU.

According to the wiki:

The NES CPU operates at a speed of 21.477272 MHz / 12 = 1789773Hz.
The NES PPU operates at a speed of 21.477272 MHz / 4 = 5369318Hz.

If we take the CPU speed and run the "3 times slower than the PPU" rule:

1789773 * 3 = 5369319hz.

This is 1hz behind the actual PPU speed since 5369319hz != 5369318Hz.

Could this be a big issue if emulator logic is expecting that the PPU clock is 1789773Hz * 3, vs trying to emulate the actual clock rate of 5369319?

[1] http://wiki.nesdev.com/w/index.php/Clock_rate


Top
 Profile  
 
PostPosted: Sun Apr 26, 2015 7:04 pm 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2963
Location: Tampere, Finland
All of those numbers are rounded, so there's no 1 Hz difference in reality. 3 PPU clocks is always equivalent to 1 CPU clock because both clocks are based on the same master clock. Also note that the real clock frequency is never exactly what is advertised, for example on the 21.47 MHz clock you can see a +-40 Hz tolerance in the page you linked.

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


Top
 Profile  
 
PostPosted: Sun Apr 26, 2015 8:09 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19113
Location: NE Indiana, USA (NTSC)
Thefox is right about rounding. If you don't want rounding, you'll need to stay in the rational number domain and multiply everything as fractions.

  • The NTSC audio subcarrier over RF is defined as 9/2 MHz.
  • The NTSC horizontal scan frequency* is defined as 1/286 of the audio subcarrier, or 9/572 MHz.
  • The NTSC color subcarrier is defined as 455/2 times the horizontal scan frequency, or 315/88 MHz. This frequency is often called "color burst" or "3.58" after its rounded value.
  • The exact value for the dot clock rate on NTSC and RGB PPUs is three-halves of color burst, or 945/176 MHz.
  • The exact value for the CPU clock rate is one-third of the PPU dot clock, or one-half of color burst, or 315/176 MHz.


* This is the standard rate for 480i television. Prior to the Dreamcast, 480i was highly uncommon on video game consoles, and their picture generators applied various forms of cheating. Horizontal scan on NES and Super NES is slightly faster than this. Horizontal scan on many other 240p consoles is slightly slower. But it still works because it's within tolerances of actual TV sets.


Top
 Profile  
 
PostPosted: Sun Apr 26, 2015 8:46 pm 
Offline

Joined: Sun Apr 05, 2015 7:16 am
Posts: 4
thefox wrote:
Also note that the real clock frequency is never exactly what is advertised, for example on the 21.47 MHz clock you can see a +-40 Hz tolerance in the page you linked.


If theres a +- 40Hz tolerance, then why is it important to care about being 1 PPU cycle short when its an odd frame. Wouldn't it not matter if the tolerance range is that big?


Top
 Profile  
 
PostPosted: Sun Apr 26, 2015 9:09 pm 
Offline

Joined: Mon Apr 01, 2013 11:17 pm
Posts: 437
RobertLoggia wrote:
Wouldn't it not matter if the tolerance range is that big?
It would be fine if they used separate clock sources. For example, the SNES CPU and APU use different clock sources, which means the CPU and APU must communicate with each other periodically if they need to remain synchronized.

However, the NES CPU and PPU are both driven by the same crystal resonator. They are always exactly in sync. You could write code for the NES that synchronizes itself against the PPU once, and then runs forever without ever needing to synchronize itself again. I'm not aware of any games that specifically rely on the one-cycle odd/even difference, but there are a few that will break if your timing is too far off.


Top
 Profile  
 
PostPosted: Sun Apr 26, 2015 9:15 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19113
Location: NE Indiana, USA (NTSC)
RobertLoggia wrote:
If theres a +- 40Hz tolerance, then why is it important to care about being 1 PPU cycle short when its an odd frame. Wouldn't it not matter if the tolerance range is that big?

To put it another way: There's a 40 Hz tolerance in the absolute rate of a particular clock source. There's no tolerance in the relative rate between two clocks derived from the same source.


Top
 Profile  
 
PostPosted: Tue Apr 28, 2015 10:51 pm 
Offline
User avatar

Joined: Sun May 27, 2012 8:43 pm
Posts: 1306
tepples wrote:
RobertLoggia wrote:
If theres a +- 40Hz tolerance, then why is it important to care about being 1 PPU cycle short when its an odd frame. Wouldn't it not matter if the tolerance range is that big?

To put it another way: There's a 40 Hz tolerance in the absolute rate of a particular clock source. There's no tolerance in the relative rate between two clocks derived from the same source.

To put it another another way: The minute difference in frequency will be proportionately reflected in all further divisions of the frequency. The PPU and CPU clock will maintain their clock ratio.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group