rangerovers.pub
The only place for a coil spring is up Zebedee's arse
Member
offline
8 posts

That sketch reads engine RPM from the CAN bus, smooths the data, then sends a frequency request to a separate frequency generator module which sends a square wave speed signal to the ECU (I have an earlier ECU that accepts the square wave signal). It also clears any AGS related errors and tells the engine ECU that 4th gear has been selected.

Yes I thought in an earlier post you has sorted the correct CAN message for the speed signal? I assume the id is 0x153? The format is odd as it's LSB first, like the engine RPM. What message are you sending? Or maybe you have to send individual wheel speeds on id 0x1F0?

And here is the Arduino code: -


#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(3, 4); // RX, TX

int rpm = 123;                  //RPM of the engine
int freq = 111;                 //Frequency for signal generator
const int numReadings = 5;      //Size of array for smoothing RPM readings
int readings[numReadings];      // the readings from the input
int readIndex = 0;              // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average

//********************************Setup Loop*********************************//

void setup() {

  Serial.begin(9600);
  Serial.println("CAN Write - Testing transmission of CAN Bus messages");
  delay(1000);

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);

  if(Canbus.init(CANSPEED_500))  //Initialise MCP2515 CAN controller at the specified speed
    Serial.println("CAN Init ok");
  else
    Serial.println("Can't init CAN");

  delay(1000);
}

//********************************Main Loop*********************************//

void loop() {



  tCAN message;
  if (mcp2515_check_message()) {
    if (mcp2515_get_message(&message)) {

      // ID for RPM
      if(message.id == 0x316) {
        //Convert 0xFF, 0x12 to 0x12FF. [RPM=(hex2dec("byte3"&"byte2"))/6.4]
        rpm = (message.data[2] + ((message.data[3]*16)*16))/6.42; 

        // Start smoothing rpm
        total = total - readings[readIndex];  // subtract the last reading
        readings[readIndex] = rpm;            // read from the data
        total = total + readings[readIndex];  // add the reading to the total
        readIndex = readIndex + 1;            // advance to the next position in the array

        // if we're at the end of the array then wrap around to the beginning:
        if (readIndex >= numReadings) {
          readIndex = 0;
        }

        average = total / numReadings;  // calculate the average

        freq = average * 0.285; //Convert average RPM into frequency to generate
        mySerial.print("F");    //Send "F" to module.....followed by the frequency
        mySerial.print(freq);   //Send the frequency required to freq generator

        // Create message from gearbox controller
    /*
        byte 1 = 0x01 where;
        01 = first gear
        02= second gear
        03 = third gear
        04 = fourth gear
        05 = D
        06 = N
        07 = R
        08 = P
        09 = 5
    */
        tCAN message;
        message.id = 0x43F;         //ID for gearbox controller
        message.header.rtr = 0;
        message.header.length = 8;  //formatted in DEC
        message.data[0] = 0x81;
        message.data[1] = 0x04;     //4th Gear
        message.data[2] = 0x40;
        message.data[3] = 0xFF;     //formatted in HEX
        message.data[4] = 0x00;
        message.data[5] = 0x80;     //Clear errors
        message.data[6] = 0xFF;
        message.data[7] = 0x00;
        mcp2515_bit_modify(CANCTRL, (1<<REQOP2)|(1<<REQOP1)|(1<<REQOP0), 0);
        mcp2515_send_message(&message);
        delay(100);
      }
    }
  }
}

So the ECU needs to be happy that the car is in a valid gear for cruise to work. On a manual map the speed and engine rpm have to be in sync for a given gear so you need to know if yours is flashed for a five or six speed box as the ratios are different. You can also modify the required ratio's for each gear in the MAP file. On an auto map the gear selection is simply sent from the AGS as a CAN message, see below copied and pasted from another forum. Please keep us up to date with how you get on as I would like to change to a manual map at some point, so I will need to re-engineer the cruise control. Have you got a valid speed signal to the ECU? I'm using the Arduino to read the engine RPM and then fabricate the speed signal with some smoothing, based on the changing RPM, it works very well. You also need two brake pedal signals, I'm using the land rover's normal brake light feed for one signal and I've added an extra switch in the hydraulic circuit for the second signal. I'm certainly no expert on this but I did do a lot of research and testing and I'm happy to share any information that I can.

message from AGS 0x43F

byte 0 = 0x81 //doesn't do anything to the ike

byte 1 = 0x01 where;
01 = first gear
02= second gear
03 = third gear
04 = fourth gear
05 = D
06 = N
07 = R
08 = P
09 = 5
0A = 6

byte 2 = 0xFF where;
FF = no display
00 = E
39 = M
40 = S

byte 3 = 0xFF //doesn't do anything to the ike

byte 4 = 0x00 //doesn't do anything to the ike

byte 5 = 0x80 where;
80 = clears the gear warning picture - all other values bring it on

byte 6 = 0xFF //doesn't do anything to the ike

byte 7 = 0x00 //doesn't do anything to the ike

Hi Sloth,

Remind me, did your doner ECU come from a manual or Auto transmission car? Mine came from a "V" reg E39 auto and in order to get the cruise to work I am using an Arduino to simulate the CAN messages from the BMW auto box, which was needed to get the cruise working. You can use DIS to read the cruise control status which needs to show "0"

The M57 in my 90 is a standard map at 184hp and it's not slow. I'm not brave enough to test the top speed but even on a good incline it just pulls and pulls and I have to lift off. It has so much torque too, it's very responsive and you can apply power in any gear and we're off. Not a trace of smoke at any time. If you get you're boost issue sorted I'm sure you will be pleased with it. The boost control vac solonid/pressure regulator can be a cause of boost issues so that might be worth looking into?

So I've made a small amount of progress with the cruise control. My ECU is also a DDE4 and it came from an early 2000 E39 530D, but mine actually appears to accept the pulse input (Rear right wheel) directly into the ECU. I thought it was a long shot but I tried sending a square wave on pin 22 and to my surprise the vehicle speed showed up on diagnostics.

DIS Screenshot

I am struggling though to get cruise control to activate. In DIS there is a "cruise control status" field which returns a number but I have no idea what it means. I have connected the BMW steering wheel buttons and the button pushes show up on diagnostics and the "status" number changed when I toggle cruise on and off. The status value changes again with brake pedal signals, the number must mean something?

I know that cruise will only activate when the ECU is happy that a valid gear is selected. In the manual car this is simply comparing engine rpm and road speed but my engine is from an auto, so perhaps it communicates gear selection with the GM gearbox on the CAN BUS. So many unknowns make it very difficult to diagnose the problem. Diagnostics also show "clutch pedal operated" but this is an auto ECU and the relevant ECU pin doesn't have a wire in the connector for the clutch switch.

Yes Ashcrofts are very good, I have used them many times. Most recently for a special 1.1:1 ratio gearset for the LT230 transfer box as I have coupled my E39 M57 engine to a six speed manual gearbox from the E46.

I've had another go at getting vehicle speed data to the ECU this evening.

After a bit of research I found what I though was the correct format that the ASC unit would send, but nothing appears on diagnostics.
I have sent ID: 153, Data: 0 85 1B 0 0 0 0 0.
I believe the speed should be on byte 1 and byte 2 and this data should represent 55km/h. I'm thinking perhaps I need to also send individual wheel speeds instead/aswell? BeaDy what data did you try sending? I now wish I'd kept the ASC unit from the doner car to have a play with.

I'm also trying to get cruise control working on my M57 converted 90. I would be very interested to know what CAN data you guys have been feeding in for road speed. I've tried using id 0x153 but not having any luck at the moment.

Another thing to note about cruise control is that the ECU expects the road speed and engine RPM to correspond correctly for a valid gear selection otherwise it will drop out, so I plan to manipulate the speed signal appropriately. I believe it also needs opposing signals on pin #24 and #28 of the x2414 connector to signal that the brake pedal is released.