Chapter 8
Counters
8-4
ni.com
Controlling the Direction of Counting
In edge co
u
nting applications, the co
u
nter can co
u
nt
u
p or down. Yo
u
can
config
u
re the co
u
nter to do the following:
•
Always co
u
nt
u
p
•
Always co
u
nt down
•
Co
u
nt
u
p when the Co
u
nter
n
B inp
u
t is high; co
u
nt down when it
is low
For information abo
u
t connecting co
u
nter signals, refer to the
section.
Pulse-Width Measurement
In p
u
lse-width meas
u
rements, the co
u
nter meas
u
res the width of a p
u
lse on
its Gate inp
u
t signal. Yo
u
can config
u
re the co
u
nter to meas
u
re the width
of high p
u
lses or low p
u
lses on the Gate signal.
Yo
u
can ro
u
te an internal or external periodic clock signal (with a known
period) to the So
u
rce inp
u
t of the co
u
nter. The co
u
nter co
u
nts the n
u
mber
of rising (or falling) edges on the So
u
rce signal while the p
u
lse on the Gate
signal is active.
Yo
u
can calc
u
late the p
u
lse width by m
u
ltiplying the period of the So
u
rce
signal by the n
u
mber of edges ret
u
rned by the co
u
nter.
A p
u
lse-width meas
u
rement is acc
u
rate even if the co
u
nter is armed while
a p
u
lse train is in progress. If a co
u
nter is armed while the p
u
lse is in the
active state, it waits for the next transition to the active state to begin the
meas
u
rement.
Single Pulse-Width Measurement
With single p
u
lse-width meas
u
rement, the co
u
nter co
u
nts the n
u
mber of
edges on the So
u
rce inp
u
t while the Gate inp
u
t remains active. When the
Gate inp
u
t goes inactive, the co
u
nter stores the co
u
nt in a hardware save
register and ignores other edges on the Gate and So
u
rce inp
u
ts. Software
then reads the stored co
u
nt.