CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Thu Jul 27, 2017 1:32 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Mon Aug 08, 2016 7:55 am 
Offline

Joined: Mon Aug 01, 2016 8:12 am
Posts: 5
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


Top
   
PostPosted: Tue Aug 09, 2016 3:12 am 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 231
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)


Top
   
PostPosted: Tue Aug 09, 2016 7:42 am 
Offline

Joined: Mon Aug 01, 2016 8:12 am
Posts: 5
scott_cunningham wrote:
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 ?


Top
   
PostPosted: Wed Aug 10, 2016 2:10 pm 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 231
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.


Top
   
PostPosted: Thu Aug 11, 2016 8:14 am 
Offline

Joined: Mon Aug 01, 2016 8:12 am
Posts: 5
scott_cunningham wrote:
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 ?


Top
   
PostPosted: Fri Aug 12, 2016 5:32 am 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 231
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.


Top
   
PostPosted: Mon Aug 15, 2016 10:51 am 
Offline
Frequent User
Frequent User

Joined: Thu Jun 14, 2007 9:49 am
Posts: 974
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.

_________________
shooter@home.nl
computer shooter
paul deelen
jacob van wassenaerstraat 29
NL 5224 GG 's-Hertogenbosch
skype shooter paul.deelen
phone +31736139136


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 7 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited