Counters and DAQ • A counter is a digital timing device. Used for event counting, frequency measurement, period measurement, position measurement and pulse generation. • A counter contains the following four main components: Count Register, Source, Gate and Output
Counters and DAQ • The count register stores the current count of the counter. • The source is the input signal that can change the current count in the count register. • The counter looks for rising and falling edges on the source. • When the active edge is received on the source signal, the count changes.
Counters and DAQ • The gate is an input signal that determines if an active edge on the source will change the count. • Counting can occur when the gate is high, low or between various combinations or rising and falling edges. • Gate setting are made in the software. • The output of the counter is an output that generates pulses or series of pulses, otherwise known as a pulse train
Counters and DAQ • When you configure a counter for simple event counting, the counter increments when an active edge is received on the source. • In order for the counter to increment on an active edge, the counter must be armed to start. • A 24‐bit counter can count to 2^(counter resolution) ‐1=2^24 ‐1=16,777,215
Counters and DAQ • When a 24‐bit counter reaches 16,777,215, the next active edge will force the counter to start at 0. • Use the DAQ Assistant Express VI to configure the DAQ device to perform counter measurement • Drag the icon to block diagram • The following window will open
Counters and DAQ
Counters and DAQ
Counters and DAQ
Count Digital Event Example • This example demonstrates how to count digital events on a Counter Input Channel. The Initial Count, Count Direction, and Edge are all configurable.
Count Digital Event Example Steps: 1. Create a Counter Input channel to Count Events. The Edge parameter is used to determine if the counter will increment on rising or falling edges. 2. Call the Start VI to arm the counter and begin counting. The counter will be preloaded with the Initial Count. 3. The counter will be continually polled until the Stop button is pressed on the front panel.
Count Digital Event Example 4. Call the Clear Task VI to clear the Task. 5. Use the popup dialog box to display an error if any.
Generate Digital Pulses Example • This example demonstrates how to generate a single digital pulse from a Counter Output Channel. The Initial Delay, High Time, Low Time, and Idle State are all configurable. • This example shows how to configure the pulse in terms of time, but can easily be modified to generate a pulse in terms of Frequency/Duty Cycle or Tick
Generate Digital Pulses Example Steps: 1. Create a Counter Output channel to produce a Pulse in terms of Time. If the Idle State of the pulse is set to low, the state of the line will begin low and remain low after the generation is stopped. 2. Call the Start VI to arm the counter and begin the pulse generation. The pulse would not begin until after the Initial Delay (in seconds) has expired. 3. Use the Wait Until Done VI to ensure the entire pulse is generated before ending the task. 4. Call the Clear Task VI to clear the Task. 5. Use the popup dialog box to display an error if any.
Generate Digital Pulses Example
Generate Digital Pulses Example with start • This example demonstrates how to generate a single digital pulse from a Counter Output Channel. The Initial Delay, High Time, Low Time, and Idle State are all configurable. This example also shows how to use a Digital Start trigger, so the digital pulse is not started until a trigger signal is received.
Generate Digital Pulses Example with start Steps: 1. Create a Counter Output channel to produce a Pulse in terms of Time. If the Idle State of the pulse is set to low, the state of the line will begin low and remain low after the generation is stopped. 2. Call the DAQmx Start Trigger VI to configure the pulse to begin on a digital trigger. 3. Call the Start VI to arm the counter and begin the pulse generation. The pulse would not begin until it receives a digital trigger and after the Initial Delay (in seconds) has expired. 4. Use the Wait Until Done VI to ensure the entire pulse is generated before ending the task. 5. Call the Clear Task VI to clear the Task.
Generate Finite Digital Pulses Example • This example demonstrates how to generate a finite digital pulse train from a Counter Output Channel. The Frequency, Duty Cycle, and Idle State are all configurable. This example uses two counters.
Generate Finite Digital Pulses Example Steps: 1. Create a Counter Output channel to produce a Pulse in terms of Frequency. If the Idle State of the pulse is set to low, the state of the line will begin low and remain low after the generation is stopped. 2.
Use the DAQmx Timing VI (Implicit) to configure the duration of the pulse generation and the number of pulses to generate.
3.
Call the Start VI to arm the counter and begin the pulse train generation.
4.
Use the Wait Until Done VI to ensure the entire finite pulse train is generated before ending the task.
5.
Call the Clear Task VI to clear the Task.
Generate Finite Digital Pulses Example
Generate Finite Digital Pulses Example with External Start • This example demonstrates how to generate a finite digital pulse train from a Counter Output Channel. The Frequency, Duty Cycle, Initial Delay, and Idle State are all configurable. This example uses two counters.
Generate Finite Digital Pulses Example with External Start Steps: 1. Create a Counter Output channel to produce a Pulse in terms of Frequency. If the Idle State of the pulse is set to low the first transition of the generated signal is from low to high. 2. Use the DAQmx Timing VI (Implicit) to configure the duration of the pulse generation and the number of pulses to generate. 3. Use the DAQmx Trigger VI to configure a trigger to start on a digital edge. 4. Call the Start VI to arm the counter and begin the pulse train generation. 5. Use the Wait Until Done VI to ensure the entire finite pulse train is generated before ending the task. 6. Call the Clear Task VI to clear the Task. 7. Use the popup dialog box to display an error if any.
Generate Continuous Digital Pulses Example • This example demonstrates how to generate a continuous digital pulse train from a Counter Output Channel. The Frequency, Duty Cycle, and Idle State are all configurable.
Generate Continuous Digital Pulses Example Steps: 1. Create a Counter Output channel to produce a Pulse in terms of Frequency. If the Idle State of the pulse is set to low, the state of the line will begin low and remain low after the generation is stopped. 2. Use the DAQmx Timing VI (Implicit) to configure the duration of the pulse generation. 3. Call the Start VI to arm the counter and begin the pulse train generation. 4. Loop continuously until the user presses the Stop button. Check for errors every 100 ms using the Is Task Done? VI 5. Call the Clear Task VI to clear the Task.
Generate Continuous Digital Pulses Example
Generate Continuous Digital Pulses Example started by an External Digital Trigger • This example demonstrates how to generate a continuous digital pulse train from a Counter Output Channel started by an external digital trigger. The Frequency, Duty Cycle, and Idle State are all configurable.
Generate Continuous Digital Pulses Example started by an External Digital Trigger Steps: 1. Create a Counter Output channel to produce a Pulse in terms of Frequency. If the Idle State of the pulse is set to low the first transition of the generated signal is from low to high. 2. Use the DAQmx Trigger VI to configure a trigger to start on a digital edge. 3. Use the DAQmx Timing VI (Implicit) to configure the duration of the pulse generation. 4. Call the Start VI to arm the counter and begin the pulse train generation. 5. Loop continuously until the user presses the Stop button. Check for errors every 100 ms using the Is Task Done? VI 6. Call the Clear Task VI to clear the Task.
Measure Angular Position • This example demonstrates how to measure angular position using a quadrature encoder on a Counter Input Channel. The Decoding Type, Pulses Per Revolution, Z Index Enable, Z Index Phase, Z Index Value, and Sample Clock Source are all configurable. • Position is measured on the counter's default A, B, and Z input terminals
Measure Angular Position Steps: 1. Create a Counter Input channel to Angular Encoder. The Decoding Type, Pulses Per Revolution, Z Index Enable, Z Index Phase, Z Index Value parameters are used to determine how the counter should measure position. 2. Call the DAQmx Timing VI (Sample Clock) to configure the external sample clock timing parameters such as Sample Mode and Sample Clock Source. The Sample Clock Source determines when a sample will be inserted into the buffer. The 100kHz, 20MHz, and 80MHz timebases cannot be used as the Sample Clock Source. The Edge parameter can be used to determine when a sample is taken. 3. Call the Start VI to arm the counter and begin measuring position. The counter will be preloaded with the Initial Angle.
Measure Angular Position 4. For finite measurements, the counter will stop reading data when the Samples to Read have been received. 5. Call the Clear Task VI to clear the Task. 6. Use the popup dialog box to display an error if any.
Measure Digital Low Frequency • This example demonstrates how to measure frequency using one counter on a Counter Input Channel. The Edge, Minimum Value and Maximum Value are all configurable. • This example shows how to measure frequency on the counter's default input terminal but could easily be expanded to measure frequency on any PFI, RTSI, or internal signal. • Additionally, this example could be extended to measure frequency with two counters for different frequency and quantization error requirements
Measure Digital Low Frequency Steps: 1. Create a Counter Input channel to Frequency. The Edge parameter is used to determine if the counter will begin measuring on a rising or falling edge. It is important to set the Maximum and Minimum Values of your unknown signal as accurately as possible so the best internal timebase can be chosen to minimize measurement error. The default values specify a range that can be measured by the counter using the 20MhzTimebase. 2. Call the Read VI to return the next frequency measurement. Set a timeout so an error is returned if a period is not returned in the specified time limit. 3. Call the Clear Task VI to clear the Task 4. Use the popup dialog box to display an error if any.
Measure Digital Finite High Frequency • This example demonstrates how to measure a finite number of frequency samples using two counters on a Counter Input Channel. The Measurement Time, Starting Edge, and Samples per Channel are configurable. • This example shows how to measure frequency on the counter's default input terminal but could easily be expanded to measure frequency on any PFI, RTSI, or internal signal. • Additionally, this example could be extended to measure frequency with other measurement methods for different frequency and quantization error requirements.
Measure Digital Finite High Frequency Steps: • 1. Create a Counter Input channel to measure Frequency. The Edge parameter is used to determine if the counter will begin measuring on a rising or falling edge. The Measurement Time specifies how often a frequency is calculated by counting the number of edges that have passed in the elapsed time. • • Note: The Maximum and Minimum Values are not used when measuring frequency using the High Frequency 2 Ctr Method. •
• •
2. Call the DAQmx Timing VI (Implicit) to configure the Sample Mode and Samples per Channel. Note: For time measurements with counters, the implicit timing VI is used because the signal being measured itself determines the sample rate. 3. Call the Start VI to arm the counter and begin measuring.
•
4. For finite measurements, the counter will stop reading data as soon as "Samples per Channel" samples have been received.
•
5. Call the Clear Task VI to clear the Task.
•
6. Use the popup dialog box to display an error if any.
Measure Digital Continuous High Frequency • This example demonstrates how to continuously measure buffered frequency samples using two counters on a Counter Input Channel. The Measurement Time and Starting Edge are configurable. • This example shows how to measure frequency on the counter's default input terminal but could easily be expanded to measure period on any PFI, RTSI, or internal signal. • Additionally, this example could be extended to measure frequency with other measurement methods for different frequency and quantization error requirements.
Measure Digital Continuous High Frequency Steps: 1. Create a Counter Input channel to measure Frequency. The Edge parameter is used to determine if the counter will begin measuring on a rising or falling edge. The Measurement Time specifies how often the frequency is calculated by counting the number of edges that have passed in the elapsed time. Note: The Maximum and Minimum Values are not used when measuring frequency using the High Frequency 2 Ctr Method. 2.
Call the DAQmx Timing VI (Implicit) to configure the Sample Mode and Samples per Channel. Note: For time measurements with counters, the implicit timing VI is used because the signal being measured itself determines the sample rate.
3.
Call the Start VI to arm the counter and begin measuring.
4.
For continuous measurements, the counter will continually read data until the Stop button is pressed on the front panel.
5.
Call the Clear Task VI to clear the Task.
6. Use the popup dialog box to display an error if any.
Measure Digital Continuous High Frequency Large Range • This example demonstrates how to continuously measure buffered frequency using two counters on a Counter Input Channel. The Divisor, Maximum and Minimum Frequency Values, and the Edge Parameter are configurable. • This example shows how to measure frequency on the counter's default input terminal but could easily be expanded to measure frequency on any PFI, RTSI, or internal signal. • Additionally, this example could be extended to measure frequency with other measurement methods for different frequency and quantization error requirements.
Measure Digital Continuous High Frequency Large Range Steps: 1. Create a Counter Input channel for Frequency The Edge parameter is used to determine if the counter will begin measuring on a rising or falling edge. The Divisor specifies how many periods of the unknown signal are used to calculate the frequency. The higher this is, the more accurate your measurement will be, but it will take the measurement longer. It is important to set the Maximum and Minimum Values of your unknown frequency as accurately as possible so the best internal timebase can be chosen to minimize measurement error. The default values specify a range that can be measured by the counter using the 20MHzTimebase 2.
Call the DAQmx Timing VI (Implicit) to configure the Sample Mode and Samples per Channel. Note: For time measurements with counters, the implicit timing VI is used because the signal being measured itself determines the sample rate.
3.
Call the Start VI to arm the counter and begin measuring.
4.
For continuous measurements, the counter will continually read all available data until the Stop button is pressed on the front panel.
5.
Call the Clear Task VI to clear the Task.
6.
Use the popup dialog box to display an error if any.
Measuring Pulse Width • This example demonstrates how to measure pulse width on a Counter Input Channel. The Starting Edge, Minimum Value and Maximum Value are all configurable.
Measuring Pulse Width Steps: 1. Create a Counter Input channel to measure Pulse Width. The Edge parameter is used to determine if the counter will measure high or low pulses. It is important to set the Maximum and Minimum Values of your unknown pulse as accurately as possible so the best internal timebase can be chosen to minimize measurement error. The default values specify a range that can be measured by the counter using the 20MhzTimebase. 2. Call the Read VI to return the next pulse width measurement. Set a timeout so an error is returned if a pulse is not returned in the specified time limit. 3. Call the Clear Task VI to clear the Task 4. Use the popup dialog box to display an error if any.
Measuring Pulse Width of Finite Pulses • This example demonstrates how to measure a finite number of pulse widths on a Counter Input Channel. The Minimum Value, Maximum Value, and Samples per Channel are all configurable.
Measuring Pulse Width of Finite Pulses Steps: 1. Create a Counter Input channel to Pulse Width. It is important to set the Maximum and Minimum Values of your unknown period as accurately as possible so the best internal timebase can be chosen to minimize measurement error. The default values specify a range that can be measured by the counter using the 20MhzTimebase. 2. Call the DAQmx Timing VI (Implicit) to configure the Sample Mode and Samples per Channel. Note: For time measurements with counters, the implicit timing VI is used because the signal being measured itself determines the sample rate. 3. 3. Call the Start VI to arm the counter and begin measuring. 4. For finite measurements, the counter will stop reading data when the Samples per Channel have been received. 5. Call the Clear Task VI to clear the Task. 6. Use the popup dialog box to display an error if any.
Measuring Pulse Width of Continuous Pulses • This example demonstrates how to continually measure pulse widths on a Counter Input Channel.
Measuring Pulse Width of Continuous Pulses Steps: 1. Create a Counter Input channel to Pulse Width. It is important to set the Maximum and Minimum Values of your unknown pulse width as accurately as possible so the best internal timebase can be chosen to minimize measurement error. The default values specify a range that can be measured by the counter using the 20MhzTimebase. 2. Call the DAQmx Timing VI (Implicit) to configure the Sample Mode and Samples per Channel. Note: For time measurements with counters, the implicit timing VI is used because the signal being measured itself determines the sample rate. 3. Call the Start VI to arm the counter and begin measuring. 4. For continuous measurements, the counter will continually read all available data until the Stop button is pressed on the front panel. 5. Call the Clear Task VI to clear the Task. 6. Use the popup dialog box to display an error if any.
Measure Digital Low Frequency Periods • This example demonstrates how to measure period using one counter on a Counter Input Channel. The Edge, Minimum Value and Maximum Value are all configurable
Measure Digital Low Frequency Periods Steps: 1. Create a Counter Input channel to measure Period. The Edge parameter is used to determine if the counter will begin measuring on a rising or falling edge. It is important to set the Maximum and Minimum Values of your unknown period as accurately as possible so the best internal timebase can be chosen to minimize measurement error. The default values specify a range that can be measured by the counter using the 20MhzTimebase. 2. Call the Read VI to return the next period measurement. Set a timeout so an error is returned if a period is not returned in the specified time limit. 3. Call the Clear Task VI to clear the Task 4. Use the popup dialog box to display an error if any.
Duty Cycle Measurement • This example demonstrates how to take a finite number of duty cycle measurements on a Counter Input Channel. The Minimum Value, Maximum Value, and Samples per Channel are all configurable. This measurement is based on the buffered Semi‐ period measurement
Duty Cycle Measurement Steps:
1. Create a Counter Input channel to measure Semi‐Period. It is important to set the Maximum and Minimum Values of your unknown period as accurately as possible so the best internal timebase can be chosen to minimize measurement error. The default values specify a range that can be measured by the counter using the 20MhzTimebase. The Maximum Value will be the largest amount of time between 2 adjacent edges. The Minimum Value will be the smallest amount of time between 2 adjacent edges. 2. Call the DAQmx Timing VI (Implicit) to configure the Sample Mode and Samples per Channel. Note: For time measurements with counters, the implicit timing VI is used because the signal being measured itself determines the sample rate. 3. Use a DAQmx Trigger Property Node to configure the Arm Start trigger on the selected input terminal of the specified counter. The trigger terminal must be the same terminal as the input terminal for the measurement. By default, the trigger terminal is set to the default semi‐period input terminal of counter 0. Setting this trigger forces the counter to begin taking its first measurement on the first rising edge of the signal being measured. Without this trigger, the counter could start taking the measurement at any time without waiting for a particular edge. This feature is only supported on TIO‐based devices.
Duty Cycle Measurement 4.
Call the Start VI to arm the counter and begin measuring.
5.
For finite measurements, the counter will stop reading data when the Samples per Channel have been received.
6.
Data is returned in an interleaved format. The width of the first high pulse is element 0, the width of the first low pulse is in element 1, etc. Seperate the high and low pulses, then divide the high pulse by the total period to get the pulse width.
7.
Call the Clear Task VI to clear the Task.
8. Use the popup dialog box to display an error if any.