Counters Topics Counter Overview Easy Counter VIs for

  • Slides: 33
Download presentation
Counters Topics • Counter Overview • Easy Counter VIs for: • Event Counting •

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 = 50 ns

Counter Signals Counters accept and generate TTL signals Maximum Rise/Fall Time = 50 ns +5. 0 V high +2. 0 V +0. 8 V 0 V indeterminate low Minimum Pulse Width = 10 ns

Parts of a Counter Gate • Count Register – Stores the current count •

Parts of a Counter Gate • Count Register – Stores the current count • Source Out Count Register 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

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

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 - 100 k. Hz, 20 MHz

Different Counter Chips Less F e a t u r e s More •

Different Counter Chips Less F e a t u r e s More • 8253 (16 -bit) – Used on Lab and 1200 Series Devices • Am 9513 (16 -bit) – Used on PC-TIO-10 and Legacy Devices (i. e. AT-MIO-16 F) • DAQ-STC (24 -bit) – Used on E-Series Devices – Created by NI • NI-TIO (32 -bit) – Used on 660 x Devices – Created by NI

Counter Palette • Easy VIs – Built out of Intermediate VIs + Easy to

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

Easy VIs • Perform basic counter operations • Not suitable for more advanced applications • Compatible with Am 9513 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 •

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

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

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

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 Train

Pulse Generation • Generates a TTL signal on counter’s out pin Single Pulse Train Gate Out Count Register Source Timebase Single Pulse or Pulse Train

Pulse Characteristics High Polarity Low Polarity Pulse Polarity Delay Width Pulse Period = Delay

Pulse Characteristics High Polarity Low Polarity Pulse Polarity Delay Width Pulse Period = Delay + Width Pulse Frequency = Duty Cycle = 1 Pulse Period Width

Generate Delayed Pulse VI • Timebase Source – Internal or External • Counter –

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 –

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

Pulse Measurement • Use a timebase with a known frequency to measure characteristics of a unknown signal Period Measurement Pulse Width Measurement Pulse Period Your Signal Timebase Width Gate Out Count Register Source

Period Measurement • Count will increment for each rising edge on source – Counting

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 Gate Source Count Yes 0 1 2 No 3 4 4 4

Pulse Width Measurement • Count will increment for each rising edge on source –

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 Gate Source Count Yes 0 1 No 2 2 2

Measure Pulse Width or Period VI • Counter – Chooses counter to address •

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 100 k. Hz or 20 Mhz • 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 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 Low Frequency •

Low Frequency Measurement Your Signal Measure period and take the inverse Low Frequency • Frequency = 1/Period 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

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

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 Measurement Your Signal Still Period Measurement except: • Gate is known – Pulse from another counter High Frequency • 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

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)

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

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 Am 9513 and DAQSTC

How Does an Encoder Work? Quadrature Encoder Light Sensor Light Source Shaft • Shaft

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 Encoder 900 phase difference Channel A Channel B Clockwise Rotation 900 phase difference Channel A Channel B 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

Up/Down Line • DAQ-STC counters also have an up/down line – DIO 6 is

Up/Down Line • DAQ-STC counters also have an up/down line – DIO 6 is up/down for counter 0 – DIO 7 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

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 DIO 6 on the DAQ Signal Accessory Channel A Channel B Clockwise Rotation Channel B Counter-Clockwise Rotation Gate U/D Count Register Source Channel A Simple Event Counting Out

Chapter 6 Summary • Counters accept and generate TTL signals • The main components

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