Applicable Model(s)

HMC2000
HMC3000
HMC4000
HMC7000
MLC Series PLC

Title

High Speed Counters and Encoders

Date

10/12/2022

Rev

04

P/N

0907-7010

Summary

Many control processes require the use of an encoder for precision measurement of motion. This technical note covers the interactions of the HMC products with high speed counters and encoders.


Solution

The HMC products offer High Speed Counters (HSC) on several I/O modules. These counters offer support for a single channel pulse train (single input) or multi-channel for use with quadrature encoders (multi-input). Note that not all models support every mode of operation. Consult the specifications for the particular model being used.

Modes

Single Phase Up Counter

This mode is used to count the number of incoming pulses to a digital input (X). The pulse count is increased by 1 each time a new pulse is received on the input. The accumulated count is compared to a preset value- when the values match; a predefined configuration bit (M) is set. There is also an option to set a physical output (Y). Once the accumulated value reaches the preset value, a configuration bit (M) or physical input (X) can be used to reset the accumulated value back to 0. A configuration bit (M) is used to enable or disable the counter.

Single Phase Down Counter

This mode is similar to the Up-Counter described above, except that the accumulated value starts at 4,294,967,295 and counts down to the preset value. For models that support both Phase Up and Phase Down counting, direction is controlled by a second digital input (X). When the input is high, the counter will count up. When it is low, the counter will count down.

Quadrature 1X Mode

Quadrature encoders are used to measure the speed and direction (clockwise or counter-clockwise) of a device. Each encoder has two tracks, A and B (thus two inputs are required), that are 90° out of phase, which enable it to provide accurate position information. It will count up when phase A precedes, and count down when phase B precedes. The length of travel can be determined by the speed of the incoming pulses. With 1X mode, the current value increments or decrements at the rising or falling edge of the phase B input after the phase A input has turned on.

Quadrature 2X Mode

Quadrature 2X Mode works the same as 1X Mode, except that the current value increments or decrements at the rising or falling edge of the phase B input after the phase A input has turned on or off.

Quadrature 4X Mode

Quadrature 4X Mode works the same as 1X and 2X Modes, except that the current value increments or decrements at the rising or falling edges of the phase A and B inputs. Both rising and falling edges of each phase are counted. This essentially quadruples the number of pulses per revolution, by counting 4 times the pulse frequency.


HMC3000 High Speed Counters

The HMC3000 Series modules have built-in High-Speed counters that link directly to specific inputs and outputs. Specific registers and bits are predefined for setup and control of these counters. No logic is required to run the counters, other than logic that may be used for configuration and control.

Two inputs on the module are used as the Triggers for the High-Speed counters, and two outputs are used as the done bits. The inputs support a maximum speed of 200 KHz.

Implementation of HSC on HMC3000 Series

1.

Connect a device that will provide the high-speed pulses to one of the high-speed inputs on the expansion module.


2.

Configure the HSC using the configuration register for that channel. Note: You can write to the configuration register value using the Power-Up logic block or in a Power-Up Task.


3.

Write the HSC preset count value in that channel’s Preset Register.


4.

Enable the HSC by setting the HSC Enable Bit for that channel.


5.

HSC increments the current value register for that channel until the preset value is reached.


6.

Enable the HSC Reset Bit for that channel. This will cause the HSC current value to reset back to 0.


7.

To start the process again, simply reset (clear) the HSC Reset Bit and set the HSC Enable Bit. Note: if the HSC Enable Bit is still ON, you must reset (clear) this bit, and then set it again.


The following bits and registers are associated with the HSC:

Register/BitDescription
Configuration RegisterThe 16-bit register that controls how the High-Speed counter operates.
Current Count RegisterThe 32-bit register that counts the number of times that the Trigger has transitioned. The specified register is the Least Significant Word (LSW); the next consecutive register is the Most Significant Word (MSW).
Preset RegisterThe 32-bit register that defines the number of counts at which the Done bit will be set (see description of Done Bit below). The specified register is the Least Significant Word (LSW); the next consecutive register is the Most Significant Word (MSW).
Trigger BitThe input bit that triggers the count. The counter will increment by one on each bit transition. The counter can operate on a falling (default) or rising edge.
Enable BitThe counter will not run unless this bit is set. If this bit is reset while the counter is running, the current values will be maintained, but the Trigger bit will have no effect. The Done bit is reset if the Enable bit is reset. If the Current Count value is greater than or equal to the Preset value, the Done bit is set after the Enable bit is set again.
Reset BitWhen this bit goes from false to true, the current count will reset to 0 and the Done bit is reset. The reset occurs even when the Enable bit is reset. The reset is accomplished by an internal bit or a physical input.
Done BitThe physical output that turns on when the Current Count is equal to or greater than the Preset value. The bit remains set until the Reset bit goes true, even if the counter counts beyond the preset. If the Enable bit is reset, the Done bit will reset. If the Enable bit is set while the Current Count is equal to or greater than the Preset, the Done bit is set.

The following registers and I/O are associated with the HSC. For the register addresses listed below, nn stands for which slot the module was installed (slot 1 is 01, slot 2 02, etc.).

FunctionCounter 1 (CH 0)Counter 2 (CH 1)
Trigger BitXnn000Xnn002
Enable BitMnn080Mnn176
Reset BitMnn081Mnn177
Configuration RegisterMWnn00MWnn06
Current Count Register (LSW, MSW)MWnn01, MWnn02MWnn07, MWnn08
Preset Register (LSW, MSW)MWnn03, MWnn04MWnn09, MWnn10

For how to set the HSC Configuration Register, reference the tables below:

Input ModeOutput ModeRegister Value
Normal InputN/A0
High Speed, Single Phase, Up/Down CounterOutput ON when preset is reached2
Output ON when counter is enabled, OFF when preset is reached258
Quadrature 4XOutput ON when preset is reached131
Output ON when counter is enabled, OFF when preset is reached387

HSC Configuration Register Bit table:

BitsFunction
15-12Not used
11-1000: Reset counter if SW Reset bit or physical I/Preset bit goes from 0 to 1 01: Reset counter if the SW reset bit goes from 0 to 1 11: reserved for future use
9Forced Output Configuration 0: Forced output ON for Preset 1 1: Forced output ON when enabled and OFF when Preset 1 reached
8Forced Output Control 0: Forced Output Disabled 1: Forced Output Enabled
7-6Quadrature mode 00: Reserved 01: Reserved 010: 4X Quadrature mode
4-5HSC 00: Single Phase Up counter
30: Falling Edge 1: Rising Edge
2-0Module Operating Mode 000: Normal Operation 010: Up Counter HSC 011: Quadrature

HMC7000 High Speed Counters

The HMC7000 Series products have built-in High-Speed counters that link directly to specific inputs and outputs. Specific registers and bits are predefined for setup and control of these counters. No logic is required to run the counters, other than logic that may be used to configure and control the counters.

Two inputs on the module are used as the Triggers for the High-Speed counters, and two outputs are used as the done bits. The inputs support a maximum speed of 25 KHz.

The following bits and registers are associated with a High-Speed counter:

Register/BitDescription
Enable BitThe counter will not run unless this bit is set. If this bit is reset while the counter is running, the current values will be maintained, but the trigger bit will have no effect. The done bit is reset. The reset occurs even when the enable bit is reset. If the current count value is greater than or equal to preset value, the done bit is set after the enable bit is set again.
Reset BitWhen the bit goes from false to true, the current count will reset to 0 and the done bit is reset. The reset occurs when the current is equal or greater than the preset value. The bit remains set until the reset bit goes true, even if the counter counts beyond the preset. If the enable bit is reset If the enable bit is set while the current count bit equal to the greater that the preset.
Done BitThe physical output that turns on when the current count is equal to or greater than the preset value. The bit remains set until the reset button goes true, even if the counter counts beyond the preset. If the enable bit is reset, the done bit will reset. If the enable bit is set while the current count is equal to or greater than the preset, the done bit is set.
Configuration RegisterThe register that controls how the High-Speed counter operates.
Current Counter RegisterThe register that counts the number of times that the Trigger has transitioned. The specified register is the Least Significant Word (LSW); the next consecutive register is the Most Significant Word (MSW).
Preset RegisterThe register that defines the number of counts at which the Done bit will be set (see description of Done Bit above). The specified register is the Least Significant Word (LSW); the next consecutive register is the Most Significant Word (MSW).

For how to set the HSC Configuration Register, reference the tables below.

HSC Configuration Register values for the HMC7-MI-01, HMC7-MIO-02, HMC7-MIO-04, and HMC7030A-L:

BitsFunction
15-4Not used
30: Falling Edge 1: Rising Edge
2-0Module Operating Mode: 000: Normal Operation 010: Up Counter HSC

HSC Configuration Register values for the HMC7-MIO-04, HMC7-MIO-05, HMC7-MIO-06, and HMC7-MIO-07:

Input ModeOutput ModeRegister Value
Normal ModeN/A0
High Speed, Single Phase, Up CounterOutput ON when preset is reached2
Output ON when counter is enabled, OFF when preset is reached258
Quadrature 1XOutput ON when preset is reached3
Output ON when counter is enabled, OFF when preset is reached259
Quadrature 2XOutput ON when preset is reached67
Output ON when counter is enabled, OFF when preset is reached323
Quadrature 4XOutput ON when preset is reached131
Output ON when counter is enabled, OFF when preset is reached387

The following registers and I/O are associated with the HSC. For the register addresses listed below, nn stands for which slot the module was installed (slot 1 is 01, slot 2 02, etc.). Note that not all models have access to Channels 3 and 4. Consult the specifications for the particular model being used.

High Speed Counter OptionHSC CH1HSC CH2HSC CH3HSC CH4
HSC InputX0 (terminal) Xnn000 (register)X5 (terminal) Xnn005 (register)X2 (terminal) Xnn002 (register)X7(terminal) Xnn007 (register)
HSC Reset InputX1 (terminal) Xnn001 (register)X6 (terminal) Xnn006 (register)X3 (terminal) Xnn003 (register)X4 (terminal) Xnn004 (register)
HSC Output FlagY1 (terminal) Ynn001 (register)Y6 (terminal) Ynn006 (register)Y7 (terminal) Ynn007 (register)Y0 (terminal) Ynn000 (register)
HSC Configuration RegisterMWnn00MWnn06MWn112MWn118
HSC Counter Register (Current Value)MWnn01 MWnn02MWnn07 MWnn08MWnn13 MWnn14MWnn19 MWnn20
HSC Preset RegisterMWnn03 MWnn04MWnn09 MWnn10MWnn15 MWnn16MWnn21 MWnn22
HSC Enable BitMnn080Mnn176Mnn272Mnn368
HSC Reset BitMnn081Mnn177Mnn273Mnn369
Quadrature InputsPair 1Pair 2
Counter InputsX0, X5X2, X7
Counter Reset InputX1X3
Output FlagY1Y7

MLC Series High Speed Counters

 Many Maple Systems MLC products have built-in High-Speed Counters (HSCs) that link directly to specific inputs and outputs. Specific registers and bits are predefined for setup and control of these counters. No logic is required to run the counters, other than logic that may be used to configure and control the counters. Each HSC option on a given module is referred to as a ‘channel’, with a set of physical inputs/outputs and predefined tags. The number of channels supported depends upon the particular MLC product.

Implementation of HSC on MLC Series

  1. Connect a device that will provide the high-speed pulses to one of the high-speed inputs on the expansion module.
  2. Configure the HSC using the configuration register for that channel. Note: You can write to the configuration register value using the Power-Up logic block or in a Power-Up Task.
  3. Write the HSC preset count value in that channel’s Preset Register.
  4. Enable the HSC by setting the HSC Enable Bit for that channel.
  5. HSC increments the current value register for that channel until the preset value is reached.
  6. Enable the HSC Reset Bit for that channel. This will cause the HSC current value to reset back to 0.
  7. To start the process again, simply reset (clear) the HSC Reset Bit and set the HSC Enable Bit. Note: if the HSC Enable Bit is still ON, you must reset (clear) this bit, and then set it again.

The following bits and registers are associated with a High-Speed counter:

Register/BitDescription
Enable BitThe counter will not run unless this bit is set. If this bit is reset while the counter is running, the current values will be maintained, but the trigger bit will have no effect. The done bit is reset. The reset occurs even when the enable bit is reset. If the current count value is greater than or equal to preset value, the done bit is set after the enable bit is set again.
Reset BitWhen the bit goes from false to true, the current count will reset to 0 and the done bit is reset. The reset occurs when the current is equal or greater than the preset value. The bit remains set until the reset bit goes true, even if the counter counts beyond the preset. If the enable bit is reset If the enable bit is set while the current count bit equal to the greater that the preset.
Done BitThe physical output that turns on when the current count is equal to or greater than the preset value. The bit remains set until the reset button goes true, even if the counter counts beyond the preset. If the enable bit is reset, the done bit will reset. If the enable bit is set while the current count is equal to or greater than the preset, the done bit is set.
Configuration RegisterThe register that controls how the High-Speed counter operates.
Current Counter RegisterThe register that counts the number of times that the Trigger has transitioned. The specified register is the Least Significant Word (LSW); the next consecutive register is the Most Significant Word (MSW).
Preset RegisterThe register that defines the number of counts at which the Done bit will be set (see description of Done Bit above). The specified register is the Least Significant Word (LSW); the next consecutive register is the Most Significant Word (MSW).

MLC Base Units with Built-in I/O (MLC1-F, MLC1-E, and MLC2-E models)

MLC1-F, MLC1-E, and MLC2-E base models support Single Phase Up, Single Phase Down, and Quadrature 4X modes at speeds of up to 200 kHz.

The following registers and I/O are associated with the MLC Base Unit HSC:

FunctionChannel 1Channel 2IEC Data Type
Trigger Input or Encoder AX0X2BOOL
Up/Down Input or Encoder BX1X3BOOL
HW Reset InputX4X5BOOL
Reset Bit (Internal)M241M721BOOL
HW Done OutputY2Y3BOOL
Preset Reached (Internal Done Bit)M242M722BOOL
Enable BitM240M720BOOL
Configuration RegisterMW10MW40WORD
Current Count Register (LSW, MSW)MW11, MW12MW41, MW42DWORD
Preset Register (LSW, MSW)MW13, MW14MW43, MW44DWORD

HSC Configuration Register values for MLC Base units:

Input ModeOutput ModeRegister Value
Normal Input (HSC not enabled)N/A0
High-Speed Single Phase Counter, Up or Down based on Up/Down InputHW Done Bit Disabled2
HW Done output ON when preset is reached258
Done output ON when counter is enabled, OFF when preset is reached770
Quadrature 4XHW Done Bit Disabled131
HW Done output ON when preset is reached387
Done output ON when counter is enabled, OFF when preset is reached899

High-Speed Expansion Modules (MLE-0808NH, MLE-0808PH)

The MLE-0808NH and MLE-0808PH expansion modules support four Single Phase Up counters at speeds of up to 25kHz or two Quadrature counters in 1X, 2X, or 4X modes at speeds of up to 5kHz on Channel 1 or 20kHz on Channel 2. If both channels are used simultaneously in quadrature mode, the max speed is 5kHz for both.

The following registers and I/O are associated with the MLC Expansion Modules HSC:

FunctionChannel 1Channel 2Channel 3Channel 4IEC Data Type
Trigger Input (Single Phase)Xnn000Xnn005Xnn002Xnn007BOOL
Encoder A (Quadrature)Xnn000N/AXnn002N/ABOOL
Encoder B (Quadrature)Xnn005N/AXnn007N/ABOOL
HW Reset Input (Single Phase)Xnn001Xnn006Xnn003Xnn004BOOL
HW Reset Input (Quadrature)Xnn001N/AXnn003N/ABOOL
Reset Bit (Internal)Mnn209Mnn273Mnn337Mnn401BOOL
Done Output (Single Phase)Ynn001Ynn006Ynn007Ynn000BOOL
Done Output (Quadrature)Ynn001N/AYnn007N/ABOOL
Preset Reached (Internal Done Bit)Xnn048Xnn049Xnn050Xnn051BOOL
Enable BitMnn208Mnn272Mnn336Mnn400BOOL
Configuration RegisterMWnn10MWnn14MWnn18MWnn22WORD
Preset Register (LSW, MSW)MWnn11, MWnn12MWnn15, MWnn16MWnn19, MWnn20MWnn23, MWnn24DWORD
Count Register (LSW, MSW)XWnn04, XWnn05XWnn06, XWnn07XWnn08, XWnn09XWnn10 XWnn11DWORD

HSC Configuration Register values for MLC Expansion Modules:

Input ModeOutput ModeRegister Value
Normal Input (HSC not enabled)N/A0
High-Speed Single Phase UP CounterHW Done output ON when preset is reached2
HW Done output ON when counter is enabled, OFF when preset is reached258
Quadrature 1XHW Done output ON when preset is reached3
HW Done output ON when counter is enabled, OFF when preset is reached259
Quadrature 2XHW Done output ON when preset is reached67
HW Done output ON when counter is enabled, OFF when preset is reached323
Quadrature 4XHW Done output ON when preset is reached131
HW Done output ON when counter is enabled, OFF when preset is reached387

Example

High-Speed Counter Operation to implement High-Speed Counter Operation (using a MLC CPU base module as example):

1.

Connect a device to X0 (Channel 1) or X2 (Channel 2) that will provide the high-speed pulses to the expansion module.


2.

Configure for HSC mode using the configuration register MW0010 (Channel1) or MW0040 (Channel2).


3.

Write the HSC preset count value in MW0013 (Channel 1) or MW0043 (Channel 2).


4.

Enable the HSC by setting the HSC Enable Bit M00240 (Channel 1) or M00720 (Channel 2).


5.

HSC increments (starting from 0) or decrements (starting from 4,294,967,295) the current value register in MW0011 (Channel 1) or MW0041 (Channel 2) until the preset value is reached. Then HSC sets Y2 (Channel 1) or Y3 (Channel 2).


6.

Enable the HSC Reset Bit by setting M00241 (Channel 1) or M00721 (Channel 2). Or by setting Reset Pin X4 (Channel 1) or Reset Pin X5 (Channel 2). This will cause the HSC current value to reset back to 0 and the output Y2 (Channel 1) or output Y3 (Channel 2) will reset (clear) to 0. MLC PLC Series I/O Module Guide 24 MLC PLC Series I/O Module Guide 24


7.

To start the process again, simply reset (clear) the HSC Reset Bit and set the HSC Enable Bit. Note: If the HSC Enable Bit is still ON, you must reset (clear) this bit, and then set it again.

Scroll to Top