CAN Bus display, speed questions

This forum is for the discussion of other projects on Megasquirt/Microsquirt hardware that don't fit into any of the other forums

Moderators: jsmcortina, muythaibxr

CAN Bus display, speed questions

Postby Nitroking » Tue Dec 06, 2016 3:55 am

Hello,

2.5 year ago I made an OLED display using an arduino Nano which was talking to the MS using the newserial protocol with CRC32 etc. Well I thought it's high time I changed it to CAN Bus in order to surpass some Serial problems and cope with the new protocols (and to learn of course). So keeping the same hardware and using a CAN BUS shield, I am able to talk to MS3 and receive packets, display them to my little OLED display.

The serial display was very very fast with great refresh rate at 115200bps.. So with CAN Bus I was expecting the speed to be the same or more. But the opposite happened. Let me explain the situation:
I use Real time Data Broadcasting because I want some more info like PWM Idle than the Dash Broadcast can offer. I only have enabled the groups I am interested in which are IDs 1520,1521,1522,1524,1526 and 1551 total of 6 groups. Initially I used 50Hz to all of them and noticed that some variables (like MAP, RPM) where refreshing slowly and surely not corresponding to actual data. Some may had taken up to 3 seconds to update. So I thought, ok I will prioritize my data and change the refresh rates from 1Hz to 50Hz depending on the importance.

Things got a bit better but still I don't like it. So here is my understanding of what really happens:
Lets assume we need to display a group which updates 5 times/sec (5HZ). MS3 populates the BUS with loads of messages as I have set it up to do (6 groups). If my code loop is running and one message of the 5hz group arrives, it probably gets ignored as the code is busy. What if the next time it comes gets ignored again? And again later on? The refresh rate maybe once per 2 or 5 seconds, stuff I have seen happening.

So what happens when we prioritize the refresh rates on TS? We give more chances to the higher refresh rate group to show up on our display as there are more messages of it in the bus, right? At the same time though, we give even less chances to the lower refresh rate variables to show up.

I am probably doing something wrong and that's why I opened this topic, as I need your help to tell me if there is some 'best practice' of manipulating CAN Bus data.

The math:
My looptime is around 28ms, steady. 500000bps for the CANBUS speed means 500000/29bits=17241 messages are being transmitted by MS3 in the bus during one second (1000ms). If my code is busy for 28ms then 482748/1000=482 messages arrive during a busy loop. So my code ignores 482-1=481 messages. It may be the case that the lower refresh rate group message is inside those 481 messages so it shows up late in the display.

Sorry if I am not expressing the problem correctly but I think I gave you a basic idea. How do you all who have made displays cope with that problem? Maybe using Teensy's with 72MHZ? Is there another way to prioritize messages? Also, what happens to the messages that don't get read? Do they timeout or waiting to be read infinitely? Maybe this is the case, the code is not reading fast enough and the CAN BUS gets flooded with "old" data.

Thank you!!
Miata NBFL 1.6 (EU), GT2560R, MS2Extra, Zeitronix.
Fiesta 1.25 Zetec-SE, N/A mods, MS3, AEM.
Nitroking
Helpful MS/Extra'er
 
Posts: 127
Joined: Fri Feb 28, 2014 6:03 am

Re: CAN Bus display, speed questions

Postby Alfagta » Tue Dec 06, 2016 5:07 am

Hello,

which shield do you use and do you use a interrupt routine to fetch the can bus data from the shild?
If it's ashiled with the MCP2515 take care this device only have a internal buffer for 3 messages.

And why dou you have a looptime off about 28ms thats really much.
I have also some can bus devices with much can bus load. My average looptime is arround 100µS.

Your Math is not really correct because one 29 bit message has more than 29 bits. You have also the playload and a few other bits to transfer via the bus.

Best Regards
Alfa 156 GTA
Alfa 75 Race Car MS III -- alway latest FW
Alfa 164 V6 Turbo
Alfa 155 2,5TD RIP
Test MS II --always latest FW
Tunerstudio V2.6.11 Registered
MegaLog Viewer V3.4.04 Registered
Alfagta
Experienced MS/Extra'er
 
Posts: 208
Joined: Wed Aug 21, 2013 2:54 am

Re: CAN Bus display, speed questions

Postby Nitroking » Tue Dec 06, 2016 5:38 am

The can bus shield is this one CAN BUS shield.. It uses MCP2515, is there any better IC to use? Or shield maybe?

I agree the loop time is huge, that's why I mentioned it. I believe this is because of the data handling and the I2C for the OLED display which uses strings to write to the display.

Initially I used interrupts for the data receiving but I saw that this caused even more delays so now I just read the messages of the CAN BUS.. Also, how many bits is an actual 29-bit style MS message?

Thank you
Miata NBFL 1.6 (EU), GT2560R, MS2Extra, Zeitronix.
Fiesta 1.25 Zetec-SE, N/A mods, MS3, AEM.
Nitroking
Helpful MS/Extra'er
 
Posts: 127
Joined: Fri Feb 28, 2014 6:03 am

Re: CAN Bus display, speed questions

Postby jsmcortina » Tue Dec 06, 2016 5:56 am

Nitroking wrote:Also, how many bits is an actual 29-bit style MS message?

CAN is robust but inefficient for data transfer.
That's 29bits of header, plus lots of built-in data validation plus DLC and 8 bytes x 8 bits.

I don't have the data to hand to check, but I seem to recall it being around 118 bits of packet for 64 bits of data?

James
I can supply, repair or upgrade Megasquirts in UK. http://www.jamesmurrayengineering.co.uk

My Success story: viewtopic.php?f=104&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
jsmcortina
Site Admin
 
Posts: 33987
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK

Re: CAN Bus display, speed questions

Postby Nitroking » Tue Dec 06, 2016 6:26 am

James that's even better for me then as my code seems to be slow. So if we recalc assuming it is 118bits then 500000/118=4237 messages per second, still is very fast! If we equally divide (like setting the refresh rate to an equal number) that by 6 (the number of groups I would like to fetch) then 4237/6=706msg/sec.. If you compare it to the 115200 serial which was around 60-70 messages/second minus the time needed to request an outpc response then it is ultra fast.. So my point still remains, it should have been faster than the serial protocol..

Regarding the 28ms looptime for my code, I discovered that it takes around 10ms to print one line for the display which is crap.. So I have 8ms to clear the display+20ms to write 2 lines (16x2) so I guess I have to change the display later on..

However, even if the loop time was 50ms it should be totally great for human eyes.. But the problems seems not to be the loop time but the frequency that each group is getting received by my board. Alfagta can you elaborate a bit more about the 3 message buffer? Does your code print anything to a display? What happens to the rest of the messages that don't fit the buffer? is there any best practice to read CAN data?

Thank you again.
Miata NBFL 1.6 (EU), GT2560R, MS2Extra, Zeitronix.
Fiesta 1.25 Zetec-SE, N/A mods, MS3, AEM.
Nitroking
Helpful MS/Extra'er
 
Posts: 127
Joined: Fri Feb 28, 2014 6:03 am

Re: CAN Bus display, speed questions

Postby Alfagta » Tue Dec 06, 2016 6:39 am

Hello,

do you use a OLED grafic display or only some old lcd with oled technology.
I think you use arduino to programm this stuff and also use the arduino librarys.
You must look into the librarys some of them have big delays in it. So they are blocking...

What i mean after 3 can messages in the buffer there are no new data acdcepted.
You must read the buffer so the mcp 2515 can receive a new message.
With that transfer rate you must use interrupts.

A better way would be to go with am atmega32M1 it is also a 32 pin version nearly the same as the atmega328P.
This device has 6 message buffers and you have the messages in the chip already. Other than with the mcp2515 you must read
the messages via spi. (How fast is you spi now?)

You can also use a teensy board that would be the better way for an arduino user.

I have a can bus display designed witch also use a 16x2 lcd display and i write all the data to the display.
It's pretty fast.

Best Regards
Alfa 156 GTA
Alfa 75 Race Car MS III -- alway latest FW
Alfa 164 V6 Turbo
Alfa 155 2,5TD RIP
Test MS II --always latest FW
Tunerstudio V2.6.11 Registered
MegaLog Viewer V3.4.04 Registered
Alfagta
Experienced MS/Extra'er
 
Posts: 208
Joined: Wed Aug 21, 2013 2:54 am

Re: CAN Bus display, speed questions

Postby Nitroking » Tue Dec 06, 2016 6:49 am

Libraries suck.. If I use a specific library it needs 15msec instead of 10 to write a line. The display is lcd style 16x2 with oled technology and excelent refresh rate and under sunlight visibility (thats why I chose it).

The code for sending the chars to the display is by using the raw Arduino wire library. Still, it takes that 10ms time for 16 chars. Don't know why, maybe I will try an old style LCD with another I2C on it.

void sendData(unsigned char data)
{
Wire.beginTransmission(OLED_Address); // **** Start I2C
Wire.write(OLED_Data_Mode); // **** Set OLED Data mode
Wire.write(data);
Wire.endTransmission(); // **** End I2C
}

I am not stuck at Arduino, I have of course no problem of changing platform and I guess Teensy 3.2 or 3.1 is a better place to start. Do you have any idea how many messages can it handle?
Miata NBFL 1.6 (EU), GT2560R, MS2Extra, Zeitronix.
Fiesta 1.25 Zetec-SE, N/A mods, MS3, AEM.
Nitroking
Helpful MS/Extra'er
 
Posts: 127
Joined: Fri Feb 28, 2014 6:03 am

Re: CAN Bus display, speed questions

Postby Raymond_B » Tue Dec 06, 2016 9:32 am

There's several threads on Teensy CAN displays here. When I first tried my hand at it I had a small LCD screen that I bought with the Teensy, the LCD could not keep up with the faster modes of broadcasting that I could set in Tuner Studio. I went with a Nextion and had the serial connection speed set to 115200 with no issues. Teensy now has a 3.5 and a 3.6, the latter has two CAN buses which opens up some interesting possibilities.
1995 Ford Lightning. Dart based 427 Windsor, Novi 2000, full sequential, E-85, etc. MS3/3X
Friends don't let friends share tunes...
http://www.buildpics.org/
Raymond_B
Master MS/Extra'er
 
Posts: 583
Joined: Thu Mar 06, 2014 2:17 pm
Location: Texas

Re: CAN Bus display, speed questions

Postby Nitroking » Tue Dec 06, 2016 12:02 pm

Thanks raymond, seen your project, fantastic job! I have also ordered a tft display to check with..

Loop time is now 8ms, I found a delay(10) in 2 spots used for the old serial communcation.. :lol:

Will try tomorrow and update..

Best regards
Nick
Miata NBFL 1.6 (EU), GT2560R, MS2Extra, Zeitronix.
Fiesta 1.25 Zetec-SE, N/A mods, MS3, AEM.
Nitroking
Helpful MS/Extra'er
 
Posts: 127
Joined: Fri Feb 28, 2014 6:03 am

Re: CAN Bus display, speed questions

Postby Alfagta » Tue Dec 06, 2016 12:40 pm

An the best would also be to go with an lcd display with direct connection.
Not a connection with the i2c expander. Thats also faster.
Alfa 156 GTA
Alfa 75 Race Car MS III -- alway latest FW
Alfa 164 V6 Turbo
Alfa 155 2,5TD RIP
Test MS II --always latest FW
Tunerstudio V2.6.11 Registered
MegaLog Viewer V3.4.04 Registered
Alfagta
Experienced MS/Extra'er
 
Posts: 208
Joined: Wed Aug 21, 2013 2:54 am

Re: CAN Bus display, speed questions

Postby jacky4566 » Tue Dec 06, 2016 12:59 pm

Upgrade to a Teensy. So much extra horsepower!

FYI the teensy is not plug and play CAN BUS. You still need a transceiver chip. SN65HVD230D, TJA1050T or similar.
jacky4566
Helpful MS/Extra'er
 
Posts: 105
Joined: Mon Aug 31, 2015 10:05 am

Re: CAN Bus display, speed questions

Postby Nitroking » Tue Dec 06, 2016 2:02 pm

Alfagta wrote:An the best would also be to go with an lcd display with direct connection.
Not a connection with the i2c expander. Thats also faster.


Performed several tests with the I2C now.. I am using Wire library direct calls. What is interesting is that one string of 16 chars (1st line) takes around 1msec to get transmitted, then 300us for the newline address send and then when I am performing a transmission for the second string (2nd line) the whole loop time jumps up to 7.3msec meaning 5.5msec for the second line! Makes no sense at all.. It is the exact same code being used just with a different argument (line1 or line2).. What the heck..?
Miata NBFL 1.6 (EU), GT2560R, MS2Extra, Zeitronix.
Fiesta 1.25 Zetec-SE, N/A mods, MS3, AEM.
Nitroking
Helpful MS/Extra'er
 
Posts: 127
Joined: Fri Feb 28, 2014 6:03 am

Re: CAN Bus display, speed questions

Postby jsmcortina » Tue Dec 06, 2016 2:17 pm

Sounds like you are being killed by libraries. That's why Megasquirt code is "bare metal" - no superfluous stuff getting in the way, which allows us to make the most of the hardware we have.

Perhaps consider getting a regular microcontroller that has CAN and I2C support.

James
I can supply, repair or upgrade Megasquirts in UK. http://www.jamesmurrayengineering.co.uk

My Success story: viewtopic.php?f=104&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
jsmcortina
Site Admin
 
Posts: 33987
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK

Re: CAN Bus display, speed questions

Postby Raymond_B » Tue Dec 06, 2016 4:29 pm

jsmcortina wrote:Sounds like you are being killed by libraries. That's why Megasquirt code is "bare metal" - no superfluous stuff getting in the way, which allows us to make the most of the hardware we have.

Perhaps consider getting a regular microcontroller that has CAN and I2C support.

James


James, is there one you would recommend?
1995 Ford Lightning. Dart based 427 Windsor, Novi 2000, full sequential, E-85, etc. MS3/3X
Friends don't let friends share tunes...
http://www.buildpics.org/
Raymond_B
Master MS/Extra'er
 
Posts: 583
Joined: Thu Mar 06, 2014 2:17 pm
Location: Texas

Re: CAN Bus display, speed questions

Postby jsmcortina » Tue Dec 06, 2016 4:39 pm

Jean and I have used the MC9S08DZ60 and similar. However, many other parts from different manufacturers exist.

James
I can supply, repair or upgrade Megasquirts in UK. http://www.jamesmurrayengineering.co.uk

My Success story: viewtopic.php?f=104&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
jsmcortina
Site Admin
 
Posts: 33987
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK

Re: CAN Bus display, speed questions

Postby Alfagta » Tue Dec 06, 2016 10:40 pm

Also the Atmega32M1 and AT90Can32 is a possible option.
For most people its harder to work with the freescale parts than with atmel parts.


As i told before i'm using atmel can devices and have no performance issues.
Best Regards
Alfa 156 GTA
Alfa 75 Race Car MS III -- alway latest FW
Alfa 164 V6 Turbo
Alfa 155 2,5TD RIP
Test MS II --always latest FW
Tunerstudio V2.6.11 Registered
MegaLog Viewer V3.4.04 Registered
Alfagta
Experienced MS/Extra'er
 
Posts: 208
Joined: Wed Aug 21, 2013 2:54 am

Re: CAN Bus display, speed questions

Postby Nitroking » Wed Dec 07, 2016 3:39 am

jsmcortina wrote:Sounds like you are being killed by libraries. That's why Megasquirt code is "bare metal" - no superfluous stuff getting in the way, which allows us to make the most of the hardware we have.

Perhaps consider getting a regular microcontroller that has CAN and I2C support.

James



That is very true.. So I dug into the libraries codes and changed a few things. Removed any silly delays being used. What made the most difference was the overclocking of the Wire library from 100 to 400KHZ.. Now the code runs at 4ms and the refresh rate is super fast, almost annoying to the human eye so I will leave it there.

The problem was that for some reason, the wire library even if it is capable of running at 400KHZ is set at 100KHZ, I guess for slower displays to be able to cope with the speed.

Thank you all for your great responses, your guidance led me to the solution. I will come back if I have any other questions, probably when I will try to send data like AFR to MS3.
Miata NBFL 1.6 (EU), GT2560R, MS2Extra, Zeitronix.
Fiesta 1.25 Zetec-SE, N/A mods, MS3, AEM.
Nitroking
Helpful MS/Extra'er
 
Posts: 127
Joined: Fri Feb 28, 2014 6:03 am

Re: CAN Bus display, speed questions

Postby jsmcortina » Wed Dec 07, 2016 4:49 am

Nitroking - glad to hear you got it working.

Alfagta wrote:Also the Atmega32M1 and AT90Can32 is a possible option.
For most people its harder to work with the freescale parts than with atmel parts.

We are getting off-topic here, but I'm interested to know why? I've tended to work with Freescale parts, but have no vested interest in them.

James
I can supply, repair or upgrade Megasquirts in UK. http://www.jamesmurrayengineering.co.uk

My Success story: viewtopic.php?f=104&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
jsmcortina
Site Admin
 
Posts: 33987
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK

Re: CAN Bus display, speed questions

Postby Alfagta » Wed Dec 07, 2016 5:17 am

Hy James,

yes of course a liitle bit off topic but who cares.

In my opinion the reason is the mass of informations you can find for the atmel parts.
A lots of librarys and forums... thats good for the hobbyist (they are mostly no hard core programmer).
Programming with the ISP or avrdude is dead easy...
And yet also arduino is a big reason for most people. (i don't use it because performance is not good, to much overhead)

I have tryied several time to play with freescale parts (they have a lot of relly cool parts!! ) but i gave up every time.
I have had not that much time to get deep enough into it.
I have tried to play with code warrior ide.

Now i think before i get into the the S08 or S12 series i prefer to usw ARM core devices.
They are less expensiv and more powerfull.
For first time users for sure its very hard to work with ARM architecture but i will go futher some day.
I have a stm32 board and play from time to time with it.

That's only my opinion but some other people (hobbyists) thinking the same.

Best regards
Alfa 156 GTA
Alfa 75 Race Car MS III -- alway latest FW
Alfa 164 V6 Turbo
Alfa 155 2,5TD RIP
Test MS II --always latest FW
Tunerstudio V2.6.11 Registered
MegaLog Viewer V3.4.04 Registered
Alfagta
Experienced MS/Extra'er
 
Posts: 208
Joined: Wed Aug 21, 2013 2:54 am

Re: CAN Bus display, speed questions

Postby Nitroking » Wed Dec 07, 2016 6:25 am

That's true, most users use arduino or arduino-style boards like teensy, attiny85 ie because there are HUGE info on them on the net. Plus the Arduino IDE is user friendly (kind of, it has some stupid bugs).

But I totally agree, once you get serious about electronics, you have to deal with some serious processors. But it is difficult to learn to code in a different platform with another IDE even for a senior software engineer like me not because of the difficulties of coding but the lack of knowledge about processors, ram etc..
Miata NBFL 1.6 (EU), GT2560R, MS2Extra, Zeitronix.
Fiesta 1.25 Zetec-SE, N/A mods, MS3, AEM.
Nitroking
Helpful MS/Extra'er
 
Posts: 127
Joined: Fri Feb 28, 2014 6:03 am

Next

Return to Other Development

Who is online

Users browsing this forum: No registered users and 1 guest