Speed Check

by Garry Francis


Issue 24

Nov/Dec 86

Next Article >>

<< Prev Article



Speed Check is an essential utility for all owners of Atari disk drives. The program allows you to check the speed of the motor in your disk drive without having to pull the drive to pieces. It presents a clear, no-nonsense digital display of test results as well as diagnostic messages, mean and standard deviation. In addition, it is the only disk speed checker that works on both PAL and NTSC systems.

The accompanying article explains how to get Speed Check up and running and how to use it. This is followed by a brief discussion of how the program works for the benefit of advanced users. In a follow-up article next issue; I'll discuss the symptoms of an incorrect drive speed, 3 ways of testing the speed and how to adjust the speed yourself.

System requirements

  • Atari 400/800/XL/XE computer with a minimum of 16k RAM
  • Any Atari (or compatible) disk drive whose optimum motor speed is 288 r.p.m.
  • Atari BASIC

How to enter Speed Check

The complete Speed Check program is given in listing 1. The listing is fairly straightforward except for the machine language string in line 1030. Be particularly careful when entering this line. If you feel uncomfortable with lines of gobbledegook like this, then use listing 2 to generate it for you automatically. Just follow these instructions:

1. Insert a formatted disk into drive 1 and leave it there until finished.

2. Enter the whole of listing 1 except for line 1030 and make sure there are no typing errors.

3. Save a copy of the program on disk using SAVE "D:SPEED.BAS". Do not attempt to run the program yet.

4. Type NEW.

5. Enter listing 2 and make sure there are no typing errors.

6. Type RUN. This will create line 1030 for you on a temporary file called TEMP.

7. Type NEW.

8. Load the original program using LOAD "D: SPEED.BAS".

9. Enter line 1030 using ENTER "D:TEMP". 

10. Save the completed program using SAVE "D:SPEED.BAS".

AtariLister - requires Java


Listing 1

0100 ;###############################
0120 ;#     DISC SPEED CHECKER      #
0130 ;#      by Garry Francis       #
0140 ;#       Copyright 1983        #
0150 ;###############################
0160 ;
0170 ;Code is relocatable, so may be stored
0180 ;in a string (e.g. ML$). Assembled to
0190 ;page 6 for convenience only.
0200 ;
0210 ;Call from BASIC using:
0220 ; X=USR(ADR(ML$))
0230 ;
0240 RTCLOK=$12
0250 DSTATS=$0303
0260 CONSOL=$D01F
0270 DSKINV=$E453
0280 COUNT=$CB
0290 *=$600
0300 PLA ;Remove no. of arguments from stack
0310 LDA #5 ;Allow 5 revolutions to get up to speed
0320 STA COUNT ;Store in zero page counter
0330 LOOP1 JSR DSKINV ;Call disk handler
0340 LDA DSTATS ;Check error code
0350 BMI EXIT ;Return if any errors
0360 LDA CONSOL ;Check if console keys are pressed
0370 AND #6 ;Test Bits 1 [SELECT] & 2 [OPTION]
0380 EOR #6 ;Complement bits
0390 STA $CC ;Save result for BASIC
0400 BNE EXIT ;Return if either was pressed
0410 DEC COUNT ;Decrement counter
0420 BNE LOOP1 ;Continue until finished 5 revs
0430 LDA #30 ;Now do 30 revolutions
0450 LDA #0 ;Reset real-time clock
0460 STA RTCLOK+2 ;Low byte
0470 STA RTCLOK+1 ;Middle byte (high byte not used)
0480 LOOP2 JSR DSKINV ;Similar to above
0520 AND #6
0530 EOR #6
0540 STA $CC
0570 BNE LOOP2
0580 LDA RTCLOK+2 ;Save time for BASIC
0590 STA $CD ;Low byte
0610 STA $CE ;Middle byte
0620 EXIT RTS ;Return to BASIC
0630 .END

Listing 3

How to use Speed Check

Once you have a completely bug-free copy of Speed Check on disk, run it by typing RUN "D:SPEED.BAS" (or whatever filename you've used) from BASIC. The program is self explanatory and extremely simple to use. You may care to read these detailed instructions once, but will probably never need them again.

When the program has loaded, you will see a fairly bare title screen. About two thirds of the way down the screen is the message line. All prompts and error messages will occur on this line. The initial prompt requests you to enter the number of the drive you wish to test. You would normally respond by pressing 1 to test the speed of drive 1. You do not have to press the RETURN key. If you have more than one drive, you can test the other drives by pressing 2, 3 or 4 as appropriate. Any response apart from the numbers 1 to 4 will be ignored.

After selecting the drive number, you will be prompted to insert a formatted disk into the drive selected in the first step. (The drive number is always displayed in messages so that you can keep track of things.) You can use any formatted disk for testing the speed. The program will only read sector 1. The disk will never be written to or altered in any way, so you can leave the Speed Check disk installed if you wish. However, you will probably feel better psychologically if you use a blank disk or some other unimportant disk.

Notice that there is now also a menu beneath the message line. Once the formatted disk is installed, you may press any of the console keys shown in the menu to carry out the indicated function. These may be pressed in any order and at any time. Their effect will be immediate.

START: START does what its name implies - it starts the test. After pressing START, a message such as 'TESTING DRIVE 1' will be displayed on the message line. The drive spurts to life and the speed test begins. The program allows 5 revolutions for the drive to get up to speed, then times the next 30 revolutions using the real time clock. The test number and the resultant speed are printed in large letters.

The speed is rounded to the nearest integer, but a more accurate result is kept internally for use later on. Immediately below this is a diagnostic message to give you an indication of whether the speed is alright. The optimum speed is 288 r.p.m. This will be reflected by the message PERFECT!. Any other speed within the acceptable range of 285-290 r.p.m. will be given the message OKAY. If the speed is below 285 r.p.m., you'll get the message TOO SLOW and if the speed is above 290 r.p.m., you'll get the message TOO FAST. A message of TOO SLOW or TOO FAST may mean that the drive needs adjusting. Note that the messages are colour-keyed to reflect this. Red means the drive needs adjusting, whereas green means it's okay.

The program now repeats this cycle continuously until you press SELECT, OPTION or SYSTEM RESET.

At the end of each group of 10 tests, the results are submitted to some standard statistical procedures to determine their mean and standard deviation. The results are printed below the diagnostic message. These results are further discussed under 'Analysing Test Results'.

SELECT: SELECT is used to pause the test so that you can take notes, change disks, answer the telephone, grab a cup of coffee or whatever. After pressing SELECT, a message such as 'TEST PAUSED ON DRIVE 1' will be displayed on the message line and the drive will stop. This does not affect the test in any way. It may be continued from where you left off by pressing START or you may choose to re-run the program by pressing OPTION.

OPTION: OPTION is normally used to change the drive number. It returns you to the first screen and is, in effect, the same as re-running the program from the beginning. The screen is cleared and all previous test results are lost.

Other keys: The keyboard has been 'idiot-proofed' to ensure that you can't press the wrong key. The BREAK key is disabled at all times. The rest of the keyboard is also disabled except for the period when selecting the drive number. CTRL-1 has no effect. All of this has one interesting side effect. If there is no user input for about 9 minutes on NTSC systems or 11 minutes on PAL systems, the random colour switching of the attract mode will come into effect. It is unlikely that you'd be running the program for this long, but if you do and you find the random colours annoying, you can press any of the console keys that would be valid at that time and the display will return to normal. As the keyboard is disabled, pressing a key will not kill the attract mode as you would normally expect.

The only way to abort the program and return to BASIC is to press SYSTEM RESET. This was done to ensure that all system parameters are properly reset.

Analysing test results

The accuracy of the testing procedure is determined by the real time clock. As this is only accurate to one jiffy (1/50th second on PAL systems or 1/60th second on NTSC systems), the individual test results become accurate to about plus or minus two jiffies. This works out to be somewhat less than plus or minus 0.2 revolutions per test (remembering there are 35 revolutions per test), so the integer test results may fluctuate slightly. If your test results are consistently in the green area, then your drive's speed is okay. As mentioned above, the optimum speed for Atari disk drives is 288 r.p.m., but anything between 285 and 290 r.p.m. is acceptable.

It is important to take note of the mean and standard deviation of each 10 test results. The mean should be well within the 285-290 limits and the standard deviation should be less than (say) 1 r.p.m. If the standard deviation is consistently over 1 r.p.m., then your drive motor is suffering from excessive fluctuation and may need servicing.

Bad readings

There are two situations when an unreliable test result will occur. The first is due to a bug in the Revision A operating system of the Atari 400/800 computers which occasionally causes a device on the serial bus to 'go to sleep'. It will be quite apparent when this happens, because the beep ... beep ... beep of sector 1 being read will come to a stop. If the drive is inactive for very long, it will stop spinning and the busy light will go out. Do not touch anything. The drive will come back to life after a variable amount of time, but the result for that test will be ridiculously low. Simply ignore this figure. This bug was ironed out in the XL/XE operating systems, hence XL/XE owners should not encounter this situation.

The second situation comes about when you adjust the speed while the test is being carried our (see next issue). Again, simply ignore this figure and wait for the next one.

In both these cases, remember that the mean and standard deviation will be affected and should also be ignored. If you like, you can press OPTION to re-run the program and clear out the bad results.


Speed Check has been thoroughly tested and is believed to be totally bug free. The only possible errors that can occur are as a result of attempts to communicate with the disk drive via the Serial Input/Output facility (SIO). The causes of these errors and the possible recovery are discussed below. This is not light reading. You may need to read up on SIO in order to understand some of these descriptions. Refer to the Operating System User's Manual (Part No. CO16555) pages 130 to 140-D and the Hardware Manual (Part No. CO16555) pages II.25 to II.27.

Of the 6 possible errors generated by SIO, the only ones you are likely to encounter are errors 138 and 144. When an error occurs, a message such as 'ERROR 138 ... TEST ABORTED ON DRIVE 1' will be displayed on the message line. Once the source of the error has been corrected, simply press START to continue from where the program left off or press OPTION to re-run the program from the first screen.

Error messages - Cause and recovery

ERROR 138 - Device Timeout

Cause: When the computer sent a command frame to the specified drive, the drive did not send an acknowledgement within the time limit set by SIO. This is usually because the specified drive does not exist, but may also occur if the command frame checksum calculated by the drive does not agree with the checksum sent by the computer.

Recovery: You may have specified the wrong drive number. Check the drive number indicated in the error message. If it is not the drive you meant to test, press OPTION to re-run the program and set the correct drive number. If this is not the problem, then:

  • Check that the drive is plugged in, power is on and the drive is turned on (indicated by the 'power on' light).
  • Check that the I/O cable between the computer and the drive is connected and working correctly, particularly lines 2, 5 and 7.
  • Check that the drive select switches at the back of the drive are set correctly.

If all else fails, you may have the checksum problem, which would indicate a garbled command frame from the computer. This is rare and may indicate a hardware problem.

ERROR 139 - Device NAK

Cause: The drive could not carry out the command frame sent by the computer because it contained an invalid command or the auxiliary bytes referred to an unaddressable sector.

Recovery: As Speed Check only reads sector 1, this error should not occur. If it does, you may have a hardware problem.

ERROR 140 - Serial Bus Input Framing Error

Cause: There were extra or missing data bits received by the computer. (All serial communications are done using an asynchronous signal. Each byte of data is transmitted and received as 8 bits of serial data preceded by a logic zero start bit and followed by a logic one stop bit.)

Recovery: This is a very rare error which occurs when the data from the drive is garbled. Check that the I/O cable between the drive and the computer is functioning correctly - particularly line 3. Alternatively, there may be a hardware problem.

ERROR 142 - Serial Bus Data Frame Overrun Error 

Cause: A byte of data received by the computer 'overran' the previous byte of data because the microprocessor had not responded fast enough to deal with the first byte. 

Recovery: Again this is a rare error which may indicate a hardware problem.

ERROR 143 - Serial Bus Data Frame Checksum Error

Cause: The checksum of the last data frame sent by the drive does not agree with the checksum calculated by the computer. Either the data or the checksum itself may be garbled.

Recovery: This is a common error with cassette I/O, but it shouldn't happen very often with disk drives. Check the I/O cable (particularly line 3) and try again. If the error persists, it may be due to a hardware problem.

ERROR 144 - Device Done Error

Cause: The drive could not execute a valid command. This will usually occur if the drive cannot locate the required sector - in our case, sector 1. The error will probably be preceded by a terrible graunching noise from the stepper motor of the drive as it travels to the innermost track, then returns to track 0 to reattempt the operation. It will make 3 attempts before generating the error message. 

Recovery: The inability to find the sector may be because there is no disk in the drive or it is not inserted properly (in which case you should properly insert a disk and try again), the disk is not formatted (replace with a formatted disk) or sector 1 of the disk is damaged (use a different disk). The various manuals tell you that this error results from attempting to write to a write protected disk. Don't panic! This would be true under normal circumstances, but it is not applicable in our case. You can rest assured that Speed Check never writes to a disk.

How Speed Check works

The program is written entirely in Atari BASIC except for one machine language routine. It is split into 2 distinct blocks - the main program and the initialisation.

The initialisation is contained in a subroutine (lines 1000-1070) and is executed by the GOSUB 1000 in the first line of the program. It begins by disabling Direct Memory Access (DMA), the keyboard and the BREAK key, making the cursor invisible, setting the margins and colours and initialising a couple of variables. This is all fairly straightforward. It then checks the hardware register PAL at memory location 53268 (8D014) to determine whether the program is running on a PAL system or NTSC. If it is PAL, then bits 1, 2 and 3 will be clear (i.e. logic zero). If it is NTSC. then these bits will be set (i.e. logic true). (According to the hardware manual, bit 0 is not used, but it is always equal to one on my PAL system. The remaining bits are also supposedly not used, but they are equal to zero on my system .

If the system is PAL, then it is assumed that the power supply is 50Hz and hence the real-time clock RTCLOK at memory location 18-20 ($12-$14) is updated 50 times per second. If the system is NTSC, then the power supply must be 60 Hz and the real-time clock is updated 60 times per second. The variable HZ is set accordingly.

The array for storing the test results and a few strings are then dimensioned. The machine language routine is relocatable, so it is stored in a string ML$.

The display list is modified to include a few lines of GRAPHICS 1. The title and copyright information is printed and the operating system's pointer to the start of display memory is moved up in memory by 200 bytes so that the title is not cleared upon execution of the clear screen command.

Finally, the Device Control Block (DCB) is set up to read sector 1 into the cassette buffer, DMA is re-enabled and control is returned to the main program. This entire process takes a fraction of a second.

The main program is fairly straightforward until you reach the machine language routine at line 200. The assembly language source code for this routine is given in listing 3. This is supplied for informative purposes only. You do not need to type it in.

The routine begins by reading the same sector five times to allow the drive to get up to speed. Each time it reads the sector, it checks to see whether there were any errors. If there were, it returns to BASIC. It also checks to see whether the SELECT or OPTION keys were pressed. If they were, it again returns to BASIC. At the end of the five revolutions, it resets the real-time clock and repeats the above process, but for 30 revolutions instead of five. If successful, the time is saved and control is returned to BASIC. Note that the code for the two sets of tests is virtually identical. This was coded 'in-line' instead of as two calls to a subroutine in order to make the whole thing relocatable.

Once BASIC gets control again, it checks to see whether the machine language routine completed successfully. There are three possible outcomes:

  • The machine language routine terminated early because of an error. This will be indicated by DSTATS at memory location 771 ($303). A one indicates no error. Any other number indicates the error code. 
  • The machine language routine was terminated early because the user pressed SELECT or OPTION. This will be indicated by memory location 204. 0 means nothing was pressed. 2 means SELECT was pressed. 4 means OPTION was pressed.
  • The machine language routine completed successfully, in which case the test result is displayed and the program continues on as described earlier.

The statistical calculations are fairly straightforward. Some users may find the subroutine at lines 330-340 to be useful. Its purpose is to round off the decimal number in TEMP and fiddle it so that it is right justified with two digits after the decimal point. For example, 0 becomes 0.00, 9.1 becomes 9.10, 2.47321 becomes 2.47, 3.0694 becomes 3.07 and so on.

Next issue

Next issue, I'll explain how to adjust your drive's speed if Speed Check indicates that it's running too fast or too slow. See you then!