Data AcQuisition And Real-Time AnalysisScope - Spectrum - Spectrogram - Signal Generator
Software for Windows
Science with your Sound Card!
Contact us about
Custom Meter Macros
(See also Custom Meters Command Summary.)
Daqarta includes built-in support for a resizeable Voltmeter, Sound Level (SPL) Meter, and Frequency Counter. But you can also display any value, expression, or indeed any string expression, as a custom resizeable meter.
There are 4 custom meters available, Mtr0 to Mtr3. Usage is similar to that for Message Macros:
Mtr0=P + " Watts"
If variable P is 1.234, this would display:
You can use all the formatting options described under String Variables and Expressions. These allow you to display values with specified decimal places, multiple values at fixed columns, and multiple lines.
As for message macros, you can also set the meter title, colors for text and background, and initial position. In addition, you can also set the initial font height. (See Custom Meters Command Summary).
In fact, Custom Meters can be used as multiple message macros, perhaps with different colors for quick visual distinction.
Alternatively, you can show values that are available from Daqarta but not normally displayed, such as Time, or Total (while the Frequency Counter is showing Hz, RPM, or msec), or those that are normally not even available, such as DiskSpace.
But the most powerful use of custom meters is to show values that you derive via computation from other values. See for example the Phase Meter, THD Meter, and IMD Meter macro mini-apps that are included with Daqarta.
Usually, as in the above examples, you will want the meter to be updated automatically by installing a Multitasking macro that performs the calculations and updates the meter on each trace update. (Or less often... see Meter Time Constants below.)
As a simple example, suppose you want a readout of the instantaneous power delivered to a loudspeaker that is being driven with an arbitrary signal like music.
You'll need an Input Range and Limiter Circuit if you connect to an amplifier rated at more than a few watts, and you must insure that the amp has speaker terminals that use a common ground (not a "bridge" type).
Knowing the RMS Volts at the speaker terminals, you can use the speaker manufacturer's stated "nominal" impedance (typically 4 or 8 ohms) as an approximate resistance R, and compute power P in watts. You can then display it on Mtr0 using a macro which we'll call _Watt_Task:
P = Volts^2 / R Mtr0=P + " Watts"
Important: Before this or any macro is installed as a real-time task (which may run a hundred times per second or more), you should run it as a normal macro to check for bugs or other unexpected behavior.
Once you are satisfied that it works properly, you can create a "parent" macro called Spkr_Watts that installs _Watt_Task as a multitasking macro, after first opening the Voltmeter with the proper channel and mode, setting the desired R value, and setting a title and color for the meter.
If you don't want the Voltmeter to stay on-screen, you can minimize it by adding VoltDlg#m=1 after the first line above.
The simple _Watt_Task macro should also be enhanced to allow you to cancel the meter task whenever the meter display is closed via its [x] button.
P=Volts^2 / R Mtr0=P(3_3) + " Watts" IF.Mtr0?E=1 Task="-_Watt_Task" ENDIF.
If you want to close the Voltmeter at the same time, include VoltDlg=0 in the IF block.
The P(3_3) term specifies that the displayed value will have up to 3 integer digits and 3 decimal places. The underscore indicates that if there are less than 3 integer digits, spaces will be used to pad the display so that the decimal position stays constant as the power reading changes. See Decimal Display Format under String Variables and Expressions.
Some custom meter applications may not require updates on every trace update, and in fact that may just cause a blur of digits. One simple way to handle this is to maintain a counter and only update the meter every Nth time the task runs, as discussed in Multitasking Macros.
A better way is to average the readings using a "time constant" exponential averaging scheme. The basic idea is that on every update, you subtract some fraction of the running average and add the same fraction of the new value. If the running average and the new value are equal, there is no change. If the new value suddenly changes, the running average moves toward it... slowly if the fraction is small, rapidly if the fraction is large.
Let A be the running average, which may be set to zero by the setup macro. Let B be the latest value obtained by the task macro math, and let C be the time constant. Then the task macro updates A before displaying it, using:
A=A - (A / C) + (B / C)
This can be rearranged to:
A=A + (B - A) / C
The time constant C is a measure of the response time to a sudden change. A large time constant means that the meter will take a long time to fully respond to a change, which is equivalent to a low-pass filter with a low cutoff frequency.
You will probably want to use a time constant in the range of 10 to 100.
With large time constants you get a well-filtered response, but there may be an unacceptable lag when you first activate the meter, as A goes from its initial value of zero up to the true average value. If this is a problem, then instead of zeroing A you can just grab the current value of the input and use that as a starting point. Unless the input is extremely noisy, this instantaneous value should be closer to the true average than a default of zero.
Spkr_Watts macro with time constant C:
VoltDlg=1 VoltCh=LI VoltMode=RMS R=8 Mtr0="<<Speaker Power" Mtr0="<C(255,0,0)" C=100 A=Volts^2 / R Task="_Watt_Task"
_Watt_Task macro with time constant C:
P=Volts^2 / R A=A + (P - A) / C Mtr0=A(3_3) + " Watts" IF.Mtr0?E=1 Task="-_Watt_Task" ENDIF.
Questions? Comments? Contact us!We respond to ALL inquiries, typically within 24 hrs.
Over 35 Years of Innovative Instrumentation
© Copyright 2007 - 2021 by Interstellar Research
All rights reserved