CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Sat Nov 18, 2017 3:50 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sun Oct 08, 2017 8:54 am 
Offline

Joined: Sun Oct 01, 2017 3:58 pm
Posts: 2
Hi all,

I'll first describe the goal:
1. Have an outside device write into a variable of codesys.
2. Detect the variable in (1) has been changed.
3. After detection, make the modbus master write to another device via trigger.

what I've tried to do:
make a stuct with:
LastValue : BOOL; //linked to the another device in (3)
CurrentValue : BOOL; //linked to the outside device in (1)
Trigger : BOOL; //linked to the modbus master trigger

now i got a task where I do the following:
Trigger := FALSE;
IF (CurrentValue <> LastValue) THEN
LastValue := CurrentValue;
Trigger := TRUE;
END_IF

When i ran this code, the trigger didn't work as planned, meaning the modbus master didn't update me about the change.
i mainly suspect about the syncing of the tasks, one task runs the code above controlling the trigger and another task runs the modbus master module who checks the trigger rising edge and performs the writing action.

Questions:
1. how would you sync between the two tasks? how to control the trigger properly?
2. What type of scheduler protocol is being used, might help me understand the problem.

Thanks in advance for any help
Roy.


Top
   
PostPosted: Sun Oct 08, 2017 12:55 pm 
Offline
Frequent User
Frequent User

Joined: Wed May 04, 2016 6:00 pm
Posts: 176
Reset the trigger in the other task.


Top
   
PostPosted: Mon Oct 09, 2017 2:28 pm 
Offline

Joined: Sun Oct 01, 2017 3:58 pm
Posts: 2
after linking code program and the modbus module to the same task
and also found a bug i had with the program, the trigger worked well!

no need for different tasks.

adding the code i ran with:

TYPE Modbus_Data :
STRUCT
Old:ARRAY[0..15] OF BOOL := [16(FALSE)];
New:ARRAY[0..15] OF BOOL := [16(FALSE)];
Trigger:BOOL := FALSE;
END_STRUCT
END_TYPE

arrModbusData: ARRAY[0..1] OF Modbus_Data;

PROGRAM Modbus_programm
VAR
wordIndex : UINT;
bitIndex : UINT;
isTriggerNeeded : BOOL;
modbusDataArrayLength : int := SIZEOF(arrModbusData)/SIZEOF(Modbus_Data);
END_VAR
VAR CONSTANT
NUMBER_OF_BITS_IN_WORD : INT := 16;
END_VAR
_____________________________________________________________________________________
isTriggerNeeded := FALSE;
FOR wordIndex:=0 TO modbusDataArrayLength -1 DO
arrModbusData[wordIndex].Trigger := FALSE;
FOR bitIndex:=0 TO NUMBER_OF_BITS_IN_WORD - 1 DO
IF(arrModbusData[wordIndex].New[bitIndex] <> arrModbusData[wordIndex].Old[bitIndex]) THEN
arrModbusData[wordIndex].Old[bitIndex] := arrModbusData[wordIndex].New[bitIndex];
isTriggerNeeded := TRUE;
END_IF;
END_FOR;
IF(isTriggerNeeded = TRUE) THEN
arrModbusData[wordIndex].Trigger := TRUE;
END_IF;
END_FOR;


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

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 4 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:  
cron
Powered by phpBB® Forum Software © phpBB Limited