main content

measure frequency using ni devices -凯发k8网页登录

this example shows how to measure frequency to determine rate of flow of fluid using a flow sensor. the sensor generates a digital signal with frequency that correlates to the rate of flow of fluid.

create a counter input channel

use daq to create a dataacquisition and addinput to add a counter input channel with frequency measurement type. for this example, use compactdaq chassis ni c9178 and module ni 9402 with id cdaq1mod5.

dq = daq("ni");
ch = addinput(dq,"cdaq1mod5", "ctr0", "frequency");
ch
ch = 
    index    type      device       channel    measurement type    range          name      
    _____    ____    ___________    _______    ________________    _____    ________________
      1      "ci"    "cdaq1mod5"    "ctr0"       "frequency"       "n/a"    "cdaq1mod5_ctr0"

determine the terminal of the counter input channel

to connect the input signal to the correct terminal, examine the terminal property of the channel. the terminal is determined by the hardware.

ch.terminal
ans =
    'pfi1'

measure frequency

to determine if the counter is operational, input a single scan while the motor is rotating.

read(dq)
ans =
  timetable
    time     cdaq1mod5_ctr0
    _____    ______________
    0 sec         100      

monitor frequency over time

use the hardware clock to acquire multiple counter measurements over time. ni counter devices require an external clock. by adding an analog input channel for a module on the same chassis, the session shares an internal clock with both modules.

dq = daq("ni");
dq.rate = 1;
addinput(dq,"cdaq1mod1", "ai0", "voltage");
addinput(dq,"cdaq1mod5", "ctr0", "frequency");
data = read(dq, seconds(10));
plot(data.time, data.cdaq1mod5_ctr0);

网站地图