Max frame rate?

This is a forum for discussing the development and testing of alpha MS2/Extra code. Documentation
(Runs on MS2 and Microsquirt)

Moderators: jsmcortina, muythaibxr

gslender
Super MS/Extra'er
Posts: 1072
Joined: Fri Sep 16, 2011 5:29 am
Location: Brisbane, Australia
Contact:

Max frame rate?

Post by gslender »

G'day folks, just looking at the max frame rate of MS2 vs the 115,200 bps serial connection speed and where the delay is at...

So, looking at straight serial, there is a max transfer rate of 14,400 bytes/sec (at 115,200 bps).

With the payload at around 175 bytes, that would indicate a maximum frames of ~82 frames per second.

Now I'd assume the serial port needs to be sent an 'A' from the PC and then the MS2 needs to see this command (via an interupt) and then respond with writing out txtbuf to the serial port... so this has some lag in response.

What I'm puzzled about is why does the frame rate reach nothing like 80 frames/second? It seems hard to reach even 20 which is 4x less than the serial port bandwidth... so why have the port at 115,200 bps ???

Would it not be more reliable to have a serial connection at 57,600 and if not, why not?

G
Mazda MX5 + MS3 Pro
Reverant
Super MS/Extra'er
Posts: 1233
Joined: Sat Apr 15, 2006 12:39 am
Location: Athens, Greece

Re: Max frame rate?

Post by Reverant »

Maybe because you don't want to calll realtime() 80 times per second?
The man behind MS Labs
2005 Audi A3 2.0L TFSI DSG AWD - Extreme MS3
2002 Mazda Miata 1.8 6sp - Enhanced MS3 1.4.0, sequential injection, sequential ignition, big turbo, lots of boost
jsmcortina
Site Admin
Posts: 39586
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK
Contact:

Re: Max frame rate?

Post by jsmcortina »

See scope shot:
100_3113b.JPG
The "high" baud rate is useful for fetching and sending configuration data.

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

My Success story: http://www.msextra.com/forums/viewtopic ... 04&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
New users, please read the "Forum Help Page".
LT401Vette
Super MS/Extra'er
Posts: 12697
Joined: Sat Jul 16, 2005 8:07 am
Location: Moorseville, NC
Contact:

Re: Max frame rate?

Post by LT401Vette »

What I'm puzzled about is why does the frame rate reach nothing like 80 frames/second? It seems hard to reach even 20 which is 4x less than the serial port bandwidth... so why have the port at 115,200 bps ???
What firmware are you using?
What USB to serial chip?
What version TunerStudio?

With the current beta TunerStudio, MS2E 3.3b and an FTDI chip USB to serial on Windows 7
I am getting ~52 reads per second. So that isn't a surprising loss.

With the FTDI chip, check the Advanced settings, make sure you set latency to 1, by default it is 16. That has a pretty good performance effect.
Phil Tobin
EFI Analytics, helping to simplify EFI
Next Generation tuning software.
Supporting all MegaSquirt versions and firmwares.
http://www.TunerStudio.com
http://www.efiAnalytics.com/MegaLogViewer/
Support the firmware running your engine:
http://www.msextra.com/doc/donations.html
mariob
Experienced MS/Extra'er
Posts: 193
Joined: Wed Nov 11, 2009 11:35 am
Location: Berlin, Germany

Re: Max frame rate?

Post by mariob »

Hi,

the 3.1.1 Firmware with a payload of 169 bytes was able to supply around 67 frames/second which comes quite near to your 80 frames/s. This was achieved with an AVR logging to an SD-Card.

I have never seen more than >25 frames on a PC but it is nice to hear, that 52 are possible.

Best Regards, Mario
Peugeot 106 Sergio_Tacchini, 1124cm³, MS2/Extra pre3.3alpah15, E85
Citroen AX, 954cm³, MS2/Extra pre3.3alpha15, E85
Peugeot 106 Rallye, 1298cm³ ... waiting for ITBs and full sequential injection
gslender
Super MS/Extra'er
Posts: 1072
Joined: Fri Sep 16, 2011 5:29 am
Location: Brisbane, Australia
Contact:

Re: Max frame rate?

Post by gslender »

I wonder then if all those calls to "realtime()" are really effective and not just chewing up CPU time in the mainloop when perhaps a single realtime() at the end of the loop would achieve the same results and actually allow the main loop to run a little quicker?

My thinking is that the serial functions aren't actually occurring (for a MS2 using ~60 frame/second) any quicker than the total time it takes to step through the entire main loop - I mean it is only able to grab data from the outpc variables every 16 milliseconds and yet the main loop seems to execute in sub milliseconds... so it is unclear why all the realtime calls???

G
Mazda MX5 + MS3 Pro
gslender
Super MS/Extra'er
Posts: 1072
Joined: Fri Sep 16, 2011 5:29 am
Location: Brisbane, Australia
Contact:

Re: Max frame rate?

Post by gslender »

LT401Vette wrote: What firmware are you using?
What USB to serial chip?
What version TunerStudio?

With the current beta TunerStudio, MS2E 3.3b and an FTDI chip USB to serial on Windows 7
I am getting ~52 reads per second. So that isn't a surprising loss.

With the FTDI chip, check the Advanced settings, make sure you set latency to 1, by default it is 16. That has a pretty good performance effect.
I'm using the latest 3.3b firmware and unsure on the seria/usb chipset - I bought the cable that DIY are selling as being compatible (is it?). I'll check the latency settings and change it if not correct.

G
Mazda MX5 + MS3 Pro
robs
Master MS/Extra'er
Posts: 564
Joined: Sun Jan 17, 2010 4:26 pm
Location: Sydney, Australia

Re: Max frame rate?

Post by robs »

gslender wrote:I wonder then if all those calls to "realtime()" are really effective and not just chewing up CPU time in the mainloop when perhaps a single realtime() at the end of the loop would achieve the same results and actually allow the main loop to run a little quicker?

My thinking is that the serial functions aren't actually occurring (for a MS2 using ~60 frame/second) any quicker than the total time it takes to step through the entire main loop - I mean it is only able to grab data from the outpc variables every 16 milliseconds and yet the main loop seems to execute in sub milliseconds... so it is unclear why all the realtime calls???

G
Hmmm. Interesting. Last time I looked at realtime() (unless my memory's playing tricks on me again) it was sending bytes one at a time without using the Tx interrupt. So it would need to be called every 0.086ms (86µs) in order to keep the SCI unit busy at 115,200 bps, hence the scattering of calls to realtime() through the mainline. But looking now at recent versions, SCI0.TIE gets set, i.e. the transfer is being done by interrupt, so there is no longer any need for that part of realtime() to be called repeatedly. I haven't looked into what ck_log_clr(), chk_crc(), cp_page() at the top of realtime() do. Perhaps they still need to be called frequently. In that case, for a very minor saving, I suppose the lower part of realtime() could be pulled into a separate function and called, as you say, at just one place in the mainline.

I seem to remember that the avoidance of a SCI Tx interrupt was to avoid jitter in the more important things (sparks and squirts).

Have fun,

Rob.
jsmcortina
Site Admin
Posts: 39586
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK
Contact:

Re: Max frame rate?

Post by jsmcortina »

Robs is spot on with the historical reasoning there. But if you look at the scope trace, the big hit on frame rate is the 5ms when the firmware is waiting for a command. The processing and sending are quite close to max efficiency.

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

My Success story: http://www.msextra.com/forums/viewtopic ... 04&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
New users, please read the "Forum Help Page".
gslender
Super MS/Extra'er
Posts: 1072
Joined: Fri Sep 16, 2011 5:29 am
Location: Brisbane, Australia
Contact:

Re: Max frame rate?

Post by gslender »

jsmcortina wrote:Robs is spot on with the historical reasoning there. But if you look at the scope trace, the big hit on frame rate is the 5ms when the firmware is waiting for a command. The processing and sending are quite close to max efficiency.

James
Sure, but it would seem the numerous realtime() calls are chewing up CPU time with zero benefit yeah? I mean it is just slowing down the mainloop and not much else... or am I missing something?

g
Mazda MX5 + MS3 Pro
jsmcortina
Site Admin
Posts: 39586
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK
Contact:

Re: Max frame rate?

Post by jsmcortina »

Yes, but all of those calls are probably a smaller cost than a single 32bit divide.

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

My Success story: http://www.msextra.com/forums/viewtopic ... 04&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
New users, please read the "Forum Help Page".
gslender
Super MS/Extra'er
Posts: 1072
Joined: Fri Sep 16, 2011 5:29 am
Location: Brisbane, Australia
Contact:

Re: Max frame rate?

Post by gslender »

jsmcortina wrote:Yes, but all of those calls are probably a smaller cost than a single 32bit divide.

James
Mmmm, so your saying that many times of calling realtime() doesn't cost much mainly because rtsci isn't #1 and drops straight through to the bottom at skip_rt and the benefit is that when the serial port is ready, it is filled with the most recent/ready information from the ecu at that time?

Is that why all the "realtime()" calls are there ?? to ensure it is realtime... :lol:

G
Mazda MX5 + MS3 Pro
jsmcortina
Site Admin
Posts: 39586
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK
Contact:

Re: Max frame rate?

Post by jsmcortina »

gslender wrote:Is that why all the "realtime()" calls are there ?? to ensure it is realtime... :lol:
With the change to interrupt driven sending, we likely could remove a few. However, I'd expect the change in mainloop time to be barely measurable.

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

My Success story: http://www.msextra.com/forums/viewtopic ... 04&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
New users, please read the "Forum Help Page".
gslender
Super MS/Extra'er
Posts: 1072
Joined: Fri Sep 16, 2011 5:29 am
Location: Brisbane, Australia
Contact:

Re: Max frame rate?

Post by gslender »

jsmcortina wrote:With the change to interrupt driven sending, we likely could remove a few. However, I'd expect the change in mainloop time to be barely measurable.
Removed all but one (1) realtime() call out of the mainloop. Went for a drive and found the logging behaviour to be as consistent as before. Probably need to do some more before/after testing but given how quick the mainloop cycles, I doubt having just one realtime() will impact the overall "realtime-ness or freshness" of the data being sent to the serial buffer.

Obviously I also need to confirm what the change has produced in terms of benefits, but from a clean code perspective, it would have benefits by keeping the number of bytes used down and reduce clutter etc, I know it is only small amounts, but every byte can impact and needless calls that don't add value surely should be removed - certainly didn't have an ill effects and can't see how it could either.

There is also some calls in the realtime() that I need to better understand - like cp_page() that only really runs if flagbyte6 & FLAGBYTE6_PAGECOPY is set, yet nowhere I could find in the code that actually sets that bit to be on, so from what I can quickly find, nothing would result in that code running, yet it takes up ram space???

G
Mazda MX5 + MS3 Pro
gslender
Super MS/Extra'er
Posts: 1072
Joined: Fri Sep 16, 2011 5:29 am
Location: Brisbane, Australia
Contact:

Re: Max frame rate?

Post by gslender »

gslender wrote: There is also some calls in the realtime() that I need to better understand - like cp_page() that only really runs if flagbyte6 & FLAGBYTE6_PAGECOPY is set, yet nowhere I could find in the code that actually sets that bit to be on, so from what I can quickly find, nothing would result in that code running, yet it takes up ram space???
Well, removed (commented out) the entire cp_page() function and no ill effect (at least with my limited testing). I guess it was a redundant bit of code?

G
Mazda MX5 + MS3 Pro
racingmini_mtl
Super MS/Extra'er
Posts: 9128
Joined: Sun May 02, 2004 6:51 am
Location: Quebec, Canada
Contact:

Re: Max frame rate?

Post by racingmini_mtl »

Look in isr_sci.s and you'll see that it should be ok to remove it.

Jean
jbperf.com Main site . . . . . . . . . . . . . . . . . . . . . . jbperf.com Forum
Image
gslender
Super MS/Extra'er
Posts: 1072
Joined: Fri Sep 16, 2011 5:29 am
Location: Brisbane, Australia
Contact:

Re: Max frame rate?

Post by gslender »

racingmini_mtl wrote:Look in isr_sci.s and you'll see that it should be ok to remove it.

Jean
Sweet. Well that's a few more bytes of space and a small improvement in the main loop time.
Mazda MX5 + MS3 Pro
piledriver
Super MS/Extra'er
Posts: 1679
Joined: Tue Oct 27, 2009 6:24 am
Location: Van Alstyne, Texas

Re: Max frame rate?

Post by piledriver »

FWIW I'm getting 49-52 fps with my old zombie killer Itronix Gobook3/PentiumM @1.8 Ghz, 16550a (real) serial port under Linux 2.6.38.
I get ~10-11 fps with a Class1 BT connection to an HTC Hero running Cyanogenmod 7 (Honeycomb)/Shadowlogger , will check with my Microconnectors dual USB setup tomorrow and also using XP, and BT>TS under Linux and XP.
Always doing things the hard way, MS2 sequential w/ v1.01 mainboard, LS2 coils. 80 mile/day commuter status.
gslender
Super MS/Extra'er
Posts: 1072
Joined: Fri Sep 16, 2011 5:29 am
Location: Brisbane, Australia
Contact:

Re: Max frame rate?

Post by gslender »

Where do you measure frame rate in TS.... I've drawn a blank?

G
Mazda MX5 + MS3 Pro
racingmini_mtl
Super MS/Extra'er
Posts: 9128
Joined: Sun May 02, 2004 6:51 am
Location: Quebec, Canada
Contact:

Re: Max frame rate?

Post by racingmini_mtl »

I don't know if there is a better way now but I count the number of frames in the same second in a log file. Make sure you set the communications to the fastest data rate.

Jean
jbperf.com Main site . . . . . . . . . . . . . . . . . . . . . . jbperf.com Forum
Image
Post Reply