February 6th, 2012, 05:09 PM
Being a series A, there is no individual counter reset, so instead they use a preset to 'reset' the count to the CtrXPreset value in the card config. The problem we are having is that the counter is no longer being reset to the preset value, even when forcing the Ctr2SoftPreset value in the output word. The Ctr2Preset value is "0" and it just stays at the current count. I've read through the manual and it only states that setting the CtrXSoftPreset will move the Preset value to the count, so I would expect to see this revert to a "0" value. It does not do this for any of the counters on the card. I've tried enabling/disabling the counters while doing this, too.
February 7th, 2012, 03:12 AM
For those, and dozens of other reasons, I can't figure out why people insist on trying to use the raw values of "High Speed Counter Modules" in every PLC. Why reinvent the wheel every time you use a different counter module, or PLC, or deal with various odd preset/reset commands and sequences?
Make a couple of tags.... "Last_Scan_Value" (DINT), "Scan_Delta_Count" (DINT), "Total_Counts" DINT), perhaps a "Counter_EU_Scaler" (real) and "Count_EU_Value" (real). Pretend that "HSC_RAW_COUNTER_IN" is an alias to the actual counter module raw value.
Add in this rung somewhere:
SUB HSC_RAW_COUNTER_IN Last_Scan_Value Scan_Delta_Count MOV HSC_RAW_COUNTER_IN Last_Scan_Value ADD Scan_Delta_Count Total_Counts Total_Counts
If you want to scale to engineering units, just use another rung of:
DIV Total_Counts Counter_EU_Scaler Count_EU_Value
To reset the counter to zero, just do:
MOV 0 Total_Counts
To preset the counter to any particular value:
MUL Preset_EU_Value Counter_EU_Scaler Total_Counts
The above is a bit crude and dirty, for extra points, on the Logix 5000 platform, if you have the FBD package, it is usually a good idea to run the raw value from the module through a PMUL instruction, with a word size of 12 to 24. The PMUL is nice, as it eliminates the minor math error on integer rollover, and automagically generates the Scan_Delta_Count as its output.
A further refinement, that I usually include, is to use enable bits before the add instruction, so I only count when I actually want to count.
A bonus of the above method, is that as long as your PLC has retentive values, your count is held through power cycles, unlike most HSC modules without major pains.
February 7th, 2012, 10:08 AM
Well, bud, I wasn't asking for your personal philosophy on programming styles...but we all thank you anyway.
I didn't write this program, nor was I asked to modify it. I was asked to troubleshoot it and exhausted all my attempts before coming here. There was no rhyme or reason for what was happening. I took the same program and re-downloaded to the controller, and it magically started working.
February 8th, 2012, 03:34 AM
Welcome to ignore!