Million counter

sarathbabu
2014-11-03
2014-11-08
  • sarathbabu - 2014-11-03

    Hi all,

            Counter has a limit of 65535 but if I want to create counter for 1 million times is there any counter or I have to manually count 65535 multiple times each and every time counter reaches limit.
    

    Sarath

     
  • Sendarix - 2014-11-03

    Hello,

    It depends on the type you use, the value 65535 is used for WORD and UINT, you could use an REAL, LREAL (which is even larger than REAL), DWORD, DINT or UDINT.

    DWORD can go from 0 to 4 294 967 295, so that one should be enough, DINT goes from -2 147 483 648 to +2 147 483 647, and UDINT is the same as DWORD, goes from 0 to 4 294 967 295.

    REAL goes from 1.175494351e-38 to 3.402823466e+38, Which is a LOT. And LREAL goes from 2.2250738585072014e-308 to 1.7976931348623158e+308.

    Hope this helps

    • Sendarix
     
  • sarathbabu - 2014-11-04

    Hi

          Codesys library counter is having limitation that Preset value should be WORD, so no other choice right?
    

    Sarath

     
  • Sendarix - 2014-11-04

    Hi,

    In my opinion, it would be easier to just make a new counter, without the counter from the standard library, which language are you programming in? ST, Ladder or FBD?

    I do have some code which is pretty easy to understand in ST which I ca provide, haven't used Ladder in a while, so I'm not sure I could provide that, but could always try the translation.

    My code consist of my own Rising trigger, but since that one is in the Standard library, then it should be easy.

    VAR
            Button: BOOL;
       Trigger: R_TRIG;
            Counter_Value: DWORD; (* COULD BE DWORD, DINT or UDINT, or even REAL and LREAL(if the controller supports it) *)
    END_VAR
    Trigger(CLK:= Button);   (* The button trigger the Rising trigger *)
    IF Trigger.Q THEN   (* Output from the Rising Trigger *)
    Counter_Value := Counter_Value + 1;   (* Value of the Counter *)
    END_IF
    IF Counter_Value >= 1000000 THEN
    OUTPUT := TRUE;   (* If you gonna trigger something *)
    Counter_Value := 0;  (* Reset of the Counter *)
    END_IF
    

    This is a very easy code, which is in ST.

    • Sendarix
     
  • shooter - 2014-11-08

    told you many times, look in oscat.de for a nice library.
    however yes preset is word, but you can use 2 counters in series this will get you to a DWORD .

     

Log in to post a comment.