Can bus issue

KMor77
2019-03-05
2019-03-08
  • KMor77 - 2019-03-05

    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!

     
  • dFx

    dFx - 2019-03-06

    Is your IO value (Switch_Input1) refreshed correctly ?

     
  • alwoso - 2019-03-06

    Hi KMor77,

    in your code you have the IF-clause

    Zitat:
    IF Switch_on = TRUE AND Switch_on_L = FALSE THEN

    As the variables are defined as BOOL, you can say

    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.

    Good luck
    Alfred

    IMG: bild1.png

     
  • KMor77 - 2019-03-06

    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?

     
  • alwoso - 2019-03-07

    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?

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

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

    Good luck

    Alfred

    IMG: bild2.png

    IMG: bild3.png

     
  • KMor77 - 2019-03-07

    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.

     
  • alwoso - 2019-03-07

    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:

    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".

    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

    IMG: bild4.png

    IMG: bild5.png

     
  • KMor77 - 2019-03-07

    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.

     
  • hence.persson - 2019-03-07

    Maybe the IO needs a sync signal to update the IOs and the CanOpen Master is not configured to send the sync telegram?

     
  • KMor77 - 2019-03-08

    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.

     

Log in to post a comment.