This program calculates key parameters of tuned (resonant) LC circuits, implementing six formulas selectable by menu: resonant frequency (F₀), unknown inductance, unknown capacitance, Q factor, bandwidth, and impedance at series or parallel resonance. Unit conversions are handled inline, dividing millihenries by 1000 and microfarads by 1,000,000 before computation. Because the platform lacks a built-in square root function, the program includes a custom iterative square-root subroutine at lines 3010–3090 using Newton’s method, which terminates when successive corrections become zero or repeat. The bandwidth section at line 360 uses a variable-comparison technique to determine which of Q, F₀, or BW is the unknown, comparing the user’s input against the current values of variables Q, F, and B.
Program Structure
The program is organized as a flat menu dispatcher. Lines 10–90 display a numbered menu of six functions; line 90 inputs the user’s choice into U. Lines 100–150 form a chain of IF … THEN GO TO branches routing to the appropriate calculation block. Each block ends with STOP, so the program halts after displaying a result rather than looping back to the menu. A custom square-root subroutine occupies lines 3010–3090 and is called only from the resonant-frequency block (line 220).
Calculation Blocks
| Lines | Function | Formula Used |
|---|---|---|
| 170–235 | Resonant frequency F₀ | F₀ = 1 / (2π √(LC)); approximated as 159 / √(LC) with L, C in base units |
| 240–275 | Unknown inductance L | L = 0.0254 / (F² × C) |
| 280–315 | Unknown capacitance C | C = 0.0254 / (F² × L) |
| 320–350 | Q of circuit | Q = X / R (reactance / series resistance) |
| 360–510 | Bandwidth (three sub-cases) | Q = F₀/BW; F₀ = Q×BW; BW = F₀/Q |
| 520–590 | Impedance (series & parallel) | Z_series = R; Z_parallel = X_L × Q |
Square Root Subroutine
Because the platform provides no intrinsic square-root function, lines 3010–3090 implement Newton’s (Heron’s) iterative method. The caller places the radicand in X and receives the result in Y; internal working variables are W and Z. Line 3030 handles the zero case, and line 3040–3050 trap negative inputs with an error message. The iteration at line 3070 computes the correction W = (X/Y − Y) × 0.5 and line 3080 exits when W is either zero or equal to the previous correction Z, preventing an infinite loop due to floating-point oscillation.
One notable anomaly: line 3030 tests X=O and assigns Y=O, using the variable O (letter O) rather than the numeric literal 0. Unless O has been explicitly set to zero beforehand, this relies on the default initialization of unassigned variables to zero — which holds in this dialect, so the code functions correctly but is potentially confusing.
Resonant Frequency Approximation
The constant 159 used in line 230 is the rounded value of 1 / (2π) × 10³ × 10³, chosen so that when X = (L/1000) × (C/1,000,000) is passed to the square-root subroutine, the result Y can be divided into 159 to yield the frequency in Hertz directly. The more precise value of 1/(2π) ≈ 0.15915 scaled for mH and µF units gives exactly 159.15, so the truncation to 159 introduces a small systematic error of about 0.1%.
The inductance and capacitance solver blocks (lines 260 and 300) use the constant 0.0254, which is 1/(4π²) ≈ 0.02533 rounded — again a mild approximation that keeps the arithmetic simple while sacrificing a fraction of a percent of precision.
Bandwidth Sub-menu Technique
Lines 360–390 implement an unusual dispatch: the user is prompted to enter the letter Q, F, or B as a string, but the INPUT stores it into the numeric variable X. The subsequent comparisons IF X=Q, IF X=F, IF X=B compare the numeric value that the parser extracts from the letter against the current runtime values of variables Q, F, and B. This is fragile — it depends on those variables being uninitialized (zero) and the parser evaluating bare variable names entered by the user as their current numeric values. In practice, if the user types a letter that maps to an uninitialized variable equaling zero, all three comparisons could match or none could, making this logic error-prone.
Key BASIC Idioms
- Multiple statements on one line separated by
:(e.g., lines 3030, 3080, 3090). GO TO VAL "80"at line 9999 uses theVALstring-to-number trick as a memory optimization for the branch target.SAVE "RESONA.B1" LINE SGN PIat line 9992 usesSGN PI(which evaluates to 1) as the auto-run line number.- Unit scaling is done inline at point of use (e.g.,
L/1E3,C/1E6) rather than storing converted values in new variables, keeping memory usage low.
Bugs and Anomalies
- Lines 320–340 use
PRINTrather thanINPUTfor the reactance and resistance prompts, so the user is never actually able to enter values forXandR; the Q calculation at line 340 will use whatever those variables held from earlier calculations. - The bandwidth dispatcher (line 360) is logically unreliable as described above — the comparison of a user-typed variable name against numeric variables is not a robust dispatch mechanism.
- Line 9999 branches to line 80, which does not exist; this would cause a runtime error if executed, though it appears to be a loader stub rather than part of normal program flow.
Source Code
1 REM \{20}\{1}RESONANCE (TUNED CIRCUITS) BY ROY BABYLON POPULAR ELECTRONICS AUG 1979 PAGE 47\{20}\{0}
5 CLS
10 PRINT TAB 15;"VARIOUS FORMULAS ON RESONANT FREQUENCY"
20 PRINT "ENTER NUMBER OF DESIRED FUNCTION"
30 PRINT "RESONANT FREQUENCY (FO) #1"
40 PRINT "UNKNOWN INDUCTANCE (L) #2"
50 PRINT "UNKNOWN CAPACITOR (C) #3"
60 PRINT "Q OF CIRCUIT (Q) #4"
70 PRINT "BANDWIDTH (BW) #5"
80 PRINT "IMPEDANCE, SRS OR PRLL (Z) #6"
90 INPUT "UNKNOWN FACTOR IS NUMBER";U
100 IF U=1 THEN GO TO 170
110 IF U=2 THEN GO TO 240
120 IF U=3 THEN GO TO 280
130 IF U=4 THEN GO TO 320
140 IF U=5 THEN GO TO 360
150 IF U=6 THEN GO TO 520
170 INPUT "ENTER VALUE OF INDUCTOR IN MILLIHENRIES";L
180 INPUT "ENTER VALUE OF CAPACITOR IN MICROFARADS";C
210 LET X=(L/1E3)*(C/1E6)
220 GO SUB 3030
230 PRINT "THE RESONANT FREQUENCY IS";159/Y;"HERTZ"
235 STOP
240 INPUT "ENTER RESONANT FREQUENCY(FO)DESIRED";F
250 INPUT "ENTER CAPACITOR VALUE IN MICROFARADS";C
260 LET L=.0254/(F*F)*(C/1E6)
270 PRINT "THE INDUCTOR NEEDED IS ";L*1E3;"MILLIHENRIES"
275 STOP
280 INPUT "ENTER RESONANT FREQUENCY(FO)DESIRED";F
290 INPUT "ENTER INDUCTOR VALUE IN MILLIHENRIES";L
300 LET C=.0254/(F*F)*(L/1E3)
310 PRINT "THE CAPACITOR NEEDED IS ";C*1E6;"MICROFARADS"
315 STOP
320 PRINT "ENTER THE REACTANCE(XC OR XL)IN OHMS";X
330 PRINT "ENTER THE SERIES RESISTANCE IN OHMS";R
340 PRINT "THE Q OF THE CIRCUIT IS";X/R;"UNITS"
350 STOP
360 INPUT "ENTER UNKNOWN, Q=Q, FO=F,BW=B";X
370 IF X=Q THEN GO TO 400
380 IF X=F THEN GO TO 440
390 IF X=B THEN GO TO 480
400 INPUT "ENTER FO IN HERTZ";F
410 INPUT "ENTER BW(F2-F1)IN HERTZ";B
420 PRINT "THE Q IS EQUAL TO ";F/B;"UNITS"
430 STOP
440 INPUT "ENTER THE Q OF THE CIRCUIT";Q
450 INPUT "ENTER BW(F2-F1)IN HERTZ";B
460 PRINT "THE RESONANT FREQUENCY(FO)IS";Q*B;"HERTZ"
470 STOP
480 INPUT "ENTER RESONANT FREQUENCY(FO)IN HERTZ";F
490 INPUT "ENTER THE Q VALUE";Q
500 PRINT "THE BANDWIDTH IS";F/Q;"HERTZ"
510 STOP
520 INPUT "ENTER VALUE OF INDUCTOR IN MILLIHENRIES";L
530 INPUT "ENTER FREQUENCY(FO)IN HERTZ";F
540 INPUT "ENTER RESISTOR VALUE IN OHMS";R
550 PRINT "AT SERIES RESONANCE,XL AND XC CANCEL THEREFORE Z=";R
560 LET P=(2* PI)*(F)*(L/1E3)
570 LET Q=P/R
580 PRINT "THE PARALLEL IMPEDANCE IS EQUAL TO";P*Q;"OHMS"
590 STOP
3000 STOP
3010 REM *SQUARE ROOT*INPUT X,OUTPUT Y
3020 REM ALSO USES W&Z INTERNALLY
3030 IF X=O THEN LET Y=O:RETURN
3040 IF X>O THEN GO TO 3060
3050 PRINT "ROOT OF NEGATIVE NUMBER?":STOP
3060 LET Y=X*.5:LET Z=O
3070 LET W=(X/Y-Y)*.5
3080 IF (W=O)+(W=Z) THEN RETURN
3090 LET Y=Y+W:LET Z=W:GO TO 3070
9989 STOP
9992 SAVE "RESONA.B1" LINE SGN PI
9998 REM LOAD "L.B1"
9999 GO TO VAL "80"
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
