Presentation is loading. Please wait.

Presentation is loading. Please wait.

Counters Topics Counter Overview Easy Counter VIs for:

Similar presentations


Presentation on theme: "Counters Topics Counter Overview Easy Counter VIs for:"— Presentation transcript:

1 Counters Topics Counter Overview Easy Counter VIs for:
Event Counting Pulse Generation Pulse Measurement Frequency Measurement Position Measurement We will finish our course by discussing the counter functionality of our DAQ device. We will start with a basic overview of counters. Our overview will cover counter signals, the parts of a counter, the pins used to connect a counter signal to, basic counter terminology, and different types of counter chips. Then we will move on to discuss the Easy VIs that are used for the following applications: Event Counting Pulse Generation Pulse Measurement Frequency Measurement We will finish Chapter 6 with a discussion about using quadrature encoders to measure position.

2 Counter Signals Counters accept and generate TTL signals
+0.8 V 0 V low +5.0 V +2.0 V high indeterminate Maximum Rise/Fall Time = 50ns Minimum Pulse Width = 10ns Before we start to discuss counters, we will discuss the types of signals counters can acquire and generate. Counters operate with TTL compatible signals. The definition of a TTL compatible signal is as follows: 0V - 0.8V = logic low 2V - 5V = logic high Maximum Rise/Fall Time = 50ns As we learned in our section on digital I/O, our digital lines can set or monitor the state of a digital line. Counters are not only concerned with the state of the signal, but the transition from one state to another. A counter can sense rising edges (transition from logic low to logic high), and falling edges (logic high to logic low). Two important parameters related to sensing rising and falling edges are the rise/fall time, and the minimum pulse width. The rise/fall time is a measure of how quickly the signal transitions from low to high, or high to low. In order for a counter to sense the edge, the transition must occur within 50ns or less as defined by the specifications for a TTL compatible signal. In addition to the time restraint on how quickly a signal transitions, a minimum delay is needed from the time when a counter senses a rising or falling edge until it can sense another rising or falling edge. This delay is known as the minimum pulse width. The minimum pulse width will depend on the counter chip that is used. The minimum pulse width for both the source and gate of a DAQ-STC chip is 10ns. Specifications for the minimum pulse width of your counter can be found in the hardware manual for your device.

3 Parts of a Counter Gate Source Out Count Register 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 Before we learn how to acquire or generate a signal with a counter, we need to understand the different parts of a counter. A counter has four main components: a count register, a source, a gate, and an out. We will examine each component in detail. Count Register The count register stores the current count of the counter. The count register can be queried with software. Source The source is an input signal that can change the current count stored in the count register. The counter looks for either rising or falling edges on the source signal. Whether a rising or falling edge changes the count is software selectable. The type of edge (rising or falling) that is selected is referred to as the active edge of the signal. When an active edge is received on the source signal the count will change. Whether an active edge increments or decrements the current count is also software selectable. Gate The gate is an input signal that decides if an active edge on the source will change the count. Counting can occur when the gate is high, low, or between various combinations of rising and falling edges. Gate settings are made in software. The gate is similar to a line mask in digital I/O, because it allows you to either acknowledge or ignore active edges on the source. Out The out is an output signal used to generate pulses or a series of pulses often referred to as a pulse train. The output signal is TTL compatible.

4 Counter Pins Counter gate and source are PFI pins For Example
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 Analog input, analog output, and digital I/O all have dedicated pins for their input or output operations. Counters use a combination of PFI pins and dedicated pins for their operations. The output pins for counters are used solely for generating pulses on the out of a counter. The source and gate pins for counters are PFI pins and can be used for applications other than the source or gate of a counter. For instance, pin 3 on the 68-pin connector shown above can be used as either PFI9, the gate of counter 0, or both. Being able to use one pin for multiple applications offers a great deal of flexibility. For instance, you could wire an external TTL signal into pin 3, and use it to start both an analog input operation and a counter operation.

5 Counter Terminology Timebase Terminal Count Resolution
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 Some of the terminology used in this chapter may be unfamiliar to you, so we will take a moment to define some of the important terms used when discussing counters. Terminal Count Term for the last count before a counter reaches 0. For instance, when a counter that increments the count reaches its maximum count it has reached the terminal count. The next increment of the count will force the counter to roll over and start counting at 0. Resolution The resolution of a counter specifies how high the counter can count before reaching the terminal count. The resolution of a counter is specified in bits. The formula for calculating the maximum count based on the resolution is: max count = 2(resolution) - 1 Common counter resolutions are 16, 24, or 32 bits. Timebase A timebase is a signal that is provided by your DAQ device. Typical frequencies for timebases range from 100Hz to 80MHz. The timebase can be routed internally to the source of a counter to provide a signal of known frequency.

6 Different Counter Chips
Less 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 Features Depending on your DAQ device, you could be using one of the following four counter chips: 8253, Am9513, DAQ-STC, NI-TIO. 8253 The 8253 is used primarily on Lab Series and 1200 Series devices. It is a 16-bit counter. The 8253 is easy to program (one VI), but has a limited amount of flexibility. The 8253 can only decrement the count, can only count rising edges, can only do high level gating, and only offers a 2MHz timebase. Am9513 The Am9513 is also a 16-bit counter, but it is a more advanced chip than the The Am9513 can increment or decrement the count, can group counters to start together, and offers a range of timebases from 100Hz to 1MHz. The Am9513 is used on the PC-TIO-10 and on Legacy DAQ devices such as the AT-MIO-16. DAQ-STC The DAQ-STC is used on E-Series devices. It is a 24-bit counter with a wide range of functionality. The DAQ-STC can increment or decrement the count, the count direction can change on the fly with the use of a hardware signal, and it offers both a 100kHz and 20MHz timebase. NI-TIO The NI-TIO is the premier counter chip offered on National Instruments devices. It is a 32-bit counter that is software compatible with the DAQ-STC. In fact, both the DAQ-STC and NI-TIO were developed by National Instruments. The NI-TIO can increment and decrement the count, supports encoders, supports a hardware trigger signal, has digital filters to remove glitches, can change the frequency of a pulse train on the fly, and offers a 100kHZ, 20MHz, and 80MHz timebase. The NI-TIO is used on the 660x family of devices. The remainder of this section will focus on the use of the DAQ-STC. The DAQ-STC offers a wide range of functionality is is more widely available on current National Instruments devices than any of the other chips. Throughout the remainder of this section, counter will refer to the DAQ-STC chip. Note: Even though the focus will be placed on the DAQ-STC chip, the VIs used in the exercises are compatible with the Am9513 chip. More

7 Counter Palette Easy VIs Intermediate VIs Advanced 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 Similar to the Digital I/O VI palette, the Counter Palette has only three categories: Easy VIs, Intermediate VIs, and Advanced VIs. Easy VIs The Easy VIs are built for specific counter applications. They offer the ability to perform an advanced counter application with little programming, but they offer little flexibility in the event the VI doesn’t meet your application needs. The Easy VIs are built out of the Intermediate VIs. The Easy VIs are compatible with the Am9513, and DAQ-STC. Intermediate VIs The Intermediate VIs offer more flexibility than the Easy VIs, but they are more complex to program. All of the VIs in the intermediate palette support the Am9513, and DAQ-STC, except the ICTR Control VI which only supports the The Intermediate VIs are built out of the Advanced VIs. Advanced VIs The Advanced VIs palette consists of a variety of VIs. The VIs you use will depend on the chip you are using. Advanced VIs exist for all four counter chips. Advanced VIs offer the greatest amount of flexibility and features, but they are the most complex to program.

8 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 In this course, we will focus on the Easy counter VIs. The Easy VIs are compatible with the Am9513 and DAQ-STC. The Easy VIs perform some basic counter operations such as event counting, pulse generation, pulse measurement, and frequency measurement. The Easy VIs are not suitable for advanced or more demanding applications.

9 Counter Applications Event Counting Pulse Generation Pulse Measurement
Simple Event Counting Time Measurement Pulse Generation Single Pulse Generation Pulse Train Generation Pulse Measurement Period Measurement Pulse Width Measurement Frequency Measurement Position Measurement In the following section, we will learn about five different categories of measurements: event counting, pulse generation, pulse measurement, frequency measurement and position measurement. We will discuss the parts of the counter used for each type of measurement, learn about the VIs necessary to perform that type of measurement, and complete an exercise that performs that type of measurement.

10 Event Counting Simple Event Counting Time Measurement
Active edges on source signal increment the count Active edge can either be rising or falling Gate Source Out Count Register Your Signal Time Measurement Gate Source Out Count Register Timebase Timebase has known frequency Time elapsed = (Count) x (timebase period) Event counting is the most basic of all counter operations. In event counting the focus is on measuring the source signal. We will learn about two types of event counting: Simple Event Counting, and Time Measurement. Simple Event Counting Simple Event Counting fits into the basic definition of a counter. The active edges of the source signal will increment the value of the count register. An active edge can be chosen in software to be falling or rising. As you can see the gate and out are not used for simple event counting. Time Measurement Time measurement is a variation on simple event counting. When you are performing simple event counting the source signal is the unknown. You are using the counter to help you measure the source signal. When you are performing time measurement, the signal source has a known frequency. You are using your knowledge of the timebase frequency to help you measure elapsed time. As you can see above time measurement uses a timebase for the source instead of the signal you are trying to measure. In fact, the only difference between time measurement and simple event counting is the signal that is used for the source. The following formula is used to calculate the elapsed time: elapsed time = (count register value) x (timebase period) where timebase period = 1/timebase frequency

11 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 1 2 3 TC-1 TC Counter Armed Source Count Now that we know only the source and the count register are used for event counting, let us examine how those two components interact during an event counting operation. When a counter is configured for simple event counting or time measurement, the count will increment when an active edge is received on the source. Whether the active edge is rising or falling can be chosen in the software. In the diagram above the active edge has been chosen to be a rising edge. As you can see above, the count will increment by one every time a rising edge is reached. A counter does have a fixed number that it can count to as determined by the resolution of the counter. For instance a 24-bit counter can count to: 2(Counter resolution) - 1 = 2(24) - 1 = 16,777,215 When a 24-bit counter reaches the value of 16,777,215 it has reached the terminal count. The next active edge will force the counter to roll over and start at 0.

12 Count Events or Time VI Source Edge Event Source/Timebase Counter
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 The VI that is used for event counting is the Count Events or Time VI. Since the only difference between simple event counting and time measurement is the signal that is used for the source, the same VI can be used for both simple event counting and time measurement. The parameters for the Count Events or Time VI are listed below. Source Edge Chooses the active edge of the source as rising or falling Event Source/Timebase The value of this parameter will depend on whether you are performing simple event counting or time measurement. If you are performing simple event counting you will set the event source/timebase input to a value of 0. If you are performing time measurement you will set the event source/timebase input to the value of the timebase you wish to use. For instance, if you want to use the 100kHz timebase you would set the value to 100,000. Device Number of the device (from MAX) you are addressing Counter Chooses the counter you want to address Start/Restart If the counter hasn’t been started, a value of TRUE will start the counter. If the counter is already running, a true value will reset the count of the counter. Stop A value of TRUE will stop the counter. Count Returns the current count from the count register. This is the value you are interested in if you are performing simple event counting. Seconds Since Start Returns the time elapsed in seconds since the counter was started. This is the value you are interested in if you are performing time measurement.

13 Single Pulse or Pulse Train
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 A counter can not only measure TTL signals, but it can also generate TTL signals. Using a counter to generate a TTL signal is known as pulse generation. As you can see above the output signal is generated on the out of of the counter. The generated signal can either be a single pulse, or a continuous set of pulses known as a pulse train. The counter uses a timebase as the source to help generate the pulse. For now it is only important to realize that a timebase is used the help generate the pulse. How the timebase is used to generate a pulse is not necessary to program the counter for pulse generation, and is beyond the scope of this course.

14 Pulse Characteristics
Delay Width High Polarity Low Polarity Delay Width Pulse Polarity Pulse Period = Delay + Width Pulse Frequency = 1 Pulse Period In order to generate the pulse that we want, it is important to understand certain characteristics of a pulse. A pulse has two parts: the delay, and the width. The delay is the first phase of the pulse and the width is the second phase of the pulse. The delay and width are always at opposite logic levels. For instance, if the delay is logic low, the width must be logic high. (Otherwise we wouldn’t have a pulse). A pulse can either be characterized as high or low polarity. A high polarity pulse has a delay that is low logic, and a width that is high logic. A low polarity pulse has a delay that is high logic, and a width that is low logic. As you can see, the naming convention for the pulse polarity corresponds to the logic level of the width. The period of a pulse is the time it takes the pulse to complete one cycle. Therefore by adding the delay time to the width time we can obtain our pulse period. Once we have determined the period of our pulse, we can simply take the inverse to obtain the frequency of our pulse. The delay and the width of a pulse are not always equal, so we need a property of a pulse that will help us to determine if our delay is larger than our width or vice versa. The parameter we use is called the duty cycle. The formula is shown above. The duty cycle will give us a number between 0 and 1 depending on the pulse. Duty cycle is often converted into a percentage. A pulse where the delay is equal to the width will have a duty cycle of 0.5 or 50%. A duty cycle greater than 50% means the width is larger than the delay, and a duty cycle less than 50% means the delay is larger than the width. Duty Cycle = Width Pulse Period

15 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 In order to generate a single pulse we will use the Generate Delayed Pulse VI. The parameters are listed below. Timebase Source Decides if the counter uses an internal timebase as the source, or if the source is an external signal. How this parameter is set will affect the units of the pulse delay and pulse width. We will only be using an internal timebase for pulse generation in this course. Device Number of the device (from MAX) you are addressing Counter Chooses the counter you want to address Pulse Polarity Sets the polarity of the pulse that is generated as either high or low. Remember that a pulse with high polarity has a low delay and high width, and a pulse with low polarity has a high delay and a low width. Pulse Delay Specifies the delay of the pulse. If the timebase source is set for an internal timebase, the units of pulse delay are in seconds. If the timebase source is set for an external signal, the units of pulse delay are in cycles of the external signal. Pulse Width Specifies the width of the pulse. If the timebase source is set for an internal timebase, the units of pulse width are in seconds. If the timebase source is set for an external signal, the units of pulse width are in cycles of the external signal. Actual Delay Returns the actual delay of the pulse that was generated. Most often the actual delay matches the pulse delay that was set, however a counter does have a limited resolution so the actual delay may differ from the expected delay. If the timebase source is set for an internal timebase, the units of actual delay are in seconds. If the timebase source is set for an external signal, the units of actual delay are in cycles of the external signal. Actual Width Returns the actual width of the pulse that was generated. Most often the actual width matches the pulse width that was set, however a counter does have a limited resolution so the actual width may differ from the expected width. If the timebase source is set for an internal timebase, the units of actual width are in seconds. If the timebase source is set for an external signal, the units of actual width are in cycles of the external signal.

16 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 To generate a series of pulses we will use the Generate Pulse Train VI. The parameters of the VI are listed below. Pulse Polarity Sets the polarity of the pulse that is generated as either high or low. Remember that a pulse with high polarity has a low delay and high width, and a pulse with low polarity has a high delay and a low width. Device Number of the device (from MAX) you are addressing Counter Chooses the counter you want to address Number of Pulses Specifies whether to start or stop the pulse train. If you set the number of pulses to 0 the VI will generate a continuous pulse train. If you set the number of pulses to -1 the VI will stop generating the continuous pulse train. Frequency Specifies the frequency of the pulse train in Hz. Remember that the frequency is the inverse of the pulse period. Duty Cycle Specifies the duty cycle of your pulse train. Remember that duty cycle is equal to the pulse width divided by the pulse period. A value of 0.5 corresponds to a duty cycle of 50%. Actual Parameters Returns the actual parameters, such as frequency and duty cycle, of the pulse train that was generated. Most often the actual parameters match the frequency and duty cycle that were set, however a counter does have a limited resolution so the actual parameters may differ from those expected.

17 Pulse Measurement Use a timebase with a known frequency to measure characteristics of a unknown signal Pulse Period Period Measurement Width Pulse Width Measurement Gate Source Out Count Register Your Signal Timebase Now that we know how to generate a pulse and a pulse train, we will focus on making measurements on a pulse. When we measure a pulse, the signal we are trying to measure will be input as the gate. The source will be a timebase of known frequency. We can use the known frequency of our timebase, and the value of our count register to determine characteristics of our gate pulse such as pulse period and pulse width.

18 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) 1 2 3 4 Armed Source Count Gate Yes No One of the types of pulse measurement we can perform is period measurement. When we perform period measurement we are still going to be counting the active edges on our source signal, but unlike simple event counting, we are only going to increment the count during the period of our gate signal. The diagram above shows period measurement that is started and stopped by a rising edge on our gate signal. You can also start and stop counting between falling edges. We will only count the rising edges on our source between these two rising edges. Note that in order to perform period measurement you need a signal with either two rising edges or two falling edges. A single pulse only has one rising edge and one falling edge. So in order to perform period measurement we need a signal with more than one pulse. In our example above we received 4 counts within one period of our gate signal. Remember that our source is a timebase of known frequency. Let us assume we are using the 100kHz timebase. The formula for calculating the period of our gate is as follows: pulse period = count x (1/source frequency) For our example shown above with the 100kHz timebase the formula would yield: pulse period = 4 x (1/100,000) = milliseconds

19 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) 1 2 Armed Source Count Gate Yes No Pulse width measurement is very similar to period measurement. The only change is where we stop counting. With period measurement we started and stopped our counting with two rising edges on the gate signal. With pulse width measurement we only want to count during the pulse width, so we will start our counting on a rising edge and end it on the falling edge as shown above. It is also possible to start counting on a falling edge and stop it with a rising edge. We will only increment our count value between the rising and falling edge as shown above. The formula for calculating the pulse width is the same as that for the period: pulse width = count x (1/source frequency) So for the example above with a 100kHz source the formula will yield: pulse width = 2 x (1/100,000) = 0.02 milliseconds Note that this is half of the value that we received for period measurement so we must have a gate signal with a duty cycle of 0.5.

20 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 In order to perform period measurement and pulse width measurement we will use the Measure Pulse Width or Period VI. We can measure either the pulse width of a signal or the period of a signal with this one VI. The parameters of the VI are described below. Device Number of the device (from MAX) you are addressing Counter Chooses the counter you want to address Type of Measurement Specifies if you are doing period or pulse width measurement and what type of edge starts and ends the measurement. The four possibilities are: Measure high pulse width [starts on rising and ends on falling] Measure low pulse width [starts on falling and ends on rising] Measure period (rising edge to rising edge) Measure period (falling edge to falling edge) Timebase Specifies the timebase used as the source. For instance, if you wanted to use the 100kHz timebase, you would enter 100,000 for the timebase input. Pulse Width/Period Returns either the pulse width or period in seconds, depending on whether you are performing a pulse width measurement or a period measurement. Valid Tells you if the value returned in pulse width/period is valid. The pulse width/period value will not be valid if the counter has rolled over. Valid returns a value of TRUE if the counter did not roll over, and a FALSE if the counter did roll over.

21 Frequency Measurement
Your Signal Low Frequency High Frequency Another measurement we can perform on a TTL signal is frequency measurement. Two Easy VIs exist to measure the frequency of a TTL signal: Measure Pulse Width or Period, and Measure Frequency. As we will learn, the Measure Pulse Width or Period VI should be used to measure low frequency signals, and the Measure Frequency VI should be used on high frequency signals. Measure Pulse Width or Period Measure Frequency

22 Low Frequency Measurement
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 Low Frequency We already know how to measure the period of a signal with the Measure Pulse Width or Period VI. By definition, the frequency of a signal is the inverse of the period of a signal. So, to obtain the frequency of our signal, we only need to take the inverse of the period that is returned from the Measure Pulse Width or Period VI. The formula for pulse period is as follows: pulse period = count x (1/source frequency) So to obtain the frequency of our signal we need to take the inverse of the pulse period. The resulting formula is as follows: pulse frequency = source frequency/count The benefits of using this VI are that it only uses one counter, and it it good at measuring low frequencies. The drawback to using the Measure Pulse Width of Period VI to measure frequency is that you see a large error at high frequencies due to a phenomenon called synchronization error. We will learn about synchronization error next. Measure Pulse Width or Period

23 Synchronization Error
Gate period is exactly four source cycles Measurement could be off by +/- 1 GATE SOURCE Miss both edges Miss one, catch one Catch both edges Synchronization error is caused when we are measuring a gate signal that is synchronized with our source signal so that an edge on our gate signal happens at the same time as an edge on our source signal. In the example shown above, we are performing period measurement on a gate signal with a period exactly equal to 4 cycles of our source signal, where the signals are synchronized. So we would expect to measure a count of 4. However, in this type of scenario we have three possibilities for our count: We could miss both our first rising edge and our last rising edge of our source signal and end up with a count of 3. We could miss one of the edges of our source signal, and catch the other edge of our source signal to give us a count of 4. We could catch both our first rising edge and our last rising edge of our source signal and end up with a count of 5. The correct count is 4, but as you can see we could get a count of 3 or 5. Therefore, due to synchronization error our count could be off by +/-1. Keep in mind that synchronization error is inherent to counter measurements and cannot be avoided. By knowing that synchronization error exists, we can learn how to minimize the error it will cause when we measure frequency. Next we will see how synchronization error affects the measurement of a low frequency and a high frequency signal.

24 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 When we measure the period of our signal and take the inverse to get frequency, synchronization error has a larger effect on a high frequency signal than it does on a low frequency signal. Let us walk through the table shown above. We’ll start by assuming that the signal we are going to measure the period of has an actual frequency of 50kHz. If we are using a 20MHz timebase to measure the period, we would expect 400 cycles of our timebase within one period of our 50kHz signal. So we are expecting a count of However, we could be off by +/1 due to synchronization error. So our expected value for the frequency is calculated as follows: pulse frequency = source frequency/count = 20,000,000/400 = 50kHz As you can see in the diagram above an error of +/-1 would cause a measurement error on the order of 0.1kHz. Now let us try to measure the frequency of a 5MHz signal with the same 20MHz timebase. Now we will only have 4 cycles of our timebase within one period of our 5MHz signal. So if we are off by +/1 due to synchronization error, we will now see an error on the order of megahertz instead of tenths of kilohertz. As you can see synchronization error has a greater effect on a higher frequency signal when we measure the period and take the inverse. A formula exists for determining the maximum frequency you can measure based on the frequency of our timebase and the amount of error you can tolerate. The formula is as follows: FMAX = FSOURCE - (FSOURCE/(1+0.x)) where FMAX = the frequency of the signal we are trying to measure FSOURCE = the frequency of the timebase used as the source x = the amount of error you can tolerate If the frequency you are trying to measure is greater than the maximum frequency returned by the previous formula you will need to use the Measure Frequency VI instead of the Measure Period or Pulse Width VI. So let us move on to discuss the Measure Frequency VI.

25 High Frequency Measurement
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 High Frequency As we just learned the Measure Pulse Width or Period VI can experience significant measurement error when trying to measure a high frequency signal. So if we have a high frequency signal we will need to use the Measure Frequency VI. We will see next that this method works well for high frequencies. However, we are forced to use another counter to perform the measurement. On a typical E-Series device we only have two counters so using the Measure Frequency VI will occupy all of the counters on our device. Measure Frequency

26 High Frequency Setup Single Pulse Generation Pulse Width Measurement
Gate Out Gate Out Count Register Known Pulse Count Register Source Counter 0 Source Counter 1 Your Signal Timebase As mentioned earlier, the Measure Frequency VI uses two counters. The first counter is set up for single pulse generation. This is counter 0 in the diagram above. Counter 0 is used to provide a pulse of known width to be used as the gate of our other counter. The other counter is set up for period measurement. This is counter 1 in the diagram above. The gate for counter 1 is the pulse of known width generated by counter 0. The source of counter 1 is the signal we are trying to measure the frequency of. We have already learned that the formula used for pulse width measurement is as follows: pulse width = count x (1/source frequency) However, we already know the pulse width, because we have generated the gate signal ourselves. We want to determine the source frequency. The above formula can be rearranged to solve for the source frequency as follows: source frequency = count / pulse width So to measure the frequency of our source signal we simply take the count of counter 1 and divide it by the known pulse width of the pulse we generated on counter 0. As was mentioned earlier synchronization error is inherent to counter measurements and cannot be avoided. So the count for counter 1 can still be off by +/-1. We will illustrate the benefits of this method for measuring high frequencies by stepping through an example. We are trying to measure a 5MHz signal. We will generate a pulse with a width of 800ns to gate our counter that is performing pulse width measurement. Performing pulse width measurement on a gate signal with a width of 800ns by using a 5MHz source signal should give us a count of 4. However, our count could be off by +/-1 due to synchronization error. So we could measure an incorrect frequency of: source frequency = count/pulse period = (5)/(800 ns) = 6.25 MHz OR source frequency = count/pulse period = (3)/(800 ns) = 3.75 MHz As you can see our error is still on the order of megahertz. So how can we improve our measurement? Let us try increasing the width of the pulse we generate for our gate. What if we were to use a gate with a width of 2 seconds instead of 800ns? Now we should get a count of 10,000,000. However, our count could still be off by +/-1 due to synchronization error. So we could measure an incorrect frequency of: source frequency = (10,000,001)/(2 seconds) = 5,000,000.5 Hz source frequency = (9,999,999)/(2 seconds) = 4,999,999.5 Hz So now our measurement error is 0.5Hz!! Increasing the width of the gate signal will continue to decrease the error. Make sure to keep the gate width short enough to prevent the counter from rolling over. 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)

27 Measure Frequency VI Counter Gate Width (s) Frequency (Hz) Valid
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 The best way to correctly measure the frequency of a high frequency signal is with the Measure Frequency VI. The parameters of the VI are listed below. Device Number of the device (from MAX) you are addressing Counter Chooses the counter you want to address NOTE: You must connect the gate of the counter you have selected to the out of counter +1 on the device. If you are using the DAQ-STC and have chosen counter 0, counter +1 is counter 1. If you have chosen counter 1, counter +1 is counter 0. If you are using the Am9513 refer to the following table: Counter -1 Counter Counter +1 5 1 2 1 2 3 2 3 4 3 4 5 4 5 1 10 6 7 6 7 8 7 8 9 8 9 10 9 10 6 Gate Width Specifies the width of the gate generated by the other counter. Frequency Returns the measured frequency of the signal connected to the source of the chosen counter. The frequency returned is in Hz. Valid Tells you if the value returned in frequency is valid. The frequency value will not be valid if the counter has rolled over. Valid returns a value of TRUE if the counter did not roll over, and a FALSE if the counter did roll over.

28 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 A popular transducer used in counter applications is a quadrature encoder. A quadrature encoder allows us to measure position. Quadrature encoders convert rotary motion into a measurable signal. The DAQ Signal Accessory has a quadrature encoder as shown above. We will discuss quadrature encoders later in this section. Out of the four counter chips, the NI-TIO is the only one that directly supports quadrature encoders. Quadrature encoders can be measured with both the Am9513 and the DAQ-STC, but neither chip was designed for encoder measurements. If you are measuring quadrature encoder signals your best option is to use the NI-TIO chip. Next we will examine how a quadrature encoder works.

29 How Does an Encoder Work?
Shaft and disk rotate Code track either passes or blocks light to sensor Light sensor creates two pulse trains Quadrature Encoder Light Source Light Sensor Shaft Rotating Disk Code Track Channel B Channel A As was mentioned earlier an encoder is a transducer that allows us to measure position or distance. To understand how an encoder works we will examine a quadrature encoder as shown above. A quadrature encoder will help us convert rotary motion into a measurable signal. The rotary motion we are interested in is the spinning of the shaft. We could be interested in the direction the shaft is rotating, the speed the shaft is rotating, or both. A disk is attached to the shaft so that it rotates in the same direction, and at the same speed as the shaft. The rotating disk is placed between a light source and a light sensor. The disk has a section of alternating opaque and transparent sections called the code track. An opaque section will block the light from the source to the sensor, and a transparent section will allow the light to pass from the source to the sensor. As you can see above, the code track consists of two rings of alternating opaque and transparent sections. Each ring will produce a pulse train. The two rings are offset so that depending on the direction the disk rotates one pulse train will lead the other. The number of opaque and transparent sections will determine how many pulses are produced per revolution. This is an important specification to know if you are interested in keeping track of how many revolutions your shaft has completed. The quadrature encoder on the DAQ Signal Accessory produces 24 pulses per revolution. Next we will take a look at the signals that are generated by an encoder.

30 Quadrature Encoder 900 phase difference Channel B Channel A 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 Clockwise Rotation 900 phase difference Channel B Channel A As we saw earlier, a quadrature encoder produces two pulse trains. Most encoders produce a TTL compatible signal that can be used with a counter. However, some encoders may not produce a signal that is suitable for a counter. For instance, some encoders produce a differential signal, and none of the four counter chips support differential inputs. If the signal produced by your encoder is not compatible with the counter chip you are using, you will need to use signal conditioning before you send the signal to the counter. The two pulse trains are referred to as Channel A and Channel B. Channel A and Channel B will always be out of phase by 90 degrees. The leading channel will be determined by the direction of rotation. If the encoder is rotated in a clockwise direction, Channel A will lead Channel B. If the encoder is rotated in a counter-clockwise direction Channel B will lead Channel A. Counter-Clockwise Rotation

31 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 Source Out Count Register U/D In order to measure encoders with the DAQ-STC we will need to use a special input to the counter called the up/down control. The up/down control for counter 0 is the same pin as DIO6 on your pinout, and DIO7 for counter 1. The up/down control determines if an active edge on the source increments or decrements the count. If the signal sent to the up/down line is TTL high, an active edge on the source will increment the count. If the signal sent to the up/down line is TTL low, an active edge on the source will decrement the count.

32 DAQ-STC and Encoders Simple Event Counting
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 B Channel A Clockwise Rotation Channel B Channel A Counter-Clockwise Rotation Gate Source Out Count Register Channel A Simple Event Counting U/D Channel B To measure an encoder with the DAQ-STC we will use both the source and the up/down control. We will connect Channel A to the source and Channel B to the up/down control. When connecting signals from the DAQ Signal Accessory it is important to note that Channel B is hard-wired to DIO6, so the only connection that needs to be made is from Channel A to the source of the counter you are using. The counter is configured for simple event counting, and the active edge is set as falling. Therefore the count will change when a falling edge is received on Channel A, and Channel B will determine if the count increments or decrements. As we already learned when the encoder is turned clockwise Channel A leads Channel B. When Channel A leads Channel B the falling edge of Channel A occurs when Channel B is high so the count will increment. By the same logic, when the encoder is turned counter-clockwise the count will decrement. It is standard for clockwise motion to increment the count and counter-clockwise motion to decrement the count. However, if you would like to switch the two you can set the active edge to rising instead of falling.

33 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 In Chapter 6 we learned about counters in general, specific counter chips, and how to program a counter with the Easy VIs. The main components of a counter are the source, gate, out, and count register. The counter will accept TTL compatible signals on the gate and source, and generate TTL signals on the counter out. A National Instruments DAQ device could have one of four counter chips: 8253 Am9513 DAQ-STC NI-TIO The DAQ-STC is used on E-Series boards. We also learned how to use the Easy VIs to program a counter for applications such as event counting, pulse generation, pulse measurement, and frequency measurement. The Easy VIs support the Am9513 and DAQ-STC counter chips. Finally, we learned how a quadrature encoder converts rotary motion into two pulse trains that are out of phase by 90 degrees. We also learned how to measure a quadrature encoder signal with the use of the Up/Down pin on the DAQ-STC chip.


Download ppt "Counters Topics Counter Overview Easy Counter VIs for:"

Similar presentations


Ads by Google