I am working on a project to read values from various flowmeters via the WAGO 750-638 module (2 channels, 16-bit, 500 Hz). Unfortunately, I don’t know where to start on the CODESYS 3.5 side.
Would you have a tutorial or documentation that could guide me regarding the hardware configuration of this card, the functional blocks (FB/FC) to use, and the integration into CODESYS?
I haven’t found much on the forum aside from the module’s technical documents.
This module doesn’t have complex operation that requires the use of any special library or function blocks. Use the “Process Image” section of the 750-638 hardware manual as your guide to operation, and then simply map variables to the various process image inputs and outputs in the module’s “KBus I/O Mapping” area.
The idea is to read pulses and increment the two counters (reading in only one direction).
I added the card and declared my variables, as well as created my persistent variables (the two counters that will be exposed via OPC UA).
Normally, my S0 (cpt1_status) and S1 (cpt2_status) inputs should be equal to 0 (00000000b), I did the initialization in my main program (is this correct? I don’t think so because each time it will reset my S0 and S1).
1/ How can I test whether I have indeed received a pulse in order to increment my counter?
2/ I’m afraid either of missing some pulses or, conversely, of counting the same pulse multiple times.
The Status bytes (i.e. Cpt1_Status) is read-only from the PLC-code. This is an INPUT to the plc, generated by the 638 module itself to indicate some status conditions. So instead of trying to set it to zero, you would monitor it for various conditions and then take action if needed.
Please don’t declare your Persistent Variable within the “VariablePersistent” object itself. This can lead to issues. Instead, declare your CompteurTot1 variable within PLC_PRG or a GVL. Then open the VariablePersistent object in a tab, right-click, and choose “Add all instance paths”. Use that variable in your programs using the declared namespace, not the VariablePersistent namespace.
Remember that the 750-638 module is inherently a counter input. It will count the pulses for you and the result will increment Compteur1 all on its own. Some plc code will be required if you want to store this value as a persistent retained variable. The module itself will reset to zero on power up. You will need to create a routine to use the “Counter setting value 1” and _OUT1 control byte to transfer your retained value into the module on power up. Then the counter can increment from there (and other code can take that value and load it back into the retained variable).
Normally, it’s not necessary to reset the physical counter (set_compteur1) — it automatically resets to zero after a restart or power outage, correct?
Is it the same in case of overflow? Should the value to test be <65535 or 65536? It’s not very clearly detailed in the manual, and I’m concerned there might be an offset or that I might miss a pulse.
I declared my variable compteurTot1 (persistent) as REAL, and I associated it with a variable of type WORD to handle the overflow. Could that cause a problem? Or should I instead manage the MSB and LSB separately (most significant bit and least significant bit), then combine them into a REAL variable afterward?