OpAmp Oscillator Design with the HP41C Programmable Calculator
May 25, 2009
I originally wrote this program for the HP67 calculator, and then ported it to the HP41C series. This program selects component values for an opamp based relaxation oscillator, given the desired frequency and output wave form peak voltages. It can also solve the inverse problem, finding the frequency and voltages resulting from given component values. The following is the schematic for such an oscillator:
R_{1} and R_{2} form a voltage divider, with an additional input from the opamp output through R_{3}. When the opamp output is at a highlevel, the voltage at the noninverting input of the opamp is higher than when the opamp output is at a low level. When the output is high, capacitor C_{1} also charges through R_{4} until the voltage across it (which is applied to the opamp’s inverting input) reaches the voltage at the noninverting input. At that time, the opamp output goes low, and the capacitor begins to discharge through R_{4} until the voltage once again reaches the (now lower) voltage at the noninverting input.
If one were to monitor the opamp output, it would alternate between a high level (V_{OH}, generally close to positive supply voltage, V_{POS}) and a low level (V_{OL}, generally close to negative supply voltage, V_{NEG}). The duty cycle of this square wave depends on the relative time it takes to charge and discharge C_{1} through R_{4}, which in turn depends on the low (V_{PL}) and high (V_{PH}) peak voltages that C_{1} cycles between (which in turn depend on R_{1}, R_{2}, and R_{3}). Monitoring the voltage across C_{1} shows a triangle wave.
With this program, you can select components for such an oscillator to achieve a desired frequency, and if it matters to your design, desired low and high triangle peaks (V_{PL} and V_{PH}). After the program computes the required component values, you can modify these values to match those actually available in the real world. The program will then compute what effect these changes have on the frequency and triangle peak voltages.
The following equations describe the operation of the oscillator:
You will first need to choose values for C_{1} and R_{1} arbitrarily, since for any desired frequency and given C_{1} and R_{1}, it will be possible to find (possibly impractical) values for R_{2}, R_{3}, and R_{4}. A good choice for R_{1} is generally somewhere around 10kΩ to 100kΩ. The choice of C_{1} depends on the frequency, and a readily available value near (50/f) μF is usually suitable.
Using the Program
First type in the program and save it, or read it from a previously recorded magnetic card. The card should be labelled as follows:
OPAMP OSCILLATOR DESIGN  

V_{NEG},V_{POS}  V_{OL},V_{OH}  C_{1}  R_{1}  V_{PL},V_{PH} 
f  →%DC  →R_{2}→  →R_{3}→  →R_{4}→ 
Forward Solution: Finding R_{2}, R_{3}, and R_{4}
Consider the following example: It is desired to find values for R_{2}, R_{3}, and R_{4} to produce an oscillator of about 2500Hz, with a triangle waveform that oscillates between 1.2V and 1.4V. The opamp is to operate from a single 5V supply, and the opamp’s output is capable of a low of 0.3V and a high of 5V. Use a 0.022μF capacitor for C_{1}, and a 22kΩ resistor for R_{1}.
Follow these steps to solve the problem:
Description  Keystrokes  Display 

Select engineering notation  ENG 2  0.00 00 
Enter power supply voltages  0 ENTER 5 a 
0.00 00 
Enter low and high level output voltages  0.3 ENTER 5 b 
300. 03 
Enter C_{1} (Farads)  0.022 EEx CHS 6 c 
22.0 09 
Enter R_{1} (Ohms)  22 EEx 3 d 
22.0 03 
Enter desired triangle lower and upper voltage peaks  1.2 ENTER 1.4 e 
1.20 00 
Enter desired frequency (Hz)  2500 A 
2.50 03 
Compute square wave duty cycle  B  788. 03 
Compute value of R_{2} (Ohms)  C  7.26 03 
Compute value of R_{3} (Ohms)  D  123. 03 
Compute value of R_{4} (Ohms)  E  71.4 03 
Notes
Specifying V_{OL} and V_{OH} is optional. If this step is omitted, the program will assume the opamp output can span the entire negative and positive supply voltage range.
If the triangle wave form peak voltages don’t matter to your design (because you’re only using the square wave output), you don’t need to specify them. The program will assume peak voltages ranging from V_{OL}+(V_{OH}–V_{OL})/3 to V_{OH}(V_{OH}–V_{OL})/3, which is the middle third of the opamp output voltage range. This also happens to result in a 50% duty cycle.
To achive a low duty cycle square wave, choose V_{PL} and V_{PH} close to the bottom of the opamp output range (V_{OL}). Likewise for a high duty cycle, choose V_{PL} and V_{PH} close to the top of the range (V_{OH}).
For the most stable oscillation frequency, choose V_{PL} and V_{PH} far away from the opamp output voltage limits, V_{OL} and V_{OH} (to keep the triangle edges steep), and far away from each other (to keep any variations a small percentage of the overall voltage swing). Since these two goals are at odds with one another, a good compromise is to select V_{PL} and V_{PH} to span the middle of the V_{OL} to V_{OH} range (which is the default if V_{PL} and V_{PH} aren’t specified).
Reverse Solution: Finding V_{PL}, V_{PH}, Frequency, and Duty Cycle
After finding the above ideal solution, we’ll want to use realworld component values to build the physical circuit. The closest E24 resistor values to those computed are: R_{2} = 7.5kΩ, R_{3} = 120kΩ, and R_{4} = 68kΩ. What effect will using these values have on the frequency, V_{PL}, and V_{PH}?
These are the steps to find out:
Description  Keystrokes  Display 

Enter new value for R_{2}  7.5 EEx 3 C 
7.50 03 
Enter new value for R_{3}  120 EEx 3 D 
120. 03 
Enter new value for R_{4}  68 EEx 3 E 
68.0 03 
Compute resulting value for V_{PL}  e  1.23 00 
Compute resulting value for V_{PH}  R/S  1.44 00 
Compute resulting frequency  A  2.57 03 
Other Uses for this Program
The oscillator design facilitated by this program consists of two parts, a comparator with hysteresis, and a capacitor being charged and discharged by the comparator output through a resistor. The equations describing the comparator aspect of the circuit are not affected by those describing the behaviour of the resistorcapacitor network, so the program can be used to design such comparators for other applications.
Here is a brief example of using this program to design a comparator: Assume we want to design a comparator operating from a +/12V supply, whose output goes low when the voltage exceeds +2V, and goes high when the voltage subsequently drops below 3V. Assume the op amp used has an output that can swing to within 0.7V of the voltage limits. Use a 10kΩ resistor for R_{1}. Follow these steps to solve the problem:
Description  Keystrokes  Display 

Enter power supply voltages  12 CHS ENTER 12 a 
12.0 00 
Enter low and high level output voltages  11.3 CHS ENTER 11.3 b 
11.3 00 
Enter R_{1}  10 EEx 3 d 
10.0 03 
Enter desired lower and upper switching points  3 CHS ENTER 2 e 
3.00 00 
Compute value of R_{2}  C  8.98 03 
Compute value of R_{3}  D  16.7 03 
Now select the closest realworld resistor values for R_{2} and R_{3} and determine how that affects the switching points:
Description  Keystrokes  Display 

Enter new value for R_{2}  9.1 EEx 3 C 
9.10 03 
Enter new value for R_{3}  16 EEx 3 D 
16.0 03 
Compute resulting lower switching point  e  3.03 00 
Compute resulting upper switching point  R/S  2.16 00 
Additional RealWorld Considerations
The mathematical model used as the basis of this program assumes that V_{OL} and V_{OH} are constant, regardless of load. For sufficiently low current, this is close enough to true to be ignored. Thus it is important to use fairly high resistor values for R_{3} and R_{4} (10kΩ or bigger to be on the safe side). If the value of R_{3} computed by the program is too low, start with a higher value for R_{1}. Similarly, if the value computed for R_{4} is too low, use a lower value for C_{1}.
Some opamps have an opencollector output. This means that when the output is low, it is pulled low through an output transistor, but when the output is high, it is simply floating. Thus, a pullup resistor is needed to pull the output high. The chosen pullup resistor must meet two requirements:

It must have a highenough resistance that the output transistor can overcome the pullup current when the output is low.

It must have a lowenough resistance that it is not so large a percentage of the resistance of R_{3} or R_{4} that it throws off the solution.
For the LM339 comparator that I often use in my designs, I’ve found that a 1kΩ resistor works well, together with R_{3} and R_{4} values about 100 times as much. As described above, use a higher value for R_{1} to achieve a higher value for R_{3}, and use a lower value for C_{1} to achieve a higher R_{4}.
Program Listing
Line  Instruction  Comments 

01♦  LBL “OSC”  
02♦  LBL a  Store V_{NEG} and V_{POS} 
03  STO 06  V_{POS} 
04  x↔y  
05  STO 05  V_{NEG} 
06  x↔y  Fall through and initialize V_{OL} and V_{OH} to V_{NEG} and V_{POS} 
07♦  LBL b  Store V_{OL} and V_{OH} 
08  CF 22  
09  STO 08  V_{OH} 
10  x↔y  
11  STO 07  V_{OL} 
12  −  Initialize V_{PL} and V_{PH} 
13  3  
14  ÷  (V_{OH}–V_{OL})/3 
15  RCL 07  
16  x↔y  
17  +  
18  STO 11  Set V_{PL} = V_{OL} + (V_{OH}–V_{OL})/3 
19  RCL 08  
20  LASTx  
21  −  
22  STO 12  Set V_{PH} = V_{OH} – (V_{OH}–V_{OL})/3 
23  CF 01  
24  RCL 08  Leave V_{OL} and V_{PH} on stack as feedback to user 
25  RCL 07  
26  RTN  
27♦  LBL c  Store C_{1} 
28  CF 22  
29  STO 13  
30  RTN  
31♦  LBL d  Store R_{1} 
32  CF 22  
33  STO 01  
34  RTN  
35♦  LBL e  Store or compute (if necessary) V_{PL} and V_{PH} 
36  FS?C 22  If data entered, store new V_{PL} and V_{PH} 
37  GTO 09  
38♦  LBL 01  Otherwise, compute V_{PL} and V_{PH} if necessary 
39  FS? 01  Need to compute V_{PL} and V_{PH}? 
40  GTO 08  
41  RCL 12  Recall alreadyuptodate V_{PL} and V_{PH} 
42  RCL 11  
43  RTN  
44  RCL 12  If user presses R/S after seeing V_{PL}, display V_{PH} 
45  RTN  
46♦  LBL 08  Recompute V_{PL} and V_{PH} 
47  RCL 01  
48  RCL 03  
49  ×  
50  STO 14  
51  RCL 02  
52  RCL 03  
53  ×  
54  STO 10  
55  +  
56  RCL 02  
57  RCL 01  
58  ×  
59  STO 09  
60  +  
61  1/x  
62  STO 15  
63  RCL 05  
64  ×  
65  RCL 14  
66  ×  
67  RCL 15  
68  RCL 06  
69  ×  
70  RCL 10  
71  ×  
72  +  
73  STO 14  Partial result common to V_{PL} and V_{PH} 
74  RCL 15  
75  RCL 09  
76  ×  
77  STO 15  End of computation common to V_{PL} and V_{PH} 
78  RCL 07  Compute V_{PL} 
79  ×  
80  +  End of computation of V_{PL} 
81  RCL 15  Compute V_{PH} 
82  RCL 08  
83  ×  
84  RCL 14  
85  +  End of computation of V_{PH}; V_{PL} is in Yregister 
86♦  LBL 09  Store entered or computed V_{PH} and V_{PL} 
87  STO 12  Store V_{PH} 
88  x↔y  
89  STO 11  Store V_{PL} 
90  CF 01  V_{PL} and V_{PH} are now up to date 
91  RTN  
92  RCL 12  If user presses R/S after seeing V_{PL}, display V_{PH} 
93  RTN  
94♦  LBL B  Compute duty cycle 
95  CF 22  
96  XEQ 07  Get numerator and denominator (also used for computing R_{4} or f) 
97  LASTx  Numerator 
98  x↔y  
99  ÷  
100  RTN  
101♦  LBL 07  Compute denominator of duty cycle, leaving numerator in LSTx 
102  XEQ 01  Recompute V_{PL} and V_{PH} if necessary; leaves V_{PH} in X, V_{PL} in Y 
103  RCL 08  Compute first half of denominator 
104  −  
105  RCL 12  
106  RCL 08  
107  −  
108  ÷  
109  LN  
110  RCL 12  Compute second half of denominator (which is also the numerator) 
111  RCL 07  
112  −  
113  RCL 11  
114  RCL 07  
115  −  
116  ÷  
117  LN  
118  +  Combine two halves, leaving numerator in LSTx 
119  RTN  
120♦  LBL A  Store or compute f 
121  FS?C 22  
122  GTO 00  
123  XEQ 07  Get denominator (also used for computing R_{4} and duty cycle) 
124  RCL 04  Multiply by R_{4} and C_{1} 
125  ×  
126  RCL 13  
127  ×  
128  1/x  
129♦  LBL 00  Store entered or computed f 
130  STO 00  
131  RTN  
132♦  LBL C  Store or compute R_{2} 
133  FS?C 22  
134  GTO 02  
135  XEQ 05  Compute numerator of R_{2} 
136  RCL 06  Compute denominator of R_{2} 
137  XEQ 06  
138  ÷  
139  STO 02  Store computed R_{2} 
140  RTN  
141♦  LBL 02  Store R_{2} and invalidate V_{PL} and V_{PH} 
142  STO 02  
143  SF 01  Must recompute V_{PL} and V_{PH} for userdefined R_{2} 
144  RTN  
145♦  LBL D  Store or compute R_{3} 
146  FS?C 22  
147  GTO 03  
148  XEQ 05  Compute numerator of R_{3} (same as R_{2}) 
149  RCL 06  Compute denominator of R_{3} 
150  RCL 05  
151  −  
152  ÷  
153  RCL 11  
154  RCL 12  
155  −  
156  ÷  
157  STO 03  Store computed R_{3} 
158  RTN  
159♦  LBL 03  Store R_{3} and invalidate V_{PL}h and V_{PH} 
160  STO 03  
161  SF 01  Must recompute V_{PL} and V_{PH} for userdefined R_{3} 
162  RTN  
163♦  LBL E  Store or compute R_{4} 
164  FS?C 22  
165  GTO 04  
166  XEQ 07  Get denominator (also used for computing f or duty cycle) 
167  RCL 00  
168  ×  
169  RCL 13  
170  ×  
171  1/x  
172♦  LBL 04  Store entered or computed R_{4} 
173  STO 04  
174  RTN  
175♦  LBL 05  Compute numerator common to R_{2} and R_{3} 
176  XEQ 01  Recompute V_{PL} and V_{PH} if necessary 
177  RCL 05  
178  XEQ 06  
179  RCL 01  
180  ×  
181  CHS  
182  RTN  
183♦  LBL 06  Compute (V_{OL} – V_{PL} – V_{OH} + V_{PH}) * X + V_{OH} * V_{PL} – V_{PH} * V_{OL} 
184  RCL 07  
185  RCL 11  
186  −  
187  RCL 08  
188  −  
189  RCL 12  
190  +  
191  ×  Multiply (V_{OL} – V_{PL} – V_{OH} + V_{PH}) by V_{POS} or V_{NEG} (now in Y) 
192  RCL 08  
193  RCL 11  
194  ×  
195  +  
196  RCL 12  
197  RCL 07  
198  ×  
199  −  
200  RTN 
Registers and Flags
Register  Use 

00  Frequency (Hz) 
01,02,03,04  Resistors R_{1}, R_{2}, R_{3}, and R_{4} (Ohms) 
05,06  V_{NEG} and V_{POS} (Volts) 
07,08  V_{OL} and V_{OH} (Volts) 
11,12  V_{PL} and V_{PH} (Volts) 
13  Capacitor C_{1} (Farads) 
09,14,15,10  Temporary registers 
Flag  Meaning 

01  V_{PL} and V_{PH} need to be recomputed 
22  User supplied input 
Revision History
2009May25 — Initial release of HP41C/CV/CX version.
2009Jun11 — Fixed a bug where the data entry flag sometimes wasn’t cleared even though there had been no data entry.
2015Jun23 — Fixed a bug in the subroutine for computing the denominator of the duty cycle, wherein V_{PL} and V_{PH} were accidentally interchanged. Bug was in website listing only, not in original program.
Related Articles
If you've found this article useful, you may also be interested in:
 OpAmp Gain and Offset Design with the HP41C Programmable Calculator
 LowSensitivity SallenKey Filter Design with the HP41C Programmable Calculator
 LowSensitivity SallenKey Filter Design with the HP67 Programmable Calculator
 OpAmp Gain and Offset Design with the HP67 Programmable Calculator
 OpAmp Oscillator Design with the HP67 Programmable Calculator
 Resistor Network Solver for the HP67 Programmable Calculator
 A Matrix MultiTool for the HP 35s Programmable Calculator
 Curve Fitting for the HP 35s Programmable Calculator
Buy Stefan a coffee! If you've found this article
useful, consider
leaving a donation to help support
stefanv.com
Disclaimer: Although every effort has been made to ensure accuracy and reliability, the information on this web page is presented without warranty of any kind, and Stefan Vorkoetter assumes no liability for direct or consequential damages caused by its use. It is up to you, the reader, to determine the suitability of, and assume responsibility for, the use of this information. Links to Amazon.com merchandise are provided in association with Amazon.com. Links to eBay searches are provided in association with the eBay partner network.
Copyright: All materials on this web site, including the text, images, and markup, are Copyright © 2022 by Stefan Vorkoetter unless otherwise noted. All rights reserved. Unauthorized duplication prohibited. You may link to this site or pages within it, but you may not link directly to images on this site, and you may not copy any material from this site to another web site or other publication without express written permission. You may make copies for your own personal use.