k 1 ; Module Number 1
0 Counting mode x1
r 999 ; Starting value of counter
r 998 ; Register preset value
1 ; Enable C static inversion
1 ; CCO static inversion
0 Input A is normal (counting)
0 Input B is normal
5 ; Measurement mode: Automatic frequency
100 ; Measurement window of 100 ms
0 Enable M static positive logic
2 ; TCO dynamic positive pulse
All parameters must be within the allowed range, otherwise the error flag fPar_Srr is set and the diagnostic register rDiag records the error code.
5.3 Execute Function Block EXEC
EXEC is used to send commands such as starting counters, reading count values, loading preset values, starting/stopping measurements, etc. Three parameters: module number, command code, and destination/source registers. The supported commands include:
LdCtPress: Load counter preset value
LdReppres: Load comparison register value
ModMsConf: Change measurement configuration (runtime)
LdMsVal: Set measurement window/time base
RdCt: Read the current count value (24 bits)
RdMsImp: Read and measure the original pulse count (16 bits)
RdMsUnit: Read the converted value (floating point number, Hz or s)
StartCt / StartMs / StopMs
RdIdent: Read module identifier (verify if the module is working properly, return value 17xx)
5.4 GRAFTEC Programming Example
The manual provides three complete GRAFTEC application routines, demonstrating the programming structure in practical engineering.
Example 1: Simple counter (frequency divider)
Task: Counter preset value 500, compare register 900, Enable C static inversion, CCO static positive logic. When the counter reaches 900, the CCO outputs a high level. The user program detects this and flips a digital output, reloading the counter to 500 to continue counting. The program calls INIT in the initialization step (IST), polls the CCO status in the subsequent steps, and executes overloading.
Example 2: Motion Control with Incremental Encoder
Task: The workbench is driven by a DC motor and equipped with a 500 pulse/rev incremental encoder (screw pitch 1 mm). It needs to move from the starting point A to B, pause and then return to A. During operation, it accelerates quickly and switches to slow speed when approaching the target, ultimately achieving precise positioning. This example uses x2 counting mode to directly control the fast/slow and direction of the motor through CCO output, and software polls the CCO status to achieve GRAFTEC step switching. The program also handles negative position display (by subtracting an offset to avoid negative display). This application demonstrates the capability of the H110 module as an axis positioning controller.
Example 3: Measuring object size with a photoelectric grid
Task: When an object on the conveyor belt obstructs the photoelectric grid, count the pulses proportional to the speed of the conveyor belt to measure the length of the object for sorting. Connect the photoelectric grid signal to the Enable C input (static inversion), connect the counting pulse to the A input, and connect the B input to a fixed high level (or GND after inversion). When the photoelectric grid is obstructed, the Enable C is activated and the counter starts counting; When the obstruction ends, the counter stops and the read count value is the length of the object. The program polls the CStart status in GRAFTEC and stores the results in a continuous register queue after each measurement. This scheme has been used for sorting melons and apricots in the south of France.
Error handling and diagnosis
The module will detect parameter errors during runtime. If a parameter in Initiat exceeds the range, the module will automatically set it to the minimum value and set the global error flag fPar-Err. At the same time, the diagnostic register rDiag will be encoded in bytes: FB number (1=Initiat, 2=EXEC), parameter number, and module number. For example, 00 01 06 02 indicates that parameter 6 (CCO configuration) of module 2 is incorrect. Users can clear this flag in XOB 16 or initialization step. In addition, EXEC command code errors will report "Symbol not defined" during assembly. Hardware failure can be verified by reading the identification code through RdIdent. The normal value should be 17xx (specific versions such as 2759, 1761, etc.). If it reads back 0, it indicates module failure or address error.
Parallel use of counting and measurement
The manual clearly points out that counting and frequency measurement can run in parallel on the same module. For example, in motion control examples, the frequency of the encoder signal can be measured while positioning to obtain real-time speed. Just configure the counting parameters and measuring parameters (parameter 9=5, parameter 10=window time) in INIT at the same time, call StartMs to start the measurement after initialization, and then read the measurement results in the main loop. Due to having only one display module, usually only one quantity is displayed, but PCD registers can store two values simultaneously.