CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Tue May 23, 2017 6:04 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri May 05, 2017 7:23 am 
Offline

Joined: Wed May 04, 2016 2:43 pm
Posts: 17
Hi Everyone
I'm currently working on a project with a lot a data to send to a TouchScreen and as I'd like to optimize the communication speed, I have to use array
But for example, I build an array with all the data for my motor so I obtain
Motor1 array[1..10] of word;
So if in my program I do:
LD word1
ST motor1[1]

So I'd like if there is a way to give to this motor1 a name or a comment, so if I use my mouse on it, I could see the comment

Many thanks in advance for your help :)


Top
   
PostPosted: Fri May 05, 2017 6:51 pm 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 218
Solution 1 (I recommend):
  • Have your speaking variables and structures as you need.
  • Have a HmiData array of WORDs
  • Create a PRG that is called every PLC scan with the name like "MapHmiData"
  • Explicitely map speaking variables to HmiData array (read only variables)
  • Explicetly map HmiData array entries to speaking variables (user write variables)

Advantages:
  • You get to use your speaking variables
  • You control scaling exactly as you need (i.e from REAL to WORD)
  • You can see exactly what variable goes to which array entry - no math, no counting in your head, etc.

Disadvantages:
  • Uses twice as much variable space (I've never run out of RAM space on a CoDeSys platform)
  • Manually code each assignment (but I prefer to see the explicit list 3 years from now when I forget what was being sent)
  • Takes CPU time (copying data into arrays of 100 or 200 WORDs does not take much processing power anymore - I've never had to optimize this until now over 11 years!)

Code Example:
Code:
PROGRAM MapHmiData
VAR
END_VAR

//copy drive1 data
GVL_APP.HmiData[0] := INT_TO_WORD(GVL_APP.Drive1.ControlWord);
GVL_APP.HmiData[1] := INT_TO_WORD(GVL_APP.Drive1.StatusWord);
GVL_APP.HmiData[2] := REAL_TO_WORD(GVL_APP.Drive1.Temperature * 10); //0.1 deg C resolution
GVL_APP.HmiData[3] := INT_TO_WORD(GVL_APP.Drive1.ActualCurrent);
GVL_APP.HmiData[4] := DWORD_TO_WORD(SHR(GVL_APP.Drive1.HourCounter,16)); //high word
GVL_APP.HmiData[5] := DWORD_TO_WORD(GVL_APP.Drive1.HourCounter); //low word

//copy drive2 data
GVL_APP.HmiData[6]  := INT_TO_WORD(GVL_APP.Drive2.ControlWord);
GVL_APP.HmiData[7]  := INT_TO_WORD(GVL_APP.Drive2.StatusWord);
GVL_APP.HmiData[8]  := REAL_TO_WORD(GVL_APP.Drive2.Temperature * 10); //0.1 deg resolution
GVL_APP.HmiData[9]  := INT_TO_WORD(GVL_APP.Drive2.ActualCurrent);
GVL_APP.HmiData[10] := DWORD_TO_WORD(SHR(GVL_APP.Drive2.HourCounter,16)); //high word
GVL_APP.HmiData[11] := DWORD_TO_WORD(GVL_APP.Drive2.HourCounter); //low word

//copy user data to controller
GVL_APP.UserCtrl.AutoRun     := WORD_TO_BOOL(GVL_APP.HmiData[20]);
GVL_APP.UserCtrl.CmdSpeed    := WORD_TO_INT(GVL_APP.HmiData[21]);
GVL_APP.UserCtrl.CyclesToRun := GVL_APP.HmiData[22];


Solution 2 (old school PLC programmer trick):
  • Define HmiData array at a specific memory location (AT %MW0)
  • Define your speaking variables at specific memory locations so they overlap with HmiData

Advantages:
  • Doesn't "waste" RAM by having two WORDS for same data
  • Doesn't use extra CPU time

Disadvantages:
  • Much work up front to align the memory locations
  • Cannot scale anything - what's in the memory location is how it will be.


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

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 5 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