Transmitting CAN message periodically MDBT MPC5744P

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Transmitting CAN message periodically MDBT MPC5744P

2,045 Views
aungkm
Contributor III

Hi constantinrazvan.chivu,

I am trying to send multiple CAN messages with different period. I am using the counter limited block and compare to constant block to periodically trigger the CAN send message block.

pastedImage_1.png

I could periodically transmit multiple messages with the same period by using this method but I am having trouble transmitting multiple messages with different period. I could transmit multiple messages if I didn't use the above mentioned two blocks but then the messages were not being sent periodically. Is there another way to transmit the message periodically? Moreover, I could not use Tx complete block with the above-mentioned method. I have attached my model which was created by 2018b.

Thanks and best regards,

Joe

3 Replies

1,786 Views
constantinrazva
NXP Employee
NXP Employee

Hello aungkm@outlook.com‌,

Regarding the CAN ISR usage, you can use the TX Complete event for every example in which you are sending something over CAN. Something that you must be aware is that the ISR block should be executed after the CAN Config block. You can view this either in the executed code, either by editing the priority in the model - you can do this by right clicking on a block -> Properties -> Priority. Note that lower number = HIGHer priority. Another thing you could do is hit CTRL + D while in the model, and watch the order that Simulink gives the blocks (e.g.: Config block has 0:12, and CAN ISR block has 0:18 - so in this example, the config block would be the 12th block for which code will be generated, while ISR will be the 18th).

pastedImage_1.png

I have attached a working model here.

Note: a TX complete event will be triggered after each CAN Send, so the toggle of the red LED in the example attached is actually made up of more toggles, as we execute 3 consecutive CAN writes.
(initial LED state - off)

1st stage - 3 frames sent

CAN Send - LED toggle to ON

CAN Send - LED toggle to off

CAN Send - LED toggle to ON

2nd stage - other 3 frames sent

CAN Send - LED toggle to off

CAN Send - LED toggle to ON

CAN Send - LED toggle to off

[etc]

Kind regards,

Razvan.

1,787 Views
aungkm
Contributor III

Hi constantinrazvan.chivu,

My model is working now. T‌hank you for your help and explanation. 

Best Regards,

Joe

0 Kudos
Reply

1,787 Views
constantinrazva
NXP Employee
NXP Employee

Hello aungkm@outlook.com‌,

So for you to periodically transmit messages (or do anything else for that manner), you have 2 choices:

  • software scheduling (via software timer)
  • hardware scheduling (via hardware timer)

One of the many approaches available for software scheduling is what you did here - enabling a subsystem via a signal (limited counter in your case). The software approach I'd recommend is described here, in a nice article wrote by gramirezv.

If you want to go for the hardware triggering, you can do this by using a PIT (periodic interrupt timer). You can find it in our toolbox, under Core and system blocks -> PIT Timer.

pastedImage_1.png

You can set the period here, and trigger a subsystem with this block.

pastedImage_3.png

Note that inside the triggered subsystem you'll have to use a trigger block, setting it's type to function-call.

pastedImage_5.png

Kind regards,

Razvan.