Sound Generator for the ZX81

Author(s): Dave Goodman
Publication: LISTing Newsletter
Date: February 1997
Pages: 3-4
  • 3 Programmable Tone Generators
  • Noise Generator with 3 Pitch Levels
  • Separate Attenuators for Noise and Tone Generators
  • Entry from PEEK and POKE in BASIC
  • Connects Directly into the Expansion Port Socket (or into the motherboard)
  • Single Address Access
Sound generator board
Sound generator board

This sound generator is a worthy addition to our ZX81 hardware projects. Almost infinite possibilities for sound and noise effects that can be added to your own programs for greater realism.

Circuit Description

ICs 1, 2, and 3 are connected to the computer address lines A1 to A15. This means that all addresses up to 65534 may be presented, so a decoder is required to examine all lines, but only to respond to a particular address. The address code used here is 16370, which lies between the 16360 and 16380 used in our I/O port project. A0 is not used, so a further address of 16371 exists.

A negative going address decode pulse appears at the output of IC2, and is used to latch data into IC4 and enable IC6. To avoid corruption of data into IC6 the output of IC4 must be latched to the data code before IC6 is enabled.

Buffers IC5a and b delay the enable pulse just enough to allow IC4 to latch before enabling IC6. IC6 pin 4 READY line controls the duration of the WRITE ENABLE (pin 5) and CHIP ENABLE pulse for correct circuit operation, via IC5c. R1 and C1 smoothe the +5V supply, to keep noise spikes down to a minimum, and audio output is taken from IC6 pin 7, via low pass filter R3 and C2, to the output pins 1 and 2. IC5d buffers the 3.22MHz clock, and prevents lengthy track runs from crashing the ZX81.

Most important is D1. You may be aware that because of incomplete address decoding, the ZX81 ROM is repeated between address 8193 and 16383, which is an unused area between ROM and system variables. These addresses can be POKEd providing that the ROM is deselected at that time, and D1 conducts when A13 is high, freeing this area for use.

Figure 1: Circuit diagram
Figure 1: Circuit diagram

Assembly and Construction

Insert all track pins and both vero pins. Fit all six DIL sockets, R1, 2, and 3 and C2. Fit disc ceramics C3 to C7 and C1 and C8 noting the polarity markings. Insert all ICs the correct way round, then clean the PCB and make the final inspection for short circuits and dry joints.

Testing and Use

If you do not possess a mother board you will require a 2 x 23 way socket to solder onto the PCB edge connector, otherwise plug into your motherboard. The signal is insufficient to drive a loudspeaker direct, as it is only 300mV in amplitude, so you will need an external amplifier and speaker connected to pins 1 (signal) and 2 (screen). Switch on the ZX81 and a cacophony of noise should be heard. Run the following test program:-

10 REM TEST PROGRAM
15 LET A = 16370
20 INPUT B
25 POKE A, B
30 GOTO 10

Press RUN then NEWLINE and input the following codes followed by NEWLINE after each code: 159 191 223 255 (you should hear the tones disappearing one by one until all the signals are off) 144 128 64. A low frequency tone of approximately 98Hz (G2) should be heard. Any number between 1 and 64 may now be entered and the appropriate tone should be audible. Refer to the following listing for access codes and settings.

TONE           ACCESS  FREQUENCY          ATTENUATION
GENERATOR      CODE    RANGE              CODE
1              128     64(G2) to 1(G8)    144 to 159 (OFF)
2              160     64(G2) to 1(G8)    176 to 191 (OFF)
3              192     64(G2) to 1(G8)    208 to 223 (OFF)
White Noise    228     High pitch         240 to 255 (OFF)
White Noise    229     Med. pitch         240 to 255 (OFF)
White Noise    230     Low pitch          240 to 255 (OFF)
Pulse (spike)  224     480Hz              240 to 255 (OFF)
Pulse (spike)  225     240Hz              240 to 255 (OFF)
Pulse (spike)  226     120Hz              240 to 255 (OFF)

To input data into tone generator 1 only, first enter the required volume level from the attenuation codes. The first code given is maximum volume, e.g. Tone generator 1 = 144 and attenuation levels are in 15 x 2dB steps down to 159, which is fully off. Next enter the tone generator access code, which in this example is 128, followed by the required frequency. The frequency range covers 98Hz (G2) up to 6.3kHz (G8) in 64 steps, code 1 being the highest frequency and code 64 being the lowest, so enter 64. The entered codes are now 144, 128, 64, which is tone generator 1 producing an output of 98Hz at full volume. As a Tone Generator access code was entered after the attenuator, the frequency can be changed as desired, but if an attenuator code is now entered, 144 to 159 in this example, the frequency can only be altered by entering the access code, 128, again, and then a frequency code.

Keep in mind that when a register is accessed it will remain ‘on line’ awaiting further update input codes. Access to Tone Generators 2 and 3 is in the same manner, except that the codes are different. If you enter 144, 128; and 64 to set up a tone in Generator 1, then enter 176, 160 and 32. Two tones will now be heard, with Generator 2 an octave above Generator 1. Entering a frequency code will now only alter Generator 2.

Sound generator plugged into the ZX81 expansion port
Sound generator plugged into the ZX81 expansion port
Figure 2: Overlay and artwork
Figure 2: Overlay and artwork

Pulse and noise effects require attenuation codes and an access code only. Once the attenuation level has been set noise and pulse codes are entered and are immediately audible.

Tone Generator 3 can be used to control either noise or pulse registers and code 231 followed by 192 allows control of white noise pitch by entering 1 to 64. Similarly, code 227 followed by 192 allows control of a 480Hz pulse tone by entering 1 to 64, and the lowest frequency possible is 6Hz.

Obviously, the best way to understand the system is to use it, therefore a few simple programs are given for assistance, shown at the end of this article. When writing music programs remember that G2 to G8 spans 73 notes and control only covers 64 notes, therefore higher frequency notes tend to become sharper in relation to the lower octaves.

Run these programs in SLOW mode:-

10 REM ZMD878DMZMD878DM182.*.28ZMD878DMSMIEDFJMZMD878DM
15 LET A = 16370
20 LET B = 16514
25 FOR J = 1 TO 48
30 FOR I = 1 TO 15
35 NEXT I
40 POKE A, (PEEK B)
45 LET B = B+1
50 NEXT J
55 GOTO 10

Press break to stop sequence.

10 REM GUN SHOT
15 LET A = 16370
20 POKE A, 159
25 POKE A, 191
30 POKE A, 223
35 POKE A, 240
40 POKE A, 23
45 FOR J = 240 TO 255
50 POKE A, J
55 NEXT J
60 INPUT E$
65 GOTO 10

After RUN press NEWLINE to fire.

10 REM PHOTON BLAST
15 LET A = 16370
20 POKE A, 159
25 POKE A, 191
30 POKE A, 223
35 POKE A, 148
40 POKE A, 240
45 POKE A, 231
50 POKE A, 192
55 FOR J = TO 30 STEP 2
60 POKE A, J
65 POKE A, 128
70 POKE A, J
75 POKE A, 192
80 NEXT J
85 POKE A, 159
90 POKE A, 228
95 POKE A, 247
100 INPUT C$
110 GOTO 10

Press NEWLINE to fire. To remove background hiss, delete line 90 and change line 95 to POKE A, 255.

ZX81 SOUND GENERATOR
PARTS LIST

Resistors: All 0.4W 1% Metal Film

R1          2k7                                    (M2K7)
R2          2R2                                    (M2R2)
R3          1k                                     (M1K)

Capacitors
C1          220uF 10V axial electrolytic           (FB60Q)
C2          1nF ceramic                            (WX68Y)
C3-7,inc.   100nF minidisc                         (YR75S)
C8          1uF35V tantalum              5 off     (WW60Q)

Semiconductors
D1          1N4148                                 (QL80B)
IC1,2       74LS30                                 (YF20W)
IC3         74LS02                       2 off     (YF02C)
IC4         74LS373                                (YH15R)
IC5         74LS08                                 (YF06G)
IC6         76489AN                                (YH33L

Miscellaneous
            14 pin dil skt               4 off     (BL18U)
            16 pin dil skt                         (BL19V)
            20 pin dil skt                         (HQ77J)
            Veropin 2141                           (FL21X)
            Track pin                    1 pkt     (FL82D)
            ZX81 Sound Gen. PCB                    (GB11M)

A complete kit of parts is available for this project.
Order As LW96E (Sound Gen. Kit). Price £10.95.

For constructors who may wish to use the Sound Generator in addition to other external hardware, a
mother board is available, called the ZX81 Extendi board (GB0[illegible]J) and will accept the Sinclair 16k RAM
pack and up to 3 plug-in modules. In addition to the PCB you will require 4 PC Edge Connectors (RK3[illegible]Q)
ZX81 SOUND GENERATOR PARTS LIST (Maplin order codes; kit LW96E)
ZX81 SOUND GENERATOR PARTS LIST (Maplin order codes; kit LW96E)

Transcription note: The quantities stand on the rows where they print. Two seem to sit a row low.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.