This discussion shows how to use a 200 mV Panel Meter with a Basic Stamp. This allows you to display such quantities as voltage, temperature, pH, RPM or compass bearing. This approach uses only a single pin on the Stamp and requires a minimum of code an d is thus a nice alternative to an LCD character display which uses many more pins and requires a considerable amount of code.
200 mV Panel meters are available from most discount electronics firms for less than $10.00. They are self contained voltmeters with an input impedance greater than 100 Meg and are capable of displaying to 200.0 mV. They may be powered from +9 VDC with a typical drain of 1 mA.
This concept of displaying quantities on a 200 mV panel meter is discussed in a separate discussion dealing with the Parallel Port. In that application, a quantity was represented in 8-bit format and output to a digital to analog converter so as to gene rate a suitable voltage which is then applied to the 200 mV panel meter. In this discussion, the PWM capability of the stamp is used to generate the voltage representing the quantity, and thus is considerably simpler. However the parallel port discussio n contains a great deal of information on panel meters and the reader may find it useful.
The Stamp's PWM command is of the form;
PWM pin, duty, cycles
Pin identifies the I/O terminal on the Stamp.
Duty ranges from 0 to 255 and specifies the analog level in the range of 0.0 to 5.0 V. The output voltage is duty/255 * 5V. For example, to obtain voltages of 0.0, 2.5 and 5.0, duty would be set to 0, 128 and 255, respectively.
Cycles relates to the number of 5 ms intervals that the PWM signal is to appear on the pin.
Use of the Panel Meter with PWM Command.
Returning now to the 200 mV panel meter, Figure #1 illustrates how a simple voltage divider might be added to the panel meter. Resistors RA and RB have been calculated such that when +5.00 V is applied to the input of the divider, 200 mV is present on th e panel meter. In fact, all of the panel meters I have seen include the pads and holes to mount the resistors on the panel meter itself.
I found that values of resistance RA less than 200K caused a noticeable drop in the capacitor voltage. Thus, I scaled the values up such that the resistance seen by the capacitor is greater than 2.0 Meg; i.e., RA = 2.4 Meg and RB = 100 K.
Thus, one might now think of the "duty" as being the fraction of 0.2 VDC. That is;
display = duty / 255 * 0.2
In fact, the decimal point on the panel meter is set by inserting a strap on the assembly, such that the reading is 2.0, 20.0 or 200.0 or 2000. Thus;
display = duty / 255 * X
where X is 2.0, 20.0, 200.0 or 2000 as determine by the strapping of the decimal point.
Temperature (0 to 150).
Consider a temperature application where the maximum temperature is 150 degrees. The panel meter would be strapped such that 200 mV appears as 200. Duty is then calculated;
duty = T * 255 / 200 pwm 0, duty, 10
pH (0.0 to 14.0).
Consider pH. pH ranges from 0 to 14. The decimal point on the meter would be strapped for 20.0 when "duty" is 255. Assume the pH has been measured using some sensor arrangement and ten times the pH is in word pH_10;
duty = pH_10 * 255 / 200 pwm 0, duty, 10
Assume the pH is 7.2. pH_10 is then 72 and duty is then 92. This then causes 92/255 * 5.0 to appear across the capacitor on the output of the stamp and 92/255 * 0.2 V to appear on the panel meter. However, as the meter has been strapped such the 0.2V a ppears to be 20.0, 92/255 * 20.0 or 7.2 appears on the panel display.
The general structure of a routine to continually display the result of a pH measurement is illustrated in Program PANEL.BAS.
' Program PANEL.BAS ' ' Example illustrates how to display a quantity on a 200 mV panel meter. ' This example displays pH readings in range of 0.0 to 14.0. ' ' Peter H. Anderson, MSU, Dec 31, '96 dirs=%00001111 symbol pH_10 = w3 symbol data = w2 top: gosub take_pH_reading data = pH_10*255/200 pwm 0, data, 255 pause 5000 goto top take_pH_reading: ' Code for taking pH measurement would appear here. In this routine ' I simply set pH_10 to a constant. pH_10 = 72 'pH is 7.2 return
Compass Bearing (0 to 359).
Consider a compass bearing in the range of 0 to 359. Strap the meter for 2000 (no decimal point).
duty = compass * 17 / 200 * 15 / 10 pwm 0, duty, 10
Note that in the above, I multiplied by 255, by first multiplying by 17, and later, after dividing by 200, by 15 (17 X 15 = 255). This was necessary as compass * 255 could cause an overflow.
Assume a compass bearing of 359. Duty is then calculated from the above as 45. Thus, the voltage on the capacitor on the output of the Stamp is;
45/255 * 5.0
The voltage on the 200 mV panel meter (after the voltage division) is
45/255 * 0.2 = 0.0353
This would then be interpreted as 353 degrees. Note that this is a full 6 degrees off. This arises from quantizing error.
Going back to the temperature example, the range of 0 to 200 is quantized into 256 bands. Thus, the best resolution we can obtain is 200 / 256 or 0.78. Thus, the quantizing error associated with the reading is 0.78 degrees.
In the case of pH, the range of 0 to 20 is quantized into 256 bands resulting in a quantizing error of 0.078.
The compass is an extreme case. We are taking 2000 and quantizing it into 256 bands. Thus, the quantizing error is 2000/256 or in this case 7.8 degrees. And I don't have a good solution. If the user were provided with an LED to indicate whether the re ading was relative to East or to West of North, the compass bearing could then be represented in the range of 0 to 180. This would permit strapping for 200.0 and the quantizing error would be a scant 0.78 degrees.