Supported platforms: CODESYS 2.3

 

Using Interrupt Functionality with J1939

Some engines require a certain message interval for TSC1 message. In some cases the software cycle time affects so that the TSC1 message is not sent in the correct time frame. In this case, the engine may not respond to the RPM (rounds per minute) request. In this case, use the interrupt functionality described here. The interrupt functionality sends the TSC1 message in the correct time frame regardless of the software cycle time.

 

Required:

  • Epec 3606, 3610, 3720, 3724 or 4602 control unit with firmware version 1.168 or newer

  • 3000InterruptSendHandler.lib (can also be used with 4602)

  • 3000SetTickExt.lib (can also be used with 4602)

  • J1939.lib  (POU J1939_MessageChecksum (FUN))

    • J1939.lib version 1.1.2-1.1.3 requires 3000InterruptSendHandler.lib version 1.0.0

    • J1939.lib version 1.2.X (or newer) requires 3000InterruptSendHandler.lib version1.0.1 (or newer)

 

 

 

In case the interruption code takes longer period of time than its call interval, the main program may not respond correctly. Therefore, avoid unnecessary code in the interrupt function. If possible, add solely the message sending to the interruption code.

 

 

To use the interrupt functionality:

 

  1. Check that your control unit firmware version is 1.168 or newer (using for example CANmoon diagnostics tool). Update firmware if needed.

  2. Check in Epec MultiTool Creator that the cycle time for TSC1 message is set to 0 (the default value is 0):
    In Epec MultiTool Creator, double-click the correct device, select J1939 and TSC1 message in Tx section. Check the Cycle Time field.

  3. In the CODESYS application, initialize interrupt handler and add a message object:

     

    FUNCTION_BLOCK Init_IRQ

     

    VAR

             InitDone: BOOL;

    END_VAR

     

    IF NOT InitDone THEN

             SYSINSTALLTICKHANDLER(INDEXOF(IRQ_Handler), 10);

             G_IRQ_MO := CANAPI_ADD_MO(G_CANAPI_CAN2);

             InitDone := TRUE;

    END_IF

     

  4. Implement the interrupt handler:

     

    PROGRAM IRQ_Handler

    VAR

             TSC1_SendMsg          :ISH_J1939_SendHandler;

             TSC1_SendStatus       :J1939_ReturnCodes;

    END_VAR

    IF G_IRQ_MO<>0 THEN

             TSC1_SendMsg(i_IRQ_MO:=G_IRQ_MO,

                i_pPGN := ADR(J1939_CAN2.Out.Default.PGN_TSC1),

                i_MsgDataValid := G_TSC1_DataValid,

                o_Status=>TSC1_SendStatus);

    END_IF

     

  5. Before assigning values to the message variables, set the validity flag to FALSE. After assigning, set the flag to TRUE. This prevents sending the message with incomplete data.

     

    FUNCTION_BLOCK RpmRequest

    VAR_INPUT

             i_RequestedRPM: UINT;

    END_VAR

    G_TSC1_DataValid := FALSE;

    J1939_CAN2.Out.Default.TSC1_EngOverrideCtrlMode:=2#01;

    J1939_CAN2.Out.Default.TSC1_EngRqedSpeed_SpeedLimit:=SHL(UINT_TO_WORD(i_RequestedRPM),3);

    G_TSC1_DataValid:=TRUE;

     

     

  6. The firmware calls now the interrupt handler automatically.

 

 

 

See also

 

 

 

Source file topic000969.htm

Last updated 21-Feb-2025