David Banks edited this page Mar 2, 2017 · 38 revisions

Music 5000 FPGA Notes

This page is a write-up of the notes I made when trying to understand the operation of the original Music 5000 hardware, with a view to re-implementing a compatible version of the design in a modern FPGA.

Wave RAM

The registers in the Music 5000 hardware are implemented as a 2048 byte block of memory, called the Wave RAM. All functionality of the Music 5000 is controlled by writing to locations in the Wave RAM.

The Wave RAM serves two purposes:

  1. It stores the Wave Definitions for 14 distinct waveforms. Each waveform is represented as 128 8-bit logarithmic samples (logarithmic because the Music 5000 uses a Companding DAC).

  2. It stores the Channel Registers for each of the 16 channels. Each channel has two sets of registers, normal and alternative, each comprising six registers (frequency lo, frequency mid, frequency hi, amplitude, waveform and control).

The reason for the two sets of registers is to support modulation of any controllable parameter, inc. frequency, amplitude, phase (for synchronisation) etc. For example, it is possible to program different characteristics in each set in one channel (e.g. different frequencies), and then use the channel two positions earlier in the table of sixteen channels to switch between them at audio frequency.

Register Addressing

The Wave RAM interfaces to the BBC using the 1MHz Bus and appears as eight 256 byte pages of memory that can be individually paged in to &FD00-&FDFF.

The Wave RAM is "addressed" by writing the value "0011BBBx" to the paging register at &FCFF.

Bit Description
Bit 7-4 Write gate - must be 0011 for the Wave RAM to be paged in
Bit 3-1 Selects one of eight pages of the Wave RAM
Bit 0 Unused

If the top nibble is not "0011", writes to &FDxx will be ignored. This allows multiple Hybrid devices (e.g. the Music 3000 Expander) to be connected in parallel.

In the original hardware, addresses &FD00-&FDFF are write only. In this FPGA version, they can also be read back, because the FPGA uses a true dual-port RAM.

Wave RAM Memory Map Summary

Bank &FCFF &FDxx Address Function
0 &30 &00-&7F Wave 0 Definition
0 &30 &80-&FF Wave 1 Definition
1 &32 &00-&7F Wave 2 Definition
1 &32 &80-&FF Wave 3 Definition
2 &34 &00-&7F Wave 4 Definition
2 &34 &80-&FF Wave 5 Definition
3 &36 &00-&7F Wave 6 Definition
3 &36 &80-&FF Wave 7 Definition
4 &38 &00-&7F Wave 8 Definition
4 &38 &80-&FF Wave 9 Definition
5 &3A &00-&7F Wave 10 Definition
5 &3A &80-&FF Wave 11 Definition
6 &3C &00-&7F Wave 12 Definition
6 &3C &80-&FF Wave 13 Definition
7 &3E &00-&0F Channel 0-15 Frequency Lo Registers
7 &3E &10-&1F Channel 0-15 Frequency Mid Registers
7 &3E &20-&2F Channel 0-15 Frequency Hi Registers
7 &3E &30-&4F Unused
7 &3E &50-&5F Channel 0-15 Waveform Registers
7 &3E &60-&6F Channel 0-15 Amplitude Registers
7 &3E &70-&7F Channel 0-15 Control Registers
7 &3E &80-&8F Channel 0-15 Frequency Lo Registers (Alt)
7 &3E &90-&9F Channel 0-15 Frequency Mid Registers (Alt)
7 &3E &A0-&AF Channel 0-15 Frequency Hi Registers (Alt)
7 &3E &B0-&CF Unused
7 &3E &D0-&DF Channel 0-15 Waveform Registers (Alt)
7 &3E &E0-&EF Channel 0-15 Amplitude Registers (Alt)
7 &3E &F0-&FF Channel 0-15 Control Registers (Alt)

Wave Definitions

The format of each Wave Definition is 128 consecutive 8-bit samples.

Bit Description
Bit 7 Sign bit (0 for positive, 1 for negative)
Bit 6-0 Wave value

The Music 5000 uses an AM6070 companding DAC. This means that the values stored in the Wave Definition need to be carefully encoded to match the transfer characteristic of the DAC.

This uses the Bell System u-225 logarithmic law which can be written as:

  • Y = 0.18 ln (1 + u |X|) sgn(X) where:
  • X = the encoder input (normalized to the range -1.0 to +1.0)
  • Y = the encoder output (normalized to the range -1.0 to +1.0)
  • u = 255

To calculate the 7-bit values to write into the Music 5000 wave table, use:

  • Y = 22.903 ln (1 + 255 |X|) where:
  • X = the waveform input (normalized to the range -1.0 to +1.0, e.g. a sine wave)
  • e.g. when X=0.0, Y=0
  • e.g. when X=1.0, Y=127

This value goes in bits 6 to 0 of the sample, and bit 7 is the sign bit (i.e. sign-and-mangnitude representation, not two's compliment).

Standard Wave Definitions

These are some example Wave Definitions used by AMPLE:

A program to display these wave definitions is shown below:

 10  FOR A=0 TO 13
 20  MODE 4
 30  PRINT '"WAVEFORM ";A
 40  ?&FCFF=A
 50  B=128*(A MOD 2)
 60  MOVE 0,512
 70  PLOT 21,1270,512
 80  FOR X=0 TO 127
 90  Y=?(&FD00+B+X)
100  S=-8
110  IF Y>127 THEN S=-S:Y=Y-128
120  Y=512+S*EXP(Y/32)
130  IF X=0 MOVE X*10,Y
140  IF X<>0 DRAW X*10,Y
150  NEXT
160  N$=STR$(A)
170  IF A<10 N$="0"+N$
180  OSCLI("SAVE WAVE"+N$+" 5800 +2800")
190  NEXT

Channel Registers

The registers for a channel are organized as follows:

Register Offset Name
&00 Frequency Lo
&10 Frequency Med
&20 Frequency Hi
&30 unused - wave access timeslot
&40 unused - process access timeslot
&50 Waveform
&60 Amplitude
&70 Control

Frequency Register

  • Lo byte: Register Address: Channel Base + &00
Bit Description
Bits 7-1 Bits 7-1 of 24-bit Frequency
Bit 0 Channel Disable
  • Mid Byte: Register Address: Channel Base + &10
Bit Description
Bits 7-0 Bits 15-8 of 24-bit Frequency
  • Hi Byte: Register Address: Channel Base + &20
Bit Description
Bits 7-0 Bits 23-16 of 24-bit Frequency

These three 8-bit registers combine to give a 24-bit frequency register.

The Music 5000 runs off a 6MHz clock and takes 128 clock cycles to update all channels. This means each channel is updated at 46.875KHz. Every time the channel is updated, the 24-bit frequency value is added to a phase accumulator. The top 7 bits of the phase accumulate (which look like a ramp) are then used as in index into the 128-byte Wave Definition.

Here's an example.

Assume the Wave Definition contains a single cycle of a sine wave, and you want to generate a 1.0 KHz tone.

The frequency register needs to be set to:

  • 2^24 * 1.0 / 48.875
  • = 343267
  • = &053CE3

So:

  • Frequency Lo = &E2
  • Frequency Mid = &3C
  • Frequency Hi = &05

Bit 0 of Frequency Lo must be zero, or the channel is disabled.

Unused Register

  • Register Address: Channel Base + &30
Bit Description
Bits 7-0 Unused

The register is unused because at this time the Wave RAM is performing waveform lookup cycle.

Unused Register

  • Register Address: Channel Base + &40
Bit Description
Bits 7-0 Unused

The register is unused because at this time the Wave RAM is performing processor access cycle.

Waveform Register

  • Register Address: Channel Base + &50
Bit Description
Bits 7-4 Waveform Number
Bits 3-0 Unused

Amplitude Register

  • Register Address: Channel Base + &60
Bit Description
Bits 7-0 Log Amplitude for the Channel

The minimum amplitude is &00.

The maximum amplitude is &80.

Values below &40 are inaudible.

Values above &80 seem to cause distortion.

Control Register

  • Register Address: Channel Base + &70
Bit Description
Bits 7-6 Unused
Bit 5 Modulate Adjacent Channel
Bit 4 Invert Waveform
Bits 3-0 Stereo Position

The stereo position allows 3-bit stereo position control (7 possible positions) as follows:

Value Left Right
1000 0% 100%
1001 0% 100%
1010 0% 100%
1011 17% 83%
1100 33% 66%
1101 50% 50%
1110 67% 33%
1111 83% 17%
0000 100% 0%
0001 100% 0%
0010 100% 0%
0011 100% 0%
0100 100% 0%
0101 100% 0%
0110 100% 0%
0111 100% 0%

Typically you will see &D (1101) used, which centres the channel

Default Channel Register Values

The below table illustrates the initial values of the channel registers when AMPLE has initialized.

    00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00: BE BE BE BE BE BE BE BE BE BE BE BE BE BE BE BE    (Freq Lo)
10: 6D 6D 6D 6D 6D 6D 6D 6D 6D 6D 6D 6D 6D 6D 6D 6D    (Freq Mid)
20: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01    (Freq Hi)
30:                                                    (Unused)
40:                                                    (Unused)
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    (Waveform)
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    (Amplitude)
70: 2D 0D 2D 0D 2D 0D 2D 0D 2D 0D 2D 0D 2D 0D 2D 0D    (Control)

80:    BE    BE    BE    BE    BE    BE    BE    BE    (Freq Lo)
90:    6D    6D    6D    6D    6D    6D    6D    6D    (Freq Mid)
A0:    01    01    01    01    01    01    01    01    (Freq Hi)
B0:                                                    (Unused)
C0:                                                    (Unused)
D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    (Waveform)
E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    (Amplitude)
F0: 2D 0D 2D 0D 2D 0D 2D 0D 2D 0D 2D 0D 2D 0D 2D 0D    (Control)

The blank entries indicate locations that appear not be be written by the AMPLE initialization code.

The initial frequency value of &16DBE (93630) corresponds to a frequency of:

  • (6MHz / 128) / (2^24 / 93630)
  • = 261.5992 Hz

Middle C happens to be 261.625565 Hz (which would correspond to 93639). I'm not sure why the numbers don't quite match up.

A program to generate this table is shown below:

10  MODE 0:@%=3
20  ?&FCFF=&3E
30  FOR A=0 TO 15
40  PRINT~A;
50  FOR B=0 TO 15
60  PRINT~?(&FD00+A*16+B);
70  NEXT
80  PRINT
90  NEXT

Example of using Frequency Modulation

In this example we will configure channel 0 to cause channel 1 to modulate between two different frequencies.

First, load some Wave Definitions by running AMPLE and playing some music (e.g. concert) then hit break followed by control break to get back to BASIC.

Next, set channel 0 to a very low frequency (a couple of Hz):

?&FD00=&00
?&FD10=&05
?&FD20=&00
?&FD50=&00 ;; Waveform 0 is a square wave
?&FD60=&00 ;; Min amplitude
?&FD70=&2D ;; Set bit 5 to modulate adjacent channel

Next, set channel 1 "normal" registers to (approx middle C):

?&FD01=&BE
?&FD11=&6D
?&FD21=&01
?&FD51=&C0 ;; Waveform 12 is a sin wave
?&FD61=&70 ;; Normal volume
?&FD71=&0D ;; Clear bit 5 not modulate adjacent channel

Finally, set channel 1 "alternative" registers to a higher frequency:

?&FD81=&BE
?&FD91=&6D
?&FDA1=&02
?&FDD1=&C0 ;; Waveform 12 is a sin wave
?&FDE1=&70 ;; Normal volume
?&FDF1=&0D ;; Clear bit 5 not modulate adjacent channel

You should now hear a sound like a old two-tone police car siren.

The modulation frequency can be adjusted by writing different values to ?&FD10.

References

The original Music 5000 schematic.

A description of How Music 5000 Works from ETI (Electronics Today International).

The datasheet for the AM6070 Companding DAC.

Acknowledgements

Chris Jordan, the original hardware designer, for a very clever design and for being supportive of my efforts to reverse engineer it.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.