I covered this a while back in another thread:

viewtopic.php?f=14&t=396&p=32431#p32431
Here it is again to save you clicking:

-----------------------------------------

I saw someone mention speed calculation from MG2 rpm, here's how I did it:

I have this at the top

Code: Select all

```
//for 255/40/R17 tyre
#define TYRE_WIDTH 255
#define TYRE_RATIO 40
#define TYRE_SIZE 17 //inches
#define DIFF_RATIO 4.1 //x:1
#define TYRE_CIRCUMFERENCE (TYRE_SIZE*25.4+TYRE_WIDTH*TYRE_RATIO/50)*3.14159265359/1000 //m travels in one wheel revolution
#define DIST_PER_MG2_REV TYRE_CIRCUMFERENCE/1.9/DIFF_RATIO/1000 //km car travels in 1x MG2 revolution
#define LOWGEAR_RATIO 2.05263157895 //how much lower the low gear is compared to high
```

Then these lines after mg2_speed = mth_data[31] | mth_data[32] << 8;

Code: Select all

```
veh_speed_kph = mg2_speed * 60 * DIST_PER_MG2_REV;
if (veh_speed_kph < 0)veh_speed_kph *= -1; //for reverse
//if (put your "low gear" check in here)veh_speed_kph /= LOWGEAR_RATIO; //low gear
veh_speed_mph = veh_speed_kph/1.60934;
```

Change your tyre specs (printed on the tyre) and the differential ratio to suit your application.

For MPH you can just divide the speed by 1.60934. I run the car in kph and just do the conversion in the gauge cluster if needed.

If you never want to use kph then just do the /1.60934 on the lines above.

This code isn't for Damiens VCU so adapt it to suit your needs.

The advantage of this code is that it makes it easy to enter your tyre size and differential ratio. The #define's are calculated by the compiler at compile-time and therefore those calculations do not use any processor or memory.