beautypg.com

Measurement Computing WBK17 User Manual

Page 26

background image

WBK17, pg. 26

987996

WBK17, Counter/Encoder Module

Application Example #2
Using Encoder mode to implement Up/Down Counters of any size.

The encoder mode does not have to be used exclusively with quadrature encoders. The encoder mode can
be used to implement a 16 or 32 bit counter that has direction control. The encoder mode can also be used
to force the counter to rollover on any value.

When an odd-numbered channel (1, 3, 5, 7) is put in encoder mode, the next higher channel (2, 4, 6, 8) is
automatically selected to be the direction control. Therefore, if channel 1 is in encoder mode, channel 2 is
the direction control. Channel 1’s counter will count up (at the edge rate coming in on channel 1) if
channel 2 is low and channel 1 will count down if channel 2 is high. If channel 1’s counter is required to
decrement only, then channel 2 can be forced high by software (set the coupling mode to OFF and the
comparator threshold to negative 12V.) Any input channel can be forced to a low or high simply by setting
the coupling mode to OFF and setting the appropriate threshold level. When a channel is turned OFF, the
input settles to 0.0V, setting a positive threshold will force a low and setting a negative threshold will force
a high.

Encoder mode allows the mapped channel to clear the counter. If the mapped channel is programmed to be
the detection signal for the counter, then the counter will rollover to zero when the setpoint criteria is met.
The setpoint criteria could be a simple “greater-than” limit, forcing the counter to rollover on 1000, for
example.

The following steps show how to set up a counter so that it will rollover on the count value of 1000.

1. Configure Channel 1 as Encoder mode, 1X option, 16-bit counter, Map channel clears the

counter option, set the Map channel to Detect 1. Select desired coupling, low pass filtering,
comparator threshold and debounce.

2. Configure Channel 2 as:

Analog mode

Coupling = OFF

LPF = 30Hz

Comparator threshold = 12.0V

If you want to observe the terminal count on pulsing high, scan the Detect signals.

3. Program a setpoint on channel 1 to be “greater than 1000.” This will take Detect 1 high

whenever channel 1’s acquired counter data is greater than 1000.

4. Take 10,000 scans at a scan rate of 2 kHz.

5. Connect a 1kHz signal to channel 1’s input. Make sure it meets the comparator threshold

setting.

6. Take the acquisition.

The counter on channel 1 will count up and rollover on the count of 1000. Since the pattern detection
circuit works on data that is latched into the data stream, the scan rate must be greater than the input
edge rate. If the scan rate is less than the input edge rate, then the counter will actually count up
beyond 1000 before the count value is sampled, detected, and then cleared back to zero.

It is important to realize that the Detect signals have the timing resolution of the scan
period and that the pattern detection module only looks at acquired data, not the actual
counter value.