22.09.2015 Views

of Microprocessors

Musical-Applications-of-Microprocessors-2ed-Chamberlin-H-1987

Musical-Applications-of-Microprocessors-2ed-Chamberlin-H-1987

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

DIGITAL TONE GENERATION TECHNIQUES 419<br />

LOOP CLC<br />

CLEAR CARRY FLAG<br />

2<br />

ADC<br />

STA<br />

NOP<br />

NOP<br />

NOP<br />

NOP<br />

B<br />

DAC<br />

ADD B TO ACCUMULATOR<br />

WRITE ACCUMULATOR TO DAC<br />

WAIT 16 CLOCKS FOR A<br />

TOTAL LOOP TIME OF<br />

25 f.LSEC WHICH GIVES<br />

A 40-ks/s SAMPLE RATE<br />

NOP<br />

JMP<br />

JMP<br />

*+3<br />

LOOP REPEAT<br />

Assuming that the A register was initially 0 and that B contains 1, the<br />

sequence <strong>of</strong> numbers that would be sent to the DAC would be 1, 2, 3,<br />

4, ... 125, 126, 127. Now, assuming twos-complement arithmetic, the next<br />

addition would try to produce 128, which, <strong>of</strong> course, overflows the 6502's 8­<br />

bit accumulator, producing instead a result <strong>of</strong> -128. The sequence would<br />

continue -127, -126, ... , - 2, -1, 0, 1, etc., and a full sawtooth cycle<br />

has been completed. The overflow from + 127 to - 128 is simply the<br />

sawtooth flyback.<br />

In a typical 6502, this loop would execute in 25 f.Lsec, giving a sample<br />

rate <strong>of</strong> 40 ks/s. Since 256 times around the loop are required for a single<br />

sawtooth cycle, the sawtooth frequency will be 40 ks/s/256 = 156.25 Hz,<br />

essentially D-sharp below middle C. Now, what if B has the value 2 in it?<br />

Register A, starting at zero would be 0, 2, 4, ... , 124, 126, -128,<br />

-126, ... , - 2, 0, 2, etc. It would take only 128 iterations for a complete<br />

cycle, so the tone frequency would be 312.5 Hz, precisely twice what it was.<br />

Other frequencies can be had by setting B to other values. Thus, continuing<br />

the analog sawtooth analogy, the content <strong>of</strong> B represents the current into the<br />

integrator, although it will be called the increment in the discussion to follow.<br />

Improving Frequency Resolution<br />

Obviously, only a very limited number <strong>of</strong> frequencies is available with<br />

this basic loop. Another way to change the sawtooth frequency is to change<br />

the loop time and thus the sample rate, perhaps by changing the number <strong>of</strong><br />

NOP instructions. However, this would violate the holy dogma <strong>of</strong> direct<br />

computer synthesis, which decrees that the sample rate shall remain constant<br />

throughout the system.<br />

Actually, the numbers in the accumulator and B should be considered<br />

as /ractions between - 1 and + 1. Thus, the accumulator starts at 0,<br />

increments in units <strong>of</strong> 1/128 to 127/128, overflows to -128/128, continues to<br />

0, and repeats. B can hold values <strong>of</strong> 1/128, 2/128, 3/128, etc. The sawtooth<br />

ftequency is given by F = 40,000[/2, where I is the ftaction stored in B, the<br />

40,000 is the sample rate, and the 2 is because the sawtooth traverses a range<br />

<strong>of</strong> 2 units; from - 1 to + 1. In order to get finer frequency resolution, it is<br />

simply necessary to specify the increment with more ptecision.<br />

3<br />

4<br />

2<br />

2<br />

2<br />

2<br />

2<br />

3<br />

-.2<br />

25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!