CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Fri Nov 15, 2019 7:47 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Can bus issue
PostPosted: Tue Mar 05, 2019 8:52 pm 
Offline

Joined: Tue Mar 05, 2019 7:31 pm
Posts: 7
Hello,

I just started programming with CodeSys. Setup is an Exor etop513 and a Seneca ZC-24DI digital input module. I copied all can settings from a project that I know is reading the bus ok. I have a switch setup into input 9 where I want to latch the off - on transition. The switch is mapped into the PDO as Switch_Input1.

Here's the program:

PROGRAM Main
VAR
Enable_view: BOOL := FALSE;
Switch_on: BOOL := FALSE;
Switch_Count: INT := 0;
Switch_on_L: BOOL := 0;
END_VAR

Switch_on := Switch_Input1;
IF Switch_on = TRUE AND Switch_on_L = FALSE THEN
Switch_Count := Switch_Count + 1;
END_IF
Switch_on_L := Switch_on;

In Debug mode the switch is read correctly only once and then never changes. If I do a "Reset Warm" then the switch will be read correctly once again.

Any help would be greatly appreciated!


Top
   
 Post subject: Re: Can bus issue
PostPosted: Wed Mar 06, 2019 8:33 am 
Offline
Frequent User
Frequent User

Joined: Fri Feb 23, 2018 3:41 pm
Posts: 169
Is your IO value (Switch_Input1) refreshed correctly ?


Top
   
 Post subject: Re: Can bus issue
PostPosted: Wed Mar 06, 2019 2:15 pm 
Offline

Joined: Mon Nov 03, 2014 7:15 am
Posts: 48
Hi KMor77,

in your code you have the IF-clause

Quote:
IF Switch_on = TRUE AND Switch_on_L = FALSE THEN


As the variables are defined as BOOL, you can say

Code:
IF Switch_on AND NOT Switch_on_L THEN


this will work too. But in general, your code looks ok. As dFx mentioned, the question is if your hardware comes in correctly. How is Switch_Input_1 refreshed on the bus? In the device-manager, on the Can-device Tab I/O Mapping you find a field "BusCycleOptions". Try here to select the task in which your program code is running.
Attachment:
bild1.png

Good luck
Alfred


You do not have the required permissions to view the files attached to this post.


Top
   
 Post subject: Re: Can bus issue
PostPosted: Wed Mar 06, 2019 9:44 pm 
Offline

Joined: Tue Mar 05, 2019 7:31 pm
Posts: 7
Thanks for the response,

I've tried using Main Task and Parent bus cycle setting but neither worked.

The value is refreshed only once at the start of the program only.

I was under the impression that the bus continuously cycles and updates the I/O values according to the cycle period set in the manager.

Could it be a debugger problem?


Top
   
 Post subject: Re: Can bus issue
PostPosted: Thu Mar 07, 2019 8:25 am 
Offline

Joined: Mon Nov 03, 2014 7:15 am
Posts: 48
That's strange :?

If you look in online status on the devices CANOpen I/O mapping, what happens with the Input Switch_input_1 when switching ON and OFF?
Attachment:
bild2.png


If nothing happens, try to remove your mapping variable and look if the status then is refreshed correctly...
Attachment:
bild3.png


Another stupid question: The code is called cyclical, not blocked by any condition?

Good luck

Alfred


You do not have the required permissions to view the files attached to this post.


Top
   
 Post subject: Re: Can bus issue
PostPosted: Thu Mar 07, 2019 1:18 pm 
Offline

Joined: Tue Mar 05, 2019 7:31 pm
Posts: 7
Thanks Alfred,

I'll try that today and let you know what happens.



When you ask if the code is called cyclical that raises a question - My code is the main program and not called from anywhere. I thought the PLC just loops through the code Continuously.


Top
   
 Post subject: Re: Can bus issue
PostPosted: Thu Mar 07, 2019 2:55 pm 
Offline

Joined: Mon Nov 03, 2014 7:15 am
Posts: 48
Okay, that might be the problem!

In your project, you should see a "Task configuration". Double click the Task below that and you should get a window like this:

Attachment:
bild4.png


If the MAIN is not in the task, add it with drag and drop or by clicking "Add Call".
If you don't see a Task configuration below the application, you need to add one by right-clicking on Application and select "add object" and then "Task configuration".

Attachment:
bild5.png


Codesys is a task-based system. If you want your MAIN program to be called cyclical, you have to place it in a cyclic task. That's different to a PLC like Siemens, where you have an OB1, that is called by the system all the time.

Hope that helps... Good luck!

Alfred


You do not have the required permissions to view the files attached to this post.


Top
   
 Post subject: Re: Can bus issue
PostPosted: Thu Mar 07, 2019 4:29 pm 
Offline

Joined: Tue Mar 05, 2019 7:31 pm
Posts: 7
Thanks - Yes I have all of that set up already so I thought the Main task would cycle every Interval Time (100ms in this case) - There's something subtle I'm missing but I won't get back to try anything until this afternoon.


Top
   
 Post subject: Re: Can bus issue
PostPosted: Thu Mar 07, 2019 11:14 pm 
Offline

Joined: Thu Aug 17, 2017 12:35 pm
Posts: 34
Maybe the IO needs a sync signal to update the IOs and the CanOpen Master is not configured to send the sync telegram?


Top
   
 Post subject: Re: Can bus issue
PostPosted: Fri Mar 08, 2019 1:53 pm 
Offline

Joined: Tue Mar 05, 2019 7:31 pm
Posts: 7
I have the CANopen manager set to "Enable Sync Producing" with a cycle period of 50 ms. Looks like I'm going to have to figure out how to go to a lower level to read the PDOs and/or find a diagnostic tool for the bus.


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

All times are UTC+01:00


Who is online

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