Increment bits in CAN message each time a message is sent

  • Software
  • Increment bits in CAN message each time a message is sent
Cody Pursifull

Posted on 08.04.2024 21:23

Hello,


I am working on a project that requires an 8 bit counter at the end of the CAN message. This counter must increase by one each time a message is sent. The goal is to be able to transmit the message at 200hz, so the counter would need to increase by 1 every 5ms. The counter needs to go from 0 to 255.


Any help would be greatly appreciated!

Pika Kreča Šmid

Posted on 10.04.2024 14:56

Dear Cody,


thank you for reaching out to us.

I have reached out to our developers for their input and help when it comes to this ticket, so I will keep you updated.

I do believe these two links might be useful to you; the first is a forum post that dealt with channel reset (although the channel was a counter, not can messages), the second is our solution for generating CAN bus message transmit indicators.


In CAN module, if you press the advanced button, you will be able to enable message count channels, meaning, you should be able to read the number of the correct messages on the bus. Please note, that you will only be able to work with Rx channels, no messages will correct messages will be found on the Rx channels.



In your case, I believe you would then need 3 CAN ports, and therefore 3 can channels. The first can port will be used to transmit messages, that will be read on the second port. From this second port, we will read the number of correct messages and make formulas for the counter.

The third port will then be used to further transmit the messages on the second port.


I am going to attach a datafile, where we used one port to transmit data, and the second port to read data. We then created a counter, that resets once the message count is 255, or, once the counter (that is one number higher than the message count) is 256.


Please let me know if this helps you in any way.


Best regards,

Pika


Attached files:
Cody Pursifull

Posted on 10.04.2024 15:57

I believe I am close to having a working setup. I have attatched my current setup to better portray my goal. I am using a square wave to create a counter and modulus to go from 0 to 255. The issue I am having is that when I monitor the messages on the CAN bus, I am seeing the same message sent multiple times when the message should be different each time it is sent due to my counter value increasing by 1. I have had success with this setup at 10Hz, but have not had success at 200Hz. Please let me know if you think it would be possible to achieve my goal this way.


Thank you,

Cody


Attached files:
Pika Kreča Šmid

Posted on 12.04.2024 13:27

Dear Cody,


thank you for the setup file.

I went through it, and asked one of our developers for help finding the most optimal solution for your application. I am attaching the setup file and data file of our solution, so that you can go over it as well.


We firstly used CAN1 port to invert the signals, so that we could observe what was going on. So, CAN1 now has a Message channel that it transmits. The signal setup is as follows:


AngleFormula is here a mathematical formula that simulates the counter:



We then made a formula that counts messages. Please do note that we changed the time axis of this channel to ensure that it only counts when the value of the Encoder Shaft Angle changes/increases:



As the last step, we made a formula that reset the channels as soon as we had more than 255 messages:



This last formula was then fed to the Control message (Tx) from port CAN1:



As per the developer, this is the most optimal, as well as the easiest, way of achieving what you are trying to do.

Please let me know if you have any other questions.


Best regards,

Pika


Attached files:
Cody Pursifull

Posted on 12.04.2024 15:13

Hello Pika,


I really appreciate all of the help, but I believe there is a slight disconnect in the understanding of what I am trying to accomplish. I beleive the name "message counter" has caused some confusion.


I am not concerned with the messages being received, or the rate at which the messages are being received. My only goal is to transmit my 5D0 message every 5ms and have bits 56 to 64 increase by a value of 1 every 5ms also. These bits are used as a "heartbeat" between the Dewesoft and the ECU I am working with. The ECU is using this counter to ensure that the messages it is receiving are up to date. If the same message is received multiple times in a row, the ECU control will be unsuccessful.


Hopefully this will clarify my goals. I have attached an small figure below to try and make my idea more clear.



Thank you,

Cody

Pika Kreča Šmid

Posted on 17.04.2024 10:59

Dear Cody,


I apologise for the error- it does look like I misunderstood what you are trying to achieve.

I will check your inquiry further with our expert in this field, and will let you know as soon as I have an answer prepared for you- due to our measurement conference currently being in full swing, and most of our colleagues taking part in the conference, my response will be delayed until the team that deals with such applications is available. I do apologise for this delay upfront.


Thank you for your patience regarding this ticket and best regards,

Pika

Pika Kreča Šmid

Posted on 25.04.2024 15:49

Dear Cody,


I apologise you've had to wait so long for a response. Our developer has created yet another setup file- I will attach it to this reply. Please check if this is relevant for you- the developer did point out that in the previous file we've sent, we were in fact increasing the bit value by 1, however, this increase did not happen exactly every 5ms.

You will notice that we introduced Transmit delay We usually receive samples for the first period after one cycle of acquisition update rate (that is approximately 50Hz for our devices, but can be longer under certain conditions). With CAN transmit delay we shift this for one or more cycles- when transmit is activated, there actually are samples to transmit, thus making the output signal more accurate. For a visual presentation, I would recommend you check out How to measure with CAN channels? section of our CAN Bus and CAN FD Data Acquisition and Analysis.

The developer has also mentioned that this lack of transmit delay could be the reason why your setup works as you expect it to work at 10Hz, but not at 200Hz.


Best regards,

Pika



Attached files:
Cody Pursifull

Posted on 25.04.2024 17:42

Hello Pika,


My team has now moved on to a different solution for this project, but I am still curious to find a solution to this problem.


Using the most recent setup file you have provided, I am still seeing the same issue as before. I have attached an image below of the message output I am seeing. I am monitoring the CAN message output with an IXXAT USB-to-CAN. The messages do not seem to be transmitting at the proper rate and the message value still does not seem to be increasing by 1 each time the message is sent.


Please do not feel rushed to find a solution to this problem as it is just for my own curiosity at this point.


Thank you,

Cody


Pika Kreča Šmid

Posted on 30.04.2024 13:03

Dear Cody,


the last time I went over this ticket with the developer, he did mention that keeping the frequency constant, meaning, ensuring that the messages are always transmitted at the time mark of 5ms after the previous one, will be difficult

As you can see, the bit value does change each time a new message is changed:


You can also see how the bit value in the Value column keeps changing:


From the Frequency column, however, you can see that the approximate frequency of the periodically transmitted channels is not constant- it oscillates around 200 Hz or 5 ms- the last time we went through the datafile with the developer, the MsgCountRx channel frequency was 200Hz, but changing the device might have had something to do with it.


If you are interested in finding a working solution, I would suggest you try checking if you can lower the frequency oscillation. You will need to utilize the Transmit delay, but this delay varies depending on which devices are connected.


Best regards,

Pika

Login to reply to this topic. If you don't have account yet, you can signup for free account .