Pulse (Square) Generation

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
Overload
Posts: 47
Joined: Mon May 30, 2011 4:38 pm
Location: Australia
Contact:

Pulse (Square) Generation

Post by Overload »

Just trying to understand how the NES pulse generator works.

Does the NES APU actually have two square wave generators in hardware or just one handling two channels on opposing clock cycles?

The reason I ask is because in documentation and source I have found the timer period is multiplied by two whereas to me it would make more sense to just have one and output on opposing clock cycles therefore eliminating the need to multiply by 2.

for example:
cycle 0: Square 0
cycle 1: Square 1
cycle 2: Square 0
cycle 3: Square 1
User avatar
cpow
NESICIDE developer
Posts: 1097
Joined: Mon Oct 13, 2008 7:55 pm
Location: Minneapolis, MN
Contact:

Re: Pulse (Square) Generation

Post by cpow »

Overload wrote: Does the NES APU actually have two square wave generators in hardware or just one handling two channels on opposing clock cycles?
Well it has to have at least two period counter registers because obviously the two channels can be at two different frequencies at the same time. Given that really all you need is a period counter and a clock to generate a square wave, I'd say that's pretty much evidence that it has two independent square wave generators. The divide-by-two is probably cheaper in chip real-estate than would be having a 16-step sequence to accomplish the same thing that a /2 and an 8-step sequence does.

To me the most interesting part is the difference in the two channels' sweep generators.
User avatar
Memblers
Site Admin
Posts: 3901
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Pulse (Square) Generation

Post by Memblers »

cpow wrote: To me the most interesting part is the difference in the two channels' sweep generators.
Yeah, the only place I can think of that being really noticable was in The Guardian Legend, with the 'alarm' sound effect it makes before you fight a boss. It sounded all wrong before that was emulated.

I don't know that details of the hardware exactly, but my observation is that seems like they aren't clocked at exactly the same time because you can't do something like use the same freqs in both channels in a way that would make them cancel each-other out. You can get different types of phasing (and a thin almost-cancelled one), but never silence. Not sure if that helps with the question though.
Overload
Posts: 47
Joined: Mon May 30, 2011 4:38 pm
Location: Australia
Contact:

Re: Pulse (Square) Generation

Post by Overload »

Memblers wrote: I don't know that details of the hardware exactly, but my observation is that seems like they aren't clocked at exactly the same time because you can't do something like use the same freqs in both channels in a way that would make them cancel each-other out. You can get different types of phasing (and a thin almost-cancelled one), but never silence. Not sure if that helps with the question though.
That is handy to know.

I figure the NES APU incorporates a 4 channel mixer, cycling square 0 on even cycles and square 1 on odd cycles.
User avatar
Dwedit
Posts: 4470
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit »

I don't think there's any evidence that it swaps channels every cycle, otherwise someone could have noticed that in a high-speed recording.

As for the sweep thing, Square Channel 1 adds 1 to the period when sweeping higher (decreasing period), and square channel #2 does not. That creates the phaser effects.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
Post Reply