Supported platforms: CODESYS 3.5 SAFETY, CODESYS 3.5

 

Sending Time Triggered CAN message 

Required:

 

 

Limitations:

  • Maximum number of the send messages is 10

  • Accuracy of the time is +-2 ms

  • Minimum time interval for sending is 1 ms, but it is recommended to use intervals > 10 ms.

  • Used CAN channel must be initialized before initializing the time triggered messages (done automatically with MultiTool Creator code template)

  • Function block instance must be called at least every 100 ms, otherwise message sending is stopped

 

 

Example code

The following example describes a time triggered CAN message (COB-ID 100h) that is triggered with 10 ms interval.

CAN bus init is not required if MultiTool Creator code template is used.

 

Definitions:

 

canChannel:EPEC_CANL2.Channel; (*not required with MT code template*)

timeTrgSending:EPEC_HWD.CanApiTimeTriggeredMsg;

 

Init:

 

(*If using MultiTool, CAN channel init is already included in code template*)

canChannel.InitCAN(0,250,0);                    (* Init channel 0 for 250 kbit/s*)

 

timeTrgSending.i_Enable := FALSE;

timeTrgSending.i_Dlc := 8;

timeTrgSending.InitCobId(0,16#100,T#10MS);      (* Init message, COB-ID 100h, 10ms interval *)

 

 

 

Code:

 

(*Update message data*)

timeTrgSending.i_Data[0] : = 1;

timeTrgSending.i_Data[1] : = 2;

timeTrgSending.i_Data[2] : = 3;

timeTrgSending.i_Data[3] : = 4;

timeTrgSending.i_Data[4] : = 5;

timeTrgSending.i_Data[5] : = 6;

timeTrgSending.i_Data[6] : = 7;

timeTrgSending.i_Data[7] : = 8;

(*Update data for message handler*)

timeTrgSending.UpdateData();

(*Call handler periodically*)

timeTrgSending(i_Enable := TRUE);    

 

 

See also

 

 

Source file topic100365.htm

Last updated 13-Jun-2024