Lesson 6 – Counters

advertisement
Counters
Topics
• Counter Overview
• Easy Counter VIs for:
– Event Counting
– Pulse Generation
– Pulse Measurement
– Frequency Measurement
• Position Measurement
Counter Signals
Counters accept and generate TTL signals
Maximum Rise/Fall Time = 50ns
+5.0 V
high
+2.0 V
+0.8 V
0V
indeterminate
low
Minimum Pulse Width = 10ns
Parts of a Counter
Gate
• Count Register
Out
Count Register
– Stores the current count
• Source
Source
– Input signal that changes the current count
– Active edge (rising or falling) of input signal changes the count
– Choose if count increments or decrements on an active edge
• Gate
– Input signal that controls when counting occurs
– Counting can occur when gate is high, low, or between various
combinations of rising and falling edges
• Out
– Output signal used to generate pulses
Counter Pins
• Counter gate and source are PFI pins
– PFI stands for Programmable Function Input
– Allows use of one pin for multiple applications
For Example
– Use pin 3 as digital trigger for analog input and counter gate
Counter Terminology
• Terminal Count
– Term for the last count before a counter reaches 0
– When counter reaches max count it starts over at 0
• Resolution
– The size of the counter register specified in bits
– Counter register size = 2(resolution) - 1
– Typical resolutions - 16, 24, 32 bit
• Timebase
– Internal signal that can be routed to the source
– Common timebases - 100kHz, 20MHz
Different Counter Chips
Less
F
e
a
t
u
r
e
s
More
• 8253 (16-bit)
– Used on Lab and 1200 Series Devices
• Am9513 (16-bit)
– Used on PC-TIO-10 and Legacy
Devices (i.e. AT-MIO-16F)
• DAQ-STC (24-bit)
– Used on E-Series Devices
– Created by NI
• NI-TIO (32-bit)
– Used on 660x Devices
– Created by NI
Counter Palette
• Easy VIs
– Built out of Intermediate VIs
+ Easy to use
- Less flexible
• Intermediate VIs
– Built out of Advanced VIs
+ Very Flexible
• Advanced VIs
– Building blocks for other levels
Easy VIs
Advanced VIs
Intermediate VIs
Easy VIs
• Perform basic counter operations
• Not suitable for more advanced applications
• Compatible with Am9513 and DAQ-STC
Count Events or Time
Generate Delayed Pulse
Generate Pulse Train
Measure Frequency
Measure Pulse Width or Period
Counter Applications
Event Counting
• Simple Event Counting
• Time Measurement
Pulse Generation
• Single Pulse Generation
• Pulse Train Generation
Pulse Measurement
• Period Measurement
• Pulse Width Measurement
Frequency Measurement
Position Measurement
Event Counting
• Active edges on source
signal increment the count
Simple Event Counting
Gate
– Active edge can either be
rising or falling
Out
Count Register
Source
Your
Signal
• Timebase has known frequency
– Time elapsed = (Count) x
(timebase period)
Time Measurement
Gate
Out
Count Register
Source
Timebase
Event Counting
• Count will increment for each rising edge on source
• You can change active edge to falling
• Counter will roll over when it reaches terminal count
– Terminal count = 2(Counter resolution) - 1
Counter Armed
Source
Count
0
1
2
3
TC-1 TC
0
Count Events or Time VI
• Source Edge
– Chooses active edge of
source signal (rising or
falling)
• Event Source/Timebase
– Chooses source signal
• Counter
– Chooses counter to address
• Start/Restart
– Set to TRUE to start/restart counter
• Stop
– Set to TRUE to stop counter
• Count
– Returns value stored in count register
• Seconds Since Start
– Time since counter started
Pulse Generation
• Generates a TTL signal on counter’s out pin
Single Pulse
Pulse Train
Gate
Out
Count Register
Source
Timebase
Single Pulse
or Pulse Train
Pulse Characteristics
High Polarity
Low Polarity
Pulse Polarity
Delay
Width
Delay
Pulse Period = Delay + Width
1
Pulse Frequency =
Pulse Period
Width
Duty Cycle =
Pulse Period
Width
Generate Delayed Pulse VI
• Timebase Source
– Internal or External
• Counter
– Chooses counter to
address
• Pulse Polarity
– High or Low
• Pulse Delay & Width
– Seconds if using internal timebase
– Cycles if using external timebase
• Actual Delay & Width
– May differ from desired values
because hardware has limited
resolution
Generate Pulse Train VI
• Pulse Polarity
– High or Low
• Counter
– Chooses counter to
address
• Number of Pulses
– Set to 0 for continuous
– Set to -1 to stop
• Frequency (Hz)
– 1/(Pulse Period)
• Duty Cycle
– (Width)/(Pulse Period)
• Actual Parameters
– May differ from desired values
because hardware has limited
resolution
Pulse Measurement
• Use a timebase with a known frequency to
measure characteristics of a unknown signal
Period Measurement
Pulse Width Measurement
Pulse Period
Width
Gate
Your
Signal
Out
Count Register
Source
Timebase
Period Measurement
• Count will increment for each rising edge on source
– Counting can either start and end on rising or falling edges
• Period of Gate = (Count) x (1/source frequency)
Armed
Yes
No
Gate
Source
Count
0
1
2
3
4
4
4
Pulse Width Measurement
• Count will increment for each rising edge on source
– Counting can start on either rising or falling edge
• Width of Gate = (Count) x (1/source frequency)
Armed
Yes
No
Gate
Source
Count
0
1
2
2
2
2
2
Measure Pulse Width or Period VI
• Counter
– Chooses counter to address
• Type of Measurement
– Measure high pulse width
– Measure low pulse width
– Measure period (rising edge
to rising edge)
– Measure period (falling edge
to falling edge)
• Timebase
– Routed to source
– DAQ-STC has choice of
100kHz or 20Mhz
• Pulse Width/Period (s)
– Returns value in seconds
• Valid
– False if counter rolls over
Frequency Measurement
Your Signal
Low Frequency
Measure Pulse Width
or Period
High Frequency
Measure Frequency
Low Frequency Measurement
Your Signal
Measure period and take the inverse
• Frequency = 1/Period
Low Frequency
Pros
• Only uses one counter
• Good at low frequencies
Cons
Measure Pulse Width
or Period
• Can see large error at high frequencies
due to a phenomenon called
synchronization error
Synchronization Error
• Gate period is exactly four source cycles
• Measurement could be off by +/- 1
GATE
SOURCE
Miss both edges
0
1
2
3
3
Miss one, catch one
0
1
2
3
4
Catch both edges
1
2
3
4
5
Effect of Synchronization error
• You can measure a frequency of F with error of 0.x
FMAX = FSOURCE - (FSOURCE/(1+0.x))
• If frequency you are measuring exceeds
acceptable error use Measure Frequency VI
High Frequency Measurement
Your Signal
Still Period Measurement except:
• Gate is known
High Frequency
– Pulse from another counter
• Source is your signal
Pro
• Works well at high frequencies
Con
• Uses two counters
Measure Frequency
High Frequency Setup
Single Pulse Generation
Gate
Pulse Width Measurement
Out
Count Register
Source
Timebase
Counter 0
Gate
Known
Pulse
Out
Count Register
Source
Counter 1
Your
Signal
• Frequency = (count of Counter 1)/(pulse width of Counter 0 Out)
• Synchronization error still exists in count of Counter 1
– Error = (+/-1)/(period of Counter 0 Out)
Measure Frequency VI
• Counter
– Chooses counter to address
• Gate Width (s)
– Desired length of pulse used
to gate the signal
– The lower the signal
frequency, the longer the
width must be
• Frequency (Hz)
– Returns value in Hertz
• Valid
– False if counter rolls over
NOTE: You must connect
Gate of chosen counter to
Out of other counter
Position Measurement
• With a transducer called a
quadrature encoder you can
measure position
• DAQ Signal Accessory has a
quadrature encoder
• NI-TIO is only counter chip
that directly supports
quadrature encoders
– Possible to measure quadrature
encoder with Am9513 and DAQSTC
How Does an Encoder Work?
Quadrature Encoder
Light Sensor
Light Source
Shaft
• Shaft and disk rotate
• Code track either
passes or blocks light
to sensor
• Light sensor creates
two pulse trains
Code Track
Channel A
Channel B
Rotating Disk
Quadrature Encoder
900 phase difference
Channel A
Channel B
Clockwise Rotation
900 phase difference
• Quadrature Encoders
produce two pulse trains 90
degrees out of phase
• Clockwise rotation
– Channel A leads Channel B
• Counter-Clockwise rotation
– Channel B leads Channel A
Channel A
Channel B
Counter-Clockwise Rotation
Up/Down Line
• DAQ-STC counters also have an up/down line
– DIO6 is up/down for counter 0
– DIO7 is up/down for counter 1
– TTL High = Count up
– TTL Low = Count down
Gate
U/D Count Register
Source
Out
DAQ-STC and Encoders
• Count on the falling edge of Channel A
– Clockwise - B is high so count increments
– Counter-Clockwise - B is low so count decrements
• Channel B is hardwired to DIO6 on the DAQ Signal Accessory
Channel A
Channel B
Clockwise Rotation
Channel A
Channel B
Counter-Clockwise Rotation
Gate
Channel B
U/D Count Register
Source
Channel A
Simple Event Counting
Out
Chapter 6 Summary
• Counters accept and generate TTL signals
• The main components of a counter are the source,
gate, out, and count register
• National Instruments devices could have one of
four different counter chips
• E-Series devices use the DAQ-STC chip
• The Easy VIs can be used to perform event
counting, pulse generation, pulse measurement,
and frequency measurement
• A quadrature encoder is a transducer that
converts rotary motion into two pulse trains which
are out of phase by 90 degrees
Download