counters

33
Counters Topics • Counter Overview • Easy Counter VIs for: – Event Counting – Pulse Generation – Pulse Measurement – Frequency Measurement • Position Measurement

Upload: nani

Post on 23-Jan-2016

25 views

Category:

Documents


0 download

DESCRIPTION

Counters. Topics Counter Overview Easy Counter VIs for: Event Counting Pulse Generation Pulse Measurement Frequency Measurement Position Measurement. Maximum Rise/Fall Time = 50ns. +5.0 V. high. +2.0 V. indeterminate. +0.8 V. low. 0 V. Minimum Pulse Width = 10ns. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Counters

Counters Topics• Counter Overview• Easy Counter VIs for:

– Event Counting– Pulse Generation– Pulse Measurement– Frequency Measurement

• Position Measurement

Page 2: Counters

Counter Signals

+0.8 V

0 Vlow

+5.0 V

+2.0 V

high

indeterminate

Maximum Rise/Fall Time = 50ns

Minimum Pulse Width = 10ns

Counters accept and generate TTL signals

Page 3: Counters

Parts of a Counter

• Count Register– Stores the current count

• 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

Gate

Source

Out

Count Register

Page 4: Counters

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

Page 5: Counters

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

Page 6: Counters

Different Counter Chips

• 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

Features

Less

More

Page 7: Counters

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

Intermediate VIs

Advanced VIs

Page 8: Counters

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

Page 9: Counters

Counter ApplicationsEvent 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

Page 10: Counters

Event Counting

• Active edges on source signal increment the count

– Active edge can either be rising or falling

Gate

Source

Out

Count Register

Your Signal

Gate

Source

Out

Count Register

Timebase

Simple Event Counting

Time Measurement

• Timebase has known frequency– Time elapsed = (Count) x

(timebase period)

Page 11: Counters

Event Counting

0 1 2 3 0TC-1 TC

Counter Armed

Source

Count

• 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

Page 12: Counters

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

Page 13: Counters

Pulse Generation

• Generates a TTL signal on counter’s out pin

Single Pulse Pulse Train

Gate

Source

Out

Count Register

Single Pulse or Pulse Train

Timebase

Page 14: Counters

Pulse Characteristics

Pulse Polarity

Delay Width

High Polarity Low Polarity

Delay Width

Pulse Period = Delay + Width

Pulse Frequency =1

Pulse Period

Duty Cycle =Width

Pulse Period

Page 15: Counters

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

Page 16: Counters

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

Page 17: Counters

Pulse Measurement

• Use a timebase with a known frequency to measure characteristics of a unknown signal

Gate

Source

Out

Count Register

Your Signal

Timebase

Pulse Period

Period Measurement

Width

Pulse Width Measurement

Page 18: Counters

• 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)

Period Measurement

0 1 2 3 4 4

Armed

Source

Count 4

Gate

Yes No

Page 19: Counters

Pulse Width Measurement

0 1 2 2 2 2

Armed

Source

Count 2

Gate

Yes No

• 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)

Page 20: Counters

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

Page 21: Counters

Frequency Measurement

High FrequencyLow Frequency

Measure Pulse Width

or PeriodMeasure Frequency

Your Signal

Page 22: Counters

Low Frequency Measurement

Low Frequency

Measure Pulse Width

or Period

Your Signal

Measure period and take the inverse• Frequency = 1/Period

Pros• Only uses one counter• Good at low frequencies

Cons• Can see large error at high frequencies

due to a phenomenon called synchronization error

Page 23: Counters

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

0 1 2 3 4 Miss one, catch one

1 2 3 4 5 Catch both edges

Page 24: Counters

Effect of Synchronization error

• You can measure a frequency of F with error of 0.xFMAX = FSOURCE - (FSOURCE/(1+0.x))

• If frequency you are measuring exceeds acceptable error use Measure Frequency VI

Page 25: Counters

High Frequency Measurement

High Frequency

Measure Frequency

Your Signal

Still Period Measurement except:• Gate is known

– Pulse from another counter

• Source is your signal

Pro• Works well at high frequencies

Con• Uses two counters

Page 26: Counters

High Frequency Setup

Gate

Source

Out

Count Register

Your Signal

Gate

Source

Out

Count Register Known Pulse

Timebase

Pulse Width MeasurementSingle Pulse Generation

• 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)

Counter 1Counter 0

Page 27: Counters

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

Page 28: Counters

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 DAQ-STC

Page 29: Counters

How Does an Encoder Work?

Light SourceLight Sensor

Shaft

Rotating Disk

Code Track

Channel B

Channel A

• Shaft and disk rotate• Code track either

passes or blocks light to sensor

• Light sensor creates two pulse trains

Quadrature Encoder

Page 30: Counters

Quadrature Encoder

900 phase difference

Channel B

Channel A

900 phase difference

Channel B

Channel A

Clockwise Rotation

Counter-Clockwise Rotation

• 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

Page 31: Counters

• 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

Up/Down Line

Gate

Source

Out

Count RegisterU/D

Page 32: Counters

• 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

DAQ-STC and Encoders

Gate

Source

Out

Count Register

Channel ASimple Event Counting

U/DChannel B

Channel B

Channel A

Clockwise Rotation

Channel B

Channel A

Counter-Clockwise Rotation

Page 33: Counters

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