Data AcQuisition And Real-Time AnalysisScope - Spectrum - Spectrogram - Signal Generator
Software for Windows
Science with your Sound Card!
Contact us about
Sound Card Custom Frequency Counter Mini-App
The Custom_Freq macro mini-app included with Daqarta provides a separate custom meter display (in addition to the normal Frequency Counter) that shows the current frequency, plus the lowest, highest, and average frequency since the last reset. You can reset it at any time by hitting the 'r' key.
Although this mini-app may appear to be specific to frequency-based measurements, it is actually intended as a prototype generic meter (and data logger) that can be modified to display any numeric values that can be computed from sound card input data, including volts, milliamps, ohms, dB, or something more exotic.
You can open this Help topic by right-clicking anywhere in the custom meter display.
You may need to adjust the Trigger Source, Slope, Level, and Hysteresis just as for normal Frequency Counter operation. Of course, you will also need to provide an Input or Generator signal to be measured.
When you are done using Custom_Freq you can exit (and uninstall _Custom_Freq_Task) by closing the custom display via its [x] button, or by attempting to run Custom_Freq again.
The Custom_Freq macro script includes provisions for supplying a custom calibration factor G and offset K to apply linear corrections to frequency readings. These can be used to compensate for inaccuracy in your sound card's internal reference clock, assuming you have a precision external frequency reference that you can use to set these values.
This scheme allows higher precision than provided by the Fcal option, though it is not quite so convenient to calibrate because it lacks Fcal's, High, Low, and Units controls. Use Fcal for normal sensor work with less than about 5 decimal places of resolution; use Custom_Freq for up to 9 places.
You can easily add data logging to Custom Freq, but you can't use the simple WaitSecs method shown in the Data Logging topic because "Wait"-type timer operations aren't allowed in multitasking Tasks. Instead, you use the High Resolution Timer command, which returns the elapsed time since Windows started. Each time the task runs (once per Trace Update Interval) the timer is read and compared to the time stored at the previous data log update; when the different exceeds the desired update interval, the log is updated and the current time is stored as the new 'previous' value.
This data logging code has already been included but commented out. Just remove the leading semicolons from the ;X=0 line and the ;LogTxt line (including its continuation) from Custom_Freq, and from the indicated section in _Custom_Freq_Task. The log update interval has been set to 1.00 sec in the latter's IF.(Timer - X)=>=1.00 line; change the value as desired.
This will write to the default DqaLog.TXT file, which is in the Documents - Daqarta - UserData folder unless you used a custom Daqarta installation, in which case it would typically be in Programs - Daqarta - UserData.
If you want to log to another file, see Changing the Log File Name in the Log Files topic.
You can modify Custom_Freq to compute other values, including non-frequency values, depending on your needs. This can be as complex as desired. For example, you can apply a non-linear curve which you load into a Macro Array (Buf0-7), then use with the Interpolation option discussed under Macro Array Math Operations.
You can easily create a Custom_Volts and _Custom_Volts_Task pair to do similar operations on voltage. The simplest way to do that is to copy Custom_Freq with a new name. Select it in the Macro List and click on Edit.
Change the Mtr0="<<Custom Frequency Counter" to Mtr0="<<Custom Voltmeter" or watever you want.
Change _Custom_Freq_Task to _Custom_Volts_Task (or whatever you want) in all 3 places; note that the first one has a leading '?' and the third has a leading '-' (negative sign).
Now hit the Save Macro button at the bottom. A prompt will appear asking if you want to 'Save as New' or 'Rename existing'. Click [Yes] to Save as New.
Now back in the macro list, scroll down to _Custom_Freq_Task and likewise edit its name to _Custom_Volts_Task (or whatever name you used above), and do the same in the Task line near the end of the macro.
On the first line, change F=Freq * G + K to F=Volts * G + K.
On the Task line at the end, change _Custom_Freq_Task to _Custom_Volts_Task, making sure to keep the '-' sign in front of it.
Now when you run the new Custom_Volts it will open the Voltmeter and report the current, highest, lowest, and average voltages. As with Custom_Freq, you can change the overall calibration via the G gain factor and K offset adjustment. These act on top of whatever Full-Scale Range and External Gain settings you may have for the main sound card calibration.
The same basic steps as above could be applied to make a custom Sound Level Meter.
Another approach that doesn't require opening a special option is to read the data that is being displayed on the screen. This not only reduces screen clutter, but allows special tailoring to your specific needs.
You can use the CursY and CursDotY macro functions to read the values under the solid and dotted cursors, respectively. You can manually adjust their positions, such as to read specific waveform or spectrum peaks.
If more than one channel is active, the above functions read from the channels selected for readout (solid and dotted may have different channels selected). You select channels manually via the little colored buttons at the left ends of each readout. CursChan and CursDotChan can be used to select via macro control.
You can read any active channel, whether selected for readout or not, via CursY?n and CursY?n, where n is channel number 0-3.
In Spectrum Peak Track mode you can use Curs to read the frequency of the largest peak, and CursY to read its magnitude.
You can use DeltY to read the Delta difference or Sigma energy between the two cursors. Sigma gives the RMS voltage included between two waveform points. In Spectrum mode it gives the included energy in dB, if the default Y-log power spectrum mode is active.
DeltX reads the X-axis difference between the cursor positions.
If you always need to read values from the same cursor positions, your macro can set them at the start via Curs for solid and CursDot for dotted.
Your macros can perform operations on waveform or spectrum data by using the Data Point Functions to read individual points. These allow you to specify the channel number and point to be read. For example, Wv(C,N) reads the waveform of channel C at sample point N for channels 0-3 and samples 0-1023.
Similarly, Sp(C,N) reads the spectrum magnitude for spectrum lines 0-511, and Av(C,N) reads the current waveform average for samples 0-1023 (except 0-511 for Histograms), or spectrum average for lines 0-511.
An entire waveform or spectrum can be copied to a Macro Array (Buf0 to Buf7), then manipulated with array math, including spectrum (FFT) operations, frequency counting, and edge/event/trigger detection.
For example, you could keep Daqarta in waveform display mode, while on each display update your macro task copies the waveform to a buffer, finds the FFT magnitude spectrum, integrates over a specified frequency band, and displays the energy in that band.
;<Help=H4914 G=1.00000000 ;Calibration gain factor K=0.00000000 ;Calibration offset TrigMode=Norm ;Normal Trigger mode FcountDlg=1 ;Open normal Freq Counter H=-1M ;High value init L=1M ;Low value init C=0 ;Averager count init T=0 ;Averager total init ;X=0 ;Data Log time Mtr0="<<Custom Frequency Counter" ;Meter title Mtr0="<H4914" ;This Meter Help topic ID Task="?_Custom_Freq_Task" ;Task status IF.Task=0 ;Not installed? ; LogTxt=n + "Time" + p20 + "Inst" + p40 _ ;Uncomment for ; + "High" + p60 + "Low" + p80 + "Avg" ; Data Log Task="_Custom_Freq_Task" ;Install ELSE. Task="-_Custom_Freq_Task" ;Else uninstall Mtr0= ;Remove meter ENDIF.
;<Help=H4914 F=Freq * G + K ;Correct Freq IF.F=>H ;Save new High? H=F ENDIF. IF.F=<L ;Save new Low? L=F ENDIF. IF.Key?r=1 ;Reset via 'r' key? T=0 ;Clear Total C=0 ;Clear Count H=-1M ;Less than lowest expected L=1M ;Higher than highest expected ENDIF. T=T+F ;Total of all Freq readings C=C+1 ;Count A=T / C ;Average Mtr0=F(0.9) +" Now" +n + H(0.9) + " High" +n _ + L(0.9) + " Low" +n + A(0.9) + " Avg" ;Uncomment for data logging: ;IF.Timer-X=>1.00 ;More than 1.00 sec elapsed? ; LogTxt=n + t + p20 + F(0.9) + p40 + H(0.9) _ ;Update data log ; + p60 + L(0.9) + p80 + A(0.9) ; X=Timer ;Update time ;ENDIF. IF.Mtr0?E=1 ;Meter closed? Task="-_Custom_Freq_Task" ;Uninstall Task if so ENDIF.
See also Macro Examples and Mini-Apps
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