Little bit more work on decoding and testing the Pectel datastream today.
I've run some performance analysis on the serial datastream - it's fast enough to return, on average, around 62 sensor datapoints a second. Not a massive amount, but better than I thought we would get, based on the baud rate.
On average, each sensor requires 25-27ms to query and return a value. But that assumes all sensors only take a single byte to query and a return a single byte result (this a value in a range from 0-255), unfortunately injector duration and RPM, at the very least, require two writes and two reads (with a result in the range 0-65535). For those sensors, time increases to 43ms.
There doesn't appear to be any statistically significant difference in the time taken to query each type of sensor.
I put together a simple test routine, outside of my digital dashboard code, to run the numbers and this is what I see:
Test run 1 - all sensors, then performance test against TPS (a single byte sensor value)
Code:
$ ./SensorReader
[2018-01-27 12:35:07,835] [ INFO] ( Cosworth.py: 126) | MainProcess | Starting Cosworth ECU sensor module
L8 Pectel None
[2018-01-27 12:35:07,835] [ INFO] ( Cosworth.py: 179) | MainProcess | Bringing up serial interface
Serial<id=0x7f736d41b860, open=True>(port='/dev/ttyUSB0', baudrate=1952, bytesize=8, parity='N', stopbits=1, timeout=0.1, xonxoff=0, rtscts=0, dsrdtr=0)
[2018-01-27 12:35:07,837] [ INFO] ( Cosworth.py: 289) | MainProcess | Serial interface up
##########################################
Test 1. We are going to attempt to read every sensor in turn...
Sensor: [ AMAL] Value: [185.000] Sample Speed: [17.922ms] Description: [Duty cycle of boost control valve]
Sensor: [IGNADV] Value: [0.000] Sample Speed: [27.345ms] Description: [Ignition timing in degrees before top dead centre]
Sensor: [ TPS] Value: [-0.116] Sample Speed: [27.223ms] Description: [Open angle of throttle plate in degrees ]
Sensor: [ MAP] Value: [390.348] Sample Speed: [27.328ms] Description: [Inlet manifold pressure in milibars]
Sensor: [ RPM] Value: [7326.000] Sample Speed: [43.284ms] Description: [Engine speed]
Sensor: [ BAT] Value: [12.183] Sample Speed: [27.351ms] Description: [Battery or supply circuit voltage]
Sensor: [ IAT] Value: [78.000] Sample Speed: [27.354ms] Description: [Inlet manifold air temperature in degrees Celsius]
Sensor: [ ECT] Value: [80.000] Sample Speed: [27.433ms] Description: [Engine coolant temperature in degrees Celsius]
Sensor: [INJDUR] Value: [16.000] Sample Speed: [43.160ms] Description: [Injector pulse width duration in milliseconds]
Check the above values!
Test 2. Now testing how fast we can read all sensors
All sensors read in 180.419ms
Test 3. Sampling one sensor [TPS] as fast as possible
256 samples read in 4113.454ms = 62.23 samples/second
Maximum sample time: 43.160ms
Minimum sample time: 31.851ms
Average sample time: 37.505ms
Test 4. Interactive display - Activate/move or update the [TPS] sensor (Control+C to exit)
Running...
Sensor: [ TPS] Value: [ -54.71] Sample Speed: [17.255ms]
Sensor: [ TPS] Value: [31.397599999999997] Sample Speed: [20.691ms]
Sensor: [ TPS] Value: [ 68.805] Sample Speed: [20.845ms]
Sensor: [ TPS] Value: [31.397599999999997] Sample Speed: [20.747ms]
Sensor: [ TPS] Value: [ -51.8868] Sample Speed: [20.756ms]
Sensor: [ TPS] Value: [58.21799999999999] Sample Speed: [20.628ms]
Sensor: [ TPS] Value: [44.102000000000004] Sample Speed: [20.757ms]
Sensor: [ TPS] Value: [-0.11640000000000006] Sample Speed: [20.798ms]
...
...
Test 2 - performance testing RPM - a 16bit sensor:
Code:
[2018-01-27 12:45:13,888] [ INFO] ( Cosworth.py: 126) | MainProcess | Starting Cosworth ECU sensor module
L8 Pectel None
[2018-01-27 12:45:13,888] [ INFO] ( Cosworth.py: 179) | MainProcess | Bringing up serial interface
Serial<id=0x7f6053eb6860, open=True>(port='/dev/ttyUSB0', baudrate=1952, bytesize=8, parity='N', stopbits=1, timeout=0.1, xonxoff=0, rtscts=0, dsrdtr=0)
[2018-01-27 12:45:13,890] [ INFO] ( Cosworth.py: 289) | MainProcess | Serial interface up
##########################################
Test 1. We are going to attempt to read every sensor in turn...
Sensor: [ TPS] Value: [-0.116] Sample Speed: [14.481ms] Description: [Open angle of throttle plate in degrees ]
Sensor: [IGNADV] Value: [70.000] Sample Speed: [27.337ms] Description: [Ignition timing in degrees before top dead centre]
Sensor: [ ECT] Value: [105.000] Sample Speed: [27.246ms] Description: [Engine coolant temperature in degrees Celsius]
Sensor: [ AMAL] Value: [185.000] Sample Speed: [27.323ms] Description: [Duty cycle of boost control valve]
Sensor: [ MAP] Value: [140.100] Sample Speed: [27.236ms] Description: [Inlet manifold pressure in milibars]
Sensor: [ IAT] Value: [82.000] Sample Speed: [27.402ms] Description: [Inlet manifold air temperature in degrees Celsius]
Sensor: [ BAT] Value: [11.744] Sample Speed: [27.439ms] Description: [Battery or supply circuit voltage]
Sensor: [INJDUR] Value: [2.000] Sample Speed: [43.219ms] Description: [Injector pulse width duration in milliseconds]
Sensor: [ RPM] Value: [15511.000] Sample Speed: [43.395ms] Description: [Engine speed]
Check the above values!
Test 2. Now testing how fast we can read all sensors
All sensors read in 180.388ms
Test 3. Sampling one sensor [RPM] as fast as possible
256 samples read in 8221.024ms = 31.14 samples/second
Maximum sample time: 32.123ms
Minimum sample time: 31.673ms
Average sample time: 31.917ms
Test 4. Interactive display - Activate/move or update the [RPM] sensor (Control+C to exit)
Running...
Sensor: [ RPM] Value: [ 16207] Sample Speed: [31.078ms]
Sensor: [ RPM] Value: [ 16068] Sample Speed: [37.105ms]
Sensor: [ RPM] Value: [ 16348] Sample Speed: [36.626ms]
Sensor: [ RPM] Value: [ 16277] Sample Speed: [37.263ms]
Sensor: [ RPM] Value: [ 16492] Sample Speed: [36.823ms]
Sensor: [ RPM] Value: [ 16268] Sample Speed: [36.609ms]
...
...
Ignore the actual values - some of the data translation routines are not in place yet, so you're seeing raw values, rather than translated to real number with some of those sensors. TPS works, and you're seeing the angle open. Many of the others are raw values and other than seeing them go up or down based on engine speed, don't correspond to a real number... yet.
Here's a video of test run 2, above, which shows the engine running and the RPM sensor data increasing and decreasing with engine speed:
What does this all mean? Well, the serial datastream seems plenty fast enough to run a digital dashboard, but, I'll have to be fairly careful about which sensors are refreshed on a regular basis. For example, I can refresh RPM up to 15 times a second (which should be more than fast enough for most people), but that leaves only around 50% of the remaining time for all other sensors but we can mitigate that to a degree by having a very slow refresh for slower-changing sensors; coolant and air charge, perhaps only twice a second, for instance.
Bookmarks