A Simplified Analog Computer in Hardware and a C++ Simulation
User Rating: / 4
Written by Bryce Ringwood   

Now that Op Amps have been, to some extent, explained, I would like to share my simple analog computer experiment with you. Just about the first program anybody writes for an analog computer, is that of "Simple Harmonic Motion". It is the motion that results when the acceleration of a mass is proportional to the restoring force. Examples are a sprung mass and a simple pendulum.

What we will do is to simulate the problem using hardware, and then look at the same problem using  C++ objects as virtual hardware. Here's a sketch of the simple pendulum.


Simple Pendulum - Simple Harmonic Motion

The simple pendulum has an interesting characteristic - namely, it doesn't swing until you give it an initial displacement or you give it an initial velocity by firing a bullet at it. Once  you have got it going, it keeps swinging in accordance with the above second order differential equation, which I don't remember how to solve, nor is it particularly obvious how to solve it with a digital computer - traditionally, it would be solved by some numerical method.

What is far more interesting, is to simulate the problem, then we can shorten the pendulum, change the initial deflection and so on to see how it might perform. Simulations are great, because they help you think about a problem, even if they are not 100% accurate - as in this problem where we approximated the value of the sine.

The trouble comes when you place too much faith in your simulations. Let's look at some analog computer components.

The analog computer

The analog computer consists of a set of "building blocks" which can be wired together to simulate the system under investigation. An analog computer program is not a set of statements which can be executed in sequence to solve a problem, it rather resembles a circuit diagram with settings described in accompanying notes. In my introdution to this section, I made reference to the EAI PACE (Precision Analog Computing Equipment)computer which I programmed in the 1960s, so some of my descriptions are in "past tense".

Coefficient Setting Potentiometer

This was a ten-turn potentiometer with turns counting dial. The top end of the potentiometer is connected to the input signal, the slider is connected to the next stage, and the third terminal is connected to ground. For the computer to be described, I just used the pot supplied with the Arduino kit.

Coefficient Setting Potentiometer

Summer and Integrator

The analog computer integrator often has several inputs with diffrent gains. The practical integrator also has an "initial conditions" setting potentiometer, and the PACE also had balance or nulling pots. The OP07 amplifier used here doesn't need nulling pots, but you can include them if you want. If you are planing on a more permanent computer than the one her, I would use a relay to place the initial charge on the integrator capacitor.

Integrator Programming Symbol

Summing Amplifier

The summing amp inverts the sum of the inputs. No difference from the inverter.


See above. We normally write the gain of the input pin on the program sheet.

Inverting amp


The PACE computer had both servomultipliers and quarter-square multipliers. They are used to multiply two dynamic quantities. The servomultiplier is fairly obvious - a servo driving a potentiometer. One input goes to the servo amp, the other goes to the pot.

The PACE also had a "Quarter Squares Multiplier", which was fast, but not particulaly accurate. For home/hobby use, the Analog devices AD633 analog multiplier might work.

Function Generator

The pendulum problem is an example of a non-linear system - we should include a sine function. This used to be accomplished using a "Diode Function Generator" or DFG.

Programming Pegboard

The pegboard is used to plug jumpers from device outputs to inputs and allow the simulation to be built up. The pegboard can be removed so that someone else can provide a different program on another pegboard. I'm not sure how this could be implemented on a home-made computer.


The voltmeter is OK for setting initial conditions and for system diagnosis. It was fairly essential (and was always breaking down on the PACE computer.) See the section on digital voltmeters.


The servoplotter provides an image that represents the response of the system under test.  This is really useful. Some computers have an oscilloscope, which provides only a fleeting glimpse of what is happening. The servoplotter used here was rescued from the company's junk heap and restored to working order.

High Speed Printer

I never found this to be useful at all. It just printed out numbers at intervals without giving any representation of what they meant.

Power Supply

Although op-amps are fairly immune to variations in power supply voltage, it is a good idea to have well stabilised positive and negative supplies. I ran the analog computer circuit from a regulated (using 7812/7912) 12 volt supply.

Solving the Pendulum Program using a Simple Analog Computer

The analog computer was assembled using OP07 op-amps. To make the system operate in real time, 1uF feedback caps were used in the integrators. 1Meg 1% resistors were used throughout. The inverter also used 1Meg resistors. The power supply was decoupled with 10u electrolytic caps. Construction was done in a very short time using the Arduino development board (ideally suited to this sort of temporary project).

The output to the servoplotter or oscilloscope is taken from the output of the second integrator.

Simple Second Order SystemReferring to the diagram below (the program) you can see how although the differential equation is expressed in the normal fashion (i.e. as differentials), when the system is programmed, we can see how the inputs to the integrators are the differentials.

Also, I have turned the equation around a little bit, so the potentiometer value represents g/l (not l/g).

There is no "initial conditions relay". Initial conditions are obtained by smartly charging/shorting the caps and plugging them in to the board.









Running The Program

After a false start (I'd wired the the inverting and noninverting inputs the wrong way round), the system was attached to the servoplotter and powered up. As expected, it did absolutely nothing - corresponding to a pendulum with no initial displacement.

The second integrator cap was charged and replaced in the circuit. Here is the result:

The simulation takes place in real-time, so there is plenty of time to twiddle the coefficient setting pot. Reducing the g/l value correctly lengthens the period.

When the servoplotter runs at 1cm/sec and the coefficient pot is set to 1, the period of the sine wave measures correctly (almost)6.25 cm. It should read 2*pi (6.28). To be honest, I think this is a bit of a "fluke" even though I selected the integrator caps to be as near the correct value as possible.

The oscillations die down after about 45 minutes.

This is a picture of the servoplotter:

Watanabe Servoplotter

Using a Digital Computer

The analog computer program consists of objects (integrators, inverters) wired together - so it should be simple to implement a C++ program that resembles the analog computer - right?

// shm.cpp : Defines the entry point for the console application.

#include "stdafx.h"
using namespace std;
// These contain definitions for cin, cout etc;
#include <iostream>
#include <iomanip>
#include <ostream>

// Simple Harmonic Motion Simulation
class  integrator
 integrator();   // Default constructor - every class needs one
 integrator(double step, double initial);
 double sum(double newval);

 double step;
 double value;
 double initial;


integrator::integrator(double step,double initial)
 integrator::step = step;
 value = initial;
// This is the code for integrating
double integrator::sum(double val)
 return value =   value - val*step;

//Finally, the actual program, in which we run the pendulum
int _tmain(int argc, _TCHAR* argv[])
 double step = 0.01;
 double displacement = 100.;
 double u = 1.0;    // Length = g
 integrator int1(step , 0.0);
 integrator int2(step, displacement);

 for (int i = 0 ; i < 5000 ; i++)
  displacement = int2.sum( int1.sum (-u*displacement));
  cout << "Displacement: " << displacement << endl;
 return 0;



Example Code for Simple Harmonic Motion

Unfortunately, the output resembles that "High Speed Printer" output.  It really needs graphical output, but graphics programming is beyond the scope of this feature. (The reason being that I still program using Microsoft Foundation Classes - MFC which is out of date.) Here is what it would look like:

Plot of Simple Pendulum Swing


Here we created a real and a virtual analog computer. The important thing to notice is the parallel between real objects made of silicon, wires caps etc. and virtual objects that can do the same thing. If you don't know, or are shaky on the subject of calculus, take a look at the integrator coding, as it explains exacly what the process of integration entails.

You could also get a book like "Numerical Recipes" and see how to solve the differential equation for SHM.( It is really easy to solve by inspection.)

Next you might want to take into account air-resistance or "damping".

Other simulation programs include "sphinxes' , "IThink/StellaII"(Commercial) and for electrical problems, there's LtSpice. There's also a mobile phone app for Android. (Which I can't remember the name of.)

The analogmuseum is also really interesting to visit if you like this sort of thing... 

Joomla template by a4joomla