Each of the two [[APU|NES APU]] pulse (square) wave channels generate a pulse wave with variable pulse width.
[[APU Sweep|Sweep Unit]] ---> [[APU#Glossary|Timer]]
| |
| |
| v
| [[APU#Glossary|Sequencer]] [[APU Length Counter|Length Counter]]
| | |
| | |
v v v
[[APU Envelope|Envelope]] -------> Gate -----> Gate -------> Gate ---> (to [[#Mixer output|mixer]])
= Registers =
Register [[#Pulse settings ($4000 / $4004, write)|$4000]], [[#Sweep control ($4001 / $4005, write)|$4001]], [[#Timer period lower 8 bits ($4002 / $4006, write)|$4002]] and [[#Length counter load value and timer period upper 3 bits ($4003 / $4007, write)|$4003]] correspond to the first Pulse channel, [[#Pulse settings ($4000 / $4004, write)|$4004]], [[#Sweep control ($4001 / $4005, write)|$4005]], [[#Timer period lower 8 bits ($4002 / $4006, write)|$4006]], [[#Length counter load value and timer period upper 3 bits ($4003 / $4007, write)|$4007]] correspond to the second Pulse channel.
== Pulse settings ($4000 / $4004, write) ==
7 bit 0
---- ----
DDLC VVVV
|||| ||||
|||| ++++- When C is set: channel volume value
|||| When C is clear: [[APU Envelope|envelope]] divider reload value
|||+------ Constant volume flag (override [[APU Envelope|envelope]] with V)
||+------- [[APU Length Counter|Length counter]] halt flag ''and'' [[APU Envelope|envelope]] loop flag
++-------- Pulse width
0 = 12.5%
1 = 25.0%
2 = 50.0%
3 = 75.0%
== Sweep control ($4001 / $4005, write) ==
See [[APU Sweep]].
== Timer period lower 8 bits ($4002 / $4006, write) ==
7 bit 0
---- ----
TTTT TTTT
|||| ||||
++++-++++- Lower 8 bits of timer period value
== Length counter load value and timer period upper 3 bits ($4003 / $4007, write) ==
7 bit 0
---- ----
LLLL LTTT
|||| ||||
|||| |+++- Upper 3 bits of timer period value
++++-+---- [[APU Length Counter|Length counter]] load value
Writing to this register also resets the sequencer index (i.e., the pulse phase) to the first value, restart [[APU Envelope|envelope]].
= Sequencer operation =
The sequencer is clocked by a [[APU#Glossary|timer]] where the period is the 11-bit value (from [[#Timer period lower 8 bits ($4002 / $4006, write)|$4002 / $4006]] and [[#Length counter load value and timer period upper 3 bits ($4003 / $4007, write)|$4003 / $4007]]) ''plus one''. Given "t" as the timer value, this timer is updated every APU cycles (i.e., every second CPU cycles), and counts t, t-1, ..., 0, t, t-1, ..., clocking the waveform generator when it goes ''from 0 to t''.
Since the period of the timer is ''t+1'' APU cycles and the sequencer has 8 steps, the period of the waveform is
''8*(t+1)'' APU cycles, or equivalently ''16*(t+1)'' CPU cycles.
With:
* fCPU = the [[Cycle reference chart#Clock rates|clock rate]] of the CPU
* tval = the value written to the timer high and low registers
* fpulse = the frequency of the wave generated by this channel
Resulting:
* fpulse = fCPU/(16*(tval+1))
* tval = fCPU/(16*fpulse) - 1
'''Note:''' A period of ''t < 8'', either set explicitly or via a sweep period update, '''silences the corresponding pulse channel'''.
'''Duty Cycle Sequences'''
{| class="wikitable"
! Duty || Output waveform
|-
| 0 || 0 1 0 0 0 0 0 0 (12.5%)
|-
| 1 || 0 1 1 0 0 0 0 0 (25%)
|-
| 2 || 0 1 1 1 1 0 0 0 (50%)
|-
| 3 || 1 0 0 1 1 1 1 1 (25% negated)
|}
Notice that a few [[CPU variants|Famiclone]] units have swapped APU duty cycles, works as if the meaning of the two [[#Pulse settings ($4000 / $4004, write)|V bits]] are swapped each other.
'''Implementation details'''
The reason for the odd output from the sequencer is that the counter is initialized to zero but counts ''downward'' rather than upward. Thus it reads the sequence lookup table in the order 0, 7, 6, 5, 4, 3, 2, 1.
{| class="wikitable"
! Duty || Sequence lookup table || Output waveform
|-
| 0 || 0 0 0 0 0 0 0 1 || 0 1 0 0 0 0 0 0 (12.5%)
|-
| 1 || 0 0 0 0 0 0 1 1 || 0 1 1 0 0 0 0 0 (25%)
|-
| 2 || 0 0 0 0 1 1 1 1 || 0 1 1 1 1 0 0 0 (50%)
|-
| 3 || 1 1 1 1 1 1 0 0 || 1 0 0 1 1 1 1 1 (25% negated)
|}
= Mixer output =
The [[APU Mixer|mixer]] receives the pulse channel's current [[APU Envelope|envelope volume]] (lower 4 bits from $4000 or $4004) except when
* the sequencer output is zero, or
* overflow from the [[APU Sweep|sweep]] unit's adder is silencing the channel, or
* the [[APU Length Counter|length counter]] ''is'' zero, or
* the timer has a value less than eight (''t<8'', noted above).
If any of the above are true, then the pulse channel sends zero (silence) to the mixer.
= Differences between Pulse 1 and Pulse 2 =
The behavior of the two pulse channels differs only in the effect of the negate mode of their [[APU Sweep|sweep units]].
= See also =
* [[Pulse Channel frequency chart]]
{{APU nav}}
[[Category:APU]]