gbdso gameboy digital sampling oscilloscope (1)
TRANSCRIPT
TEST& MEASUREMENT
34 Elektor Electronics 10/2000
GBDSOGameboy Digital Sampling Oscilloscope (1)
Convert a Nintendo games console into a portable oscilloscope
By Steve Willis
The application of dedicatedgames consoles to more variedfunctions other than justplaying games is fraught withdifficulties. Not only do theconsoles contain highlyintegrated and custom-madecomponents, there will oftenbe no publicly availabledevelopment tools orapplications manuals. Howeverthe Nintendo Gameboy© isone such system which hasreceived considerableattention from the hobbydesigner and enjoys a largeselection of both technical andsoftware support through anetwork of websites.
entire screen of data is captured before it isdisplayed (standard mode). The number ofsamples captured per scan may be set toeither 240 or 600 points per channel, allowingthe visible screen window to be moved rela-tive to the initial trigger. Sampling of the twoinput channels occurs simultaneously, exceptfor the 10 and 5 µS/DIV ranges, when thechannels are sampled on alternate traces rel-ative to the trigger (alternate mode). CHAmay also be saved as an on-screen reference,thus allowing a total of three traces to be dis-played at once.
Gateway: the ROM cartridge interfaceAll the signals required for the oscilloscopeare available on the external ROM cartridgeslot, so no modifications need be made to theGB console itself.
The oscilloscope cartridge plugs into acustom 32-pin card edge connector on theunderside of the GB and interfaces directly to
The attraction of using a mass pro-duced console soon becomes clearwhen the time and cost involved inproducing a general purpose portableinstrument with processor, LCD dis-play and user interface, not to men-tion the moulded case, sound systemand serial port, are considered.
The Gameboy OscilloscopeThe GameBoy ‘GB’ digital samplingoscilloscope ‘GBDSO’ converts aGBpocket or GBcolour into a multi-purpose test instrument whichshould prove invaluable to the hobbydesigner. Design of GBDSO posedmany contrasting requirements: highspeed, low power, low cost, smallsize and versatility. In order to sim-plify the hardware as much as pos-sible, real-time software is used toperform the majority of control func-tions e.g., triggering and variable-rate sampling. Once captured, thesampled data is displayed using astandard oscilloscope 10 by 8 screenformat that is designed to maximisescreen use. A simple four-positionmenuing system (one for each key)in combination with the joypad pro-vides easy setting of the standardscope functions.
A number of advanced optionsare also possible for the more expe-rienced user, these include FFTanalysis, XY mode, averaging andreference storage. A serial data linkallows the displayed screen or tracedata values to be transferred to a PCcomputer via the computer’s printer
port. The PC software is MS Win-dows 95 compatible.
The oscilloscope has two inputchannels CHA/B, with independentsoftware-controlled variable-gainamplifiers. The inputs have a 1-MΩinput impedance so they can be con-nected directly to 1:1 or 10:1 scopeprobes or to an audio jack lead. (lim-itations on size made BNC type con-nectors impractical). The amplifierscan be AC or DC coupled by meansof a switch. The variable-gain ampli-fiers give an input sensitivity of50 mV to 10 V per division with 10:1probes and an input bandwidth ofDC to 100 kHz.
The displayed trace has twomodes of operation. For low frequen-cies (100 s to 100 ms/DIV), a chartrecorder style of display is producedwith the trace scrolling across fromthe right hand side. For high fre-quencies (50 ms to 5 µs/DIV), an
TEST& MEASUREMENT
3510/2000 Elektor Electronics
Key Features:Dual trace displaySampling Rate: DC to 1 MspsTime Base: 100 s to 5 µs/DivInputs: AC/DC 1 MegOhmInput gain: 50 mV to 10 V/DivLine or chart recorder trace
modesReal-time FFT mode with dB scaleVariable persistence XY modePC link for screen or data transfer5 hrs operation from NiMH bat-
teriesAveraging and Auto trigger func-
tionsReference trace storage
FFT — the basicsThe following details the specific implementation of the GBDSO FFT for those requiring agreater explanation of its operation. Initially, the input data is sampled using the standardscope capture programs. The data is then passed through a Hamming window to reduceartefacts caused by the finite sample points (rectangular window). A Hamming window waschosen as it gives a good compromise between main lobe and side lobe widths. The win-dowed data is recorded using a bit-reversal algorithm to suit the decimation in time (DIT)process of the FFT. The data is then processed by a discrete Fourier transform (DFT),which is implemented using a 256-point radix-2 fast Fourier transform (FFT).16-bit arithmetic is used for the majority of the calculations, but since the GB has no multi-ply instruction this has to be calculated longhand by assembler software. The complex realand imaginary values of the DFT are combined to produce 128 x 32 bit values.Finally, a logarithm is taken (1 bit = 6 dB) and the data is displayed on the screen. The entireprocesses (excluding sampling) takes 0.8 seconds of which the FFT accounts for 90% of thetime requiring 4096 signed 16-bit multiplications and 6144 signed 16-bit additions.
Figure 1. Gameboy card edge connector (end view of ROM cartridge).
1
+5V
32
990082 - 11
ECLKWR
A0 - A15 D0 - D7
RDRAM_CS
GNDAUDIO INRESET
GAME BOY
top view
the data and address busses of the GB Z80 (-like) main processor. The pin functions of thecard edge connector are shown in Figure 1.
Circuit diagram
As you can see from the circuit diagram inFigure 2, the GBDSO cartridge, despite itsrather complex function, contains a relativelysmall number of integrated circuits.
The GB is controlled by an 8-bit Z80-likeprocessor that gives a direct addressingrange of 64 kB. However internal devices e.g.,LCD, RAM, sound etc. use most of the top32 KB leaving 0000-7FFF available for exter-nal ROM and A000-BFFF for external RAM.The GBDSO program is stored in a low power27C256 32 kB EPROM, IC7, occupying lowermemory at 0000 to 7FFF which is executedupon power-on. The ADC and input gain con-trol chips occupy a single memory location atA000.
Address decoding consists of a74HC138 1-of-8 decoder, IC6, thatdecodes the address range down toA000-BFFF and provides two enablesignals: 1. A000./RD at pin 9 accesses theADC and reads CHA/B 8-bit datavalue while reinitialising the ADC forthe next sample.2. A000./WR at pin 10 accesses the74HC175 quad latch and writes datato the DS1267 gain control circuit, orselects the input sampling channelof the ADC.
The DS1267 from Dallas Semicon-ductor is a dual channel 10-kΩ digi-tal gain control potentiometer with256 wiper positions per channel.Data is transferred to the devicethrough a serial interface via the74HC175 latch, this updates both pot
values simultaneously. Onceupdated, the values are held untilthe next update or the power isremoved. A condensed datasheet ofthis interesting IC may be foundelsewhere in this issue.
The GBDSO analogue circuitryrequires ±5 V to operate, so aninverting capacitive charge pumpcircuit is used to provide the nega-tive supply. The device used for thisis a MAX828EUK (IC9) which has aninternal oscillator that operates at12 kHz. This allows relatively smallcapacitors to be used for smoothing.However, to prevent any high fre-quency noise being passed to thesensitive input amplifiers, additionalLC filters are used.
As already mentioned, the CHA/Binput amplifiers are designed to becompatible with 1:1 or 10:1 (0 or
TEST& MEASUREMENT
36 Elektor Electronics 10/2000
AUDIO _IN
RAM_CS
RESET
ECLK
+5V
K3
A10
A11
A12
A13
A14
A15
GND
WR
RD
A0
A1
A2
A310 A411 A512 A613 A714 A815 A916
17
18
19
20
21
22 D023 D124 D225 D326 D427 D528 D629 D730
31
32
1
2
3
4
5
6
7
8
9
74HC138DIC6
10
11
12
13
14
15DX
1
2
3
4
5
67
9&
0
1
2
3
4
5
6
7
0
2
G07
74HC175D
IC5
1314
15
11
1012
C1
1D
1
9
4
6
7
3
2
5
RC9
100n
C8
100n
C7
220p
C16
220p
6
5
7IC1b
6
5
7IC3b
R5
470k
1%
C3
1p8
C2
100n
C1
18p
R2
1M
1%
R3
4k
7
R1
1M
S1
R4
1M
D1
BAV199
100k
P1
K1
1%
CH B
5V 5VA
2V5 2V5
2
3
1IC3a
R12
470k
1%
C13
1p8
C11
100n
C1
18p
R9
1M
1%
R10
4k
7
R8
1M
S2
R11
1M
D2
BAV199
100k
P2
K2
1%
5V 5VA
2V5 2V5
R13
4k7
1%
R144
k7
1%
2
3
1IC1a
R6
4k7
1%
R7
4k
7
1%
C5
15p
C15
15p
C17
100n
D1
D0
D1
D2
D3
D4
D5
D6
D7
D0
D1
D2
D3
D4
D5
D6
D7
D4
D6
C18
100n
27C256
EPROM
IC7
PLCC
A10
A11
A12
VPP
A13
A14
25
11A0
A1
A2
A3
A4
A5
A6
A729
A828
A924
27
16
OE
23
CS
32
13D0
14D1
15D2
18D3
19D4
20D5
21D6
22D7
30
31
10
9
8
7
6
5
4
3
2
A13
A14
D0
D1
D2
D3
D4
D5
D6
D7
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
A15
A0
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
A11
A12
A13
A14
A15
MAX828
IC9
EUK
C– C+
4
2 1
3 5
C22
10µ6V
C25
10µ6V
C26
10µ6V
C28
10µ6V
C31
10µ6V
C33
10µ6V
C24
10µ6V
C23
100n
L1
100µH
IC5
16
8
IC6
16
8
L2
100µH
L3
100µH
C29
100n
C30
100n
6
5
7IC8b
R16
100k
1%
R17
100k
1%
C19
100n
R15
15
k
D3
ZR25D01
C20
100n
2
3
1IC8a
C21
100n
IC14
8
C4
100n
C5
100n
C12
100n
C14
100n
IC34
8
2V5
2V5
5VA
5V
2V5
2V5
CH A
CW
CW
5V
5VA
5VC
5VC
5VA
5V
5V
5V
5VA
5VC
5V5V5V
WR
ECLK
RD
RD
1V25
1V25
0V
0V
IC1 = MC33182D
IC3 = MC33182D
D7
D5
2V5
MAX114
IC4
MODE
REF+
REF–
INT
CAG
IN4
IN3
IN2
IN1
D0
24
12
D1
D2
D3
D417
D518
D619
D720
11
A022
A121
14
13
PD23
RD10
WR15
CS16
6
5
7
8
9
1
2
3
4
D1
DS1267S100
RESET
IC2
COUT
SOUT
CLK
H0
W0
16 13
12L0
11
W1
H1 L1
10
14DQ
VB
NC
NC15
8 5
3 4
6
9
1
2
7
C27
100n
8
4
IC8 = TLC27L2CD
990082 - 12
Figure 2. Circuit diagram of the GBDSO cartridge. Stop playing games — turn the Nintendo Gameboy into a sampling oscilloscope witha large clear display!
e.g., joypad, screen and sound generator. Formore information on software developmenthave a look through the list of referenceswhich will be given at the end of nextmonth’s concluding instalment.
User interface
On power up the GB starts to execute theGBDSO interface program that resides inexternal EPROM. The program initially dis-plays an intro screen and a set of four prede-fined start options which initialise the scopesettings: Single/Dual/Logic/AC. The scope isnow ready for use. Figure 3 shows a typicaldisplay screen with both channels enabled,
9 MΩ) probes, each input amplifierhaving a relatively high input imped-ance of 1 MΩ. This is achieved byfeeding the signal via a 1-MΩ resis-tor (R1; R8) into the negative input ofa CMOS opamp (IC1b/IC3a) typeMC33182D. This device is marked bylow power, high slew rate and JFETinputs. By utilising the negativeinput of the amplifier, the signal isfed to a virtual ground, reducingbandwidth limitations imposed bystray capacitance on the inputs.Input protection is provided byD1/D2, which are type BAV199 duallow-leakage diodes. The negativeinput also forms a current summingjunction for the DC zero preset(P1/P2) which is adjusted to reduceDC errors at high gain settings.
The variable-gain amplifier sec-tion consists of IC1a/IC3b and theelectronic potentiometer inside theDS1267. The amplifier is configuredas an inverting amplifier with thepotentiometer forming the input andfeedback resistors (wiper is W0). Bychanging the wiper position throughsoftware, the gain of the amplifiercan be varied between 0.004 and255, considerably reducing theamount of input circuitry requiredand eliminating the need formechanical switches.
Interfacing to the 8-bit ADC typeMAX114 from Maxim (IC4) requiresan input signal in the range 0-2.5 V.To achieve a stable reference voltagewith varying supply, a 2.5-Vbandgap diode type ZR25D01 isused. DC biasing of the CHA/Bamplified signal to match the ADCinput is achieved with two 4k7 resis-tors which transform the ±2.5-Vamplifier signal into 0-2.5 V for theADC. The MAX114 is identified byMaxim as a ‘1-Msps, 4 &8-Channel,8-bit ADC with 1-µA Power-Down’.The device is good for a conversiontime of 680 ns per channel, and fea-tures internal track/hold circuitrythat does not require an externalclock.
Finally, the power supply is rigor-ously decoupled to prevent high-fre-quency noise affecting the operationof the sensitive input circuitry. Acombination of electrolytic capaci-tors and smaller solid ones of 0.1 µF,plus two 100-µH chokes areemployed to keep supply-bornenoise to a minimum.
Gameboy softwareThe GBDSO software that resides inthe EPROM on the cartridge boardwas written in a mixture of assem-bler language and ‘C’, with assem-bler used for the real time dataacquisition and display and ‘C’ pro-vides the user interface. The ‘C’ com-piler used was GBDK V. 2.17, whichis a public domain program writtenby Pascal Felber and Michael Hope5.GBDK is an excellent means ofquickly developing dedicated soft-ware for the Gameboy, as it containsmany predefined functions for inter-facing to dedicated GB hardware
TEST& MEASUREMENT
3710/2000 Elektor Electronics
Figure 3. Typical view from dual trace screen.
Table 1. Key Function Menu
Highlighted Function Key
Joypad SELECT-‘TRIG’ START- ‘Timebase’ B - ‘CHB’ A - ‘CHA’
UP Trigger level Screen window Y Position Y Position Down Position
Right Trigger mode1 Timebase scale2 Input gain Input gain Left Scale3 scale3
Notes.1. Trigger modes for CHA are Auto, Auto, Normal, Normal.
Auto trigger — produces a trace if a trigger has not occurred within a set timeNormal trigger — holds the trace until a trigger occurs
2. Timebase scale range is 500,200,100,50S etc. up to 5 µS/DIV.3. Gain scale range is 10,5,2,1V,500,200,100,50 mV/DIV,GND,OFF
990082 - 13
Standard menusBy pressing A/B/Start/Select, the appropriatefunction will be highlighted on the bottomline of the scope (note CHA is highlighted).Once a function is highlighted, the joypadcontrol can be used to adjust the values asso-ciated with that function, as shown inTable 1.
Advanced menusThe function key menu provides a quickmeans of changing the standard scope set-tings with as few key presses as possible.However, if the highlighted function key ispressed a second time then an advancedmenu will be displayed. The advanced menuoptions may be found in Table 2.
Each advanced menu has three optionsand an exit. When an option is selected withthe function key it will be enabled immedi-ately and the screen will return to normaloperation. Some options switch between oneof two modes e.g., average on/off. The normalscreen will display which of the two modesis currently selected. The following sectiondescribes in greater detail the operation ofeach option.
‘A’ Advanced menu600/240pt, selects the number of points sam-pled each trace scan. By moving the screenwindow position with the ‘timebase + ↑↓’menu, it is possible to scroll through up tothree screens of data in 600pt mode. The cur-rent window position and size are shown inthe top right corner of the screen. The defaultmode is 240 points as this gives the fastestscreen update rate. In FFT mode this is fixedat 240 points.
Auto Trigger calculates the average value ofCHA relative to the current timebase setting,the trigger is set to this value.
Average, averages CHA (and CHB if enabled)using previous trace scans. The average iscalculated from X=X+(Xnew–X)/8. This canbe useful for removing uncorrelated noisefrom a trace, so the required signal can bemeasured.
‘START’ advanced menuCHA⇒REF, Stores the current trace of CHAto the reference channel and displays itallowing up to three traces on the screen atonce. Selecting this menu again will clear thereference. The letter R will appear in the left-hand column indicating a reference trace.
SCREEN⇒PC, The current scope screen willbe transferred to the PC computer via the linklead. When the start of transfer has been
acknowledged, the GB will beep andthe progress indicator will change onthe PC. At the end of transfer the GBwill beep again. The screen will beconverted to a black and white160x144 .BMP format by the PC andcan be saved to disk.
DATA⇒PC, The current data values(not screen) of CHA and CHB will betransferred to the PC computer in asimilar method to that above. Datacan be saved to disk as raw data orin MathCad 6.0 format for import-ing back into the computer for analy-sis. See the section on the PC Link
Interface (part 2) for more details.‘SELECT’ advanced menuFFT, changes scope operation to FFTmode. FFT mode produces a spec-trum analysis of the sampled data,where the horizontal axis representsfrequency and the vertical axis rep-resents amplitude in dB (10 dB/DIV).See the FFT section for more infor-mation on the FFT mode.
XY, changes the scope operation toXY mode with the horizontal tracedeflection set by CHA and the verti-cal deflection set by CHB. The tracepersistence (how long each point is
TEST& MEASUREMENT
38 Elektor Electronics 10/2000
Table 2. Advanced Menu Screens
Function Key Advanced menu screens
Select
Start
B Not used
A
10k
100nCHA CHB
500Hz6Vpk-pk
Time to XY
990082 - 14
Figure 4. RC network and XY mode.
Time to FFT
990082 - 15
Figure 5. FFT of 1 kHz 0 dB sinewave.
down. By comparison, the 1-kHz square waveof Figure 6 contains a fundamental and oddharmonics at 3, 5, 7 kHz, etc. which reduce inamplitude as the frequency increases.
Closer observation of Figure 5 shows aspurious spectral peak at 3 kHz which is30 dB down on the fundamental, this is in factproduced by the signal generator and repre-sents distortion of the pure sine wave. Thetime response gives no indications of thisproblem and it is clear that without the FFTmode this imperfection would not be mea-surable but it could cause problems whenanalysing circuits.
Using the FFT mode can often give unex-pected results and some experimentation andexperience is required to obtain meaningfulresults. Here are some points to consider.
Make full use of the 8bit samples, if possibleadjust the signal amplitude or referencemarker so that the input signal is at its max-imum i.e.: the highest peak is just below thereference marker. The Reference Markerrange is 35, 30, 20, 15, 10, 0, –5, –10 dB, GND.Do not increase the signal above this point asthis will saturate the scope amplifiers andintroduce spurious harmonics.
If a signal contains a wide spectrum of fre-quencies, often the frequency componentsthat extend beyond the FFT will be reflectedback so that they become visible again,which can be misleading. By increasing thetimebase frequency you can reduce thiseffect. The Timebase scale range is 10, 25,50 Hz etc., up to 100 kHz/DIV.
To lower the noise floor, use the averagingmode.
Measuring small signals with a large fun-damental, is possible if you use a notch filtercircuit (e.g., twin-T) to remove the fundamen-tal component before the signal is applied tothe scope. This effectively increases thescope’s dynamic range.
(990082-1)
Next month we continue with the PC LinkInterface, the construction of he cartridge,testing and calibrating the instrument.
displayed) can be set to 100 ms, 1 s,10 s, 100 s or OFF (infinite). The max-imum number of points plotted onthe screen at any time is 600. See theXY section for more information onthe XY mode.
TIME, changes the scope operationto normal scope mode with the hori-zontal axis representing Time afteran initial trigger point and the verti-cal axis representing amplitude inVolts.
XY Mode
The XY mode allows the horizontaland vertical deflection to be con-trolled by CHA and CHB respec-tively. This can be used to displayhow one circuit parameter is chang-ing with respect to another.
A simple RC network demon-strates how phase shift is introducedinto a circuit by the capacitive com-ponent, see Figure 4. The inputsinewave moves the trace horizon-tally and the ‘phase advanced’ out-put from the RC network moves thetrace vertically resulting in a circularimage. Changing the frequency andwaveform type gives some interest-ing effects.
In XY mode the trace persistence(how long each point is displayed)can be set from the timebase to100 ms, 1 s, 10 s, 100 s or OFF (infi-nite). When the persistence is set toOFF, the points plotted on the screenremain visible until the screen iscleared by pressing one of the func-tion keys. When the persistence isset to one of the time values, a max-imum of 600 points can be displayedat a time and they will remain visiblefor length of time defined by thetimebase setting. Therefore, the 100-ms setting is used to measure fastchanges and the 100-s setting for
measuring slow changes.
FFT Mode
Normally, signals are considered asvarying in amplitude with time andare therefore measured as a functionof voltage versus time. However, allcontinuous signals can be con-structed from a fundamental andharmonically related (Fourier) com-ponents which are best representedlogarithmically as magnitude (dB)versus frequency (Hz). This is morecommonly known as a spectralanalysis and is often used in audiosystems to measure the performanceof an amplifier, or the purity of a sig-nal. The GBDSO computes the spec-tral analysis using an algorithmknown as the fast Fourier transformor FFT which is a mathematicallyintensive method, normally associ-ated with high speed digital signalprocessors – DSPs. Nevertheless, bycoding the algorithm entirely inassembly language and optimisingits performance, the FFT is per-formed in just 0.8 seconds.
A full discussion on frequencyanalysis is beyond the scope of thisarticle, but by considering a fewexamples it will soon become clearhow useful the FFT mode is and inwhat circumstances it should beused. Figure 5 shows a 1-kHz sinewave of amplitude 0 dBVrms or1.414 Vpk (0 dB = 20log(1V rms),rms=pk x 0.707). The vertical scaleis fixed at 10 dB/DIV and the refer-ence marker (represented by a dot-ted line near the top of the screen) isdetermined by the ACH gain settingin dB. Since the sine wave containsonly one frequency component (thefundamental), the frequency spec-trum shows a single peak at 1 kHz.With the reference marker set to0 dB, the noise floor is about –45dB
TEST& MEASUREMENT
3910/2000 Elektor Electronics
Time to FFT
990082 - 16
Figure 6. FFT of 1 kHz 0 dB squarewave.
WarningWhen using 10:1 probes, the maximum inputvoltage applied to GBDSO must not exceed±50 V; with 1:1 probes the maximum inputmust not exceed ±16 V. Under no circum-stances should 230/110 V mains voltages beapplied to the GBDSO.