Page 1 of 1

Pulse (Square) Generation

Posted: Sun Jul 17, 2011 3:41 am
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

Re: Pulse (Square) Generation

Posted: Sun Jul 17, 2011 7:43 am
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.

Re: Pulse (Square) Generation

Posted: Sun Jul 17, 2011 8:17 pm
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.

Re: Pulse (Square) Generation

Posted: Mon Jul 18, 2011 4:21 pm
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.

Posted: Mon Jul 18, 2011 4:30 pm
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.