using CTU block for uint counter

Hicham.M
2016-08-08
2016-08-15
  • Hicham.M - 2016-08-08

    Hello,
    I want to use the CTU block to count beyond WORD type max (65,535).
    I put in the output of the CTU block an UINT variable, it compiles with no errors but I'm not sure if this would work or not ?

    What's the best way to do this ?

    Thank you

     
  • Anonymous - 2016-08-09

    Originally created by: scott_cunningham

    I deleted my first answer due to not understanding the question.

    The CTU should work with UINT, INT, WORD. Check the help - it says what is supported. I don't think longs are, though (may be wrong)

     
  • Hicham.M - 2016-08-09

    scott_cunningham hat geschrieben:
    I deleted my first answer due to not understanding the question.
    The CTU should work with UINT, INT, WORD. Check the help - it says what is supported. I don't think longs are, though (may be wrong)

    Thank you for your answer, In the help it says the following

    Function block Incrementer (CTU):
    The input variables CU and RESET as well as the output variable Q are type BOOL, the input variable
    PV and the output variable CV are type WORD.

    Also in the first chapters of the help, they mention that the size of type WORD variable is 16bit means it's max is 65535.

    Am I reading the help wronge ?

     
  • Anonymous - 2016-08-10

    Originally created by: scott_cunningham

    Ah, you are using version 2.3. Sorry, missed that. So a WORD is "the same" as a UINT. You simply need to cast your variables WORD_TO_UINT() or UINT_TO_WORD(). In general programmers signal but coded usage with WORD and arithmetic with an UINT. Otherwise they are both 16 bit unsigned.... Embedded controller programmers and C programmers will often use BYTE WORD and LONG instead of USINT UINT UDINT.

     
  • Hicham.M - 2016-08-11

    scott_cunningham hat geschrieben:
    Ah, you are using version 2.3. Sorry, missed that. So a WORD is "the same" as a UINT. You simply need to cast your variables WORD_TO_UINT() or UINT_TO_WORD(). In general programmers signal but coded usage with WORD and arithmetic with an UINT. Otherwise they are both 16 bit unsigned.... Embedded controller programmers and C programmers will often use BYTE WORD and LONG instead of USINT UINT UDINT.

    Now I see, I'm an embedded software developer and have this small project using PLC.

    Based on codesys manual
    WORD is the same as UINT : size 2 bytes with max value : 65535.
    I need to use DWORD type to get my counter beyond 65535 which is not possible with CTU bloc !!

    is there a solution for that ?

     
  • Anonymous - 2016-08-12

    Originally created by: scott_cunningham

    Use two CTU blocks - one feeding into the other, with rollover mode.

    Or, just build your own (ST language may be easiest). You simply need to increment your var on rising edge (R_TRIG).

    Or check into the OSCAT library (OSCAT.de). I think it has larger CTUs.

     
  • shooter - 2016-08-15

    indeed look at oscat for a double word counter, or make it yourself, you will learn a lot from it.

    if a DW is not enough, you will need to make a 8 byte counter, with for example an array.

     

Log in to post a comment.