Starting a new build

Started by Chewy1576, February 12, 2018, 07:34:30 PM

Rx7man

another way to do it would be to imitate vehicle ECU's.. the display unit, or whatever requests a parameter and then the relevant computer responds.. I think it's explained in plain english here
https://www.youtube.com/watch?v=OhShoU_E-0g
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

hakcenter

so simple gosh even a monkey could do it, lolol
TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

Chewy1576

Took a long weekend to drive down to Nevada with some buddies for a golf trip. I ordered the 16 MHz crystal and some other parts before I left. They were delivered last Friday. Now that I'm back, I got the new crystal soldered in and changed the code on the LCD side to use the same lib as the VGT side and added the interrupt input and it seems to be working much better. No delay timers or anything, it just chews through them.

Rx7man

I think I might take a look at the current CAN library and see what can be changed to make the frequency selectable...  Using interrupts on both sides I was able to get ping rates under 1ms, and maybe better since this was with 8mhz crystals.. I do have some 16mhz crystals spare, but I'd rather find a software solution since I have so many of these boards with 8's on them
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

Chewy1576

#94
Here's the one I switched to. I like the frame formatting in this one. There was also a download link in that forum post I mentioned earlier that had a library with selectable mhz settings.

Rx7man

I was thinking of modifying the existing library so it wouldn't need any other changes to code except for the initializer.. I will keep that one in mind though, since there's a good chance the units I'll build that use these 8mhz modules will have totally different code anyhow
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

Chewy1576

I haven't really had much time to work on this, but I've been trying to set up the message filtering on the LCD side and it's kicking my butt! It's receiving all of the messages, but I'm having trouble figuring out how to grab specific messages and copying the data into the variables for display on the LCD.

Rx7man

Are you trying to do it in hardware (the MCP chip has some mailboxes, filters, etc) or in software?
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

Chewy1576

In the software, using if statements looking for the  specific message ID, then doing a memcpy into the fourbyte array. I started looking into masks and filters too, but haven't gotten very far.

Rx7man

I'd start with setting up a bunch of #DEFINE statements that set up the messageID and what they're for, then use a CASE statement.. Can't remember the exact syntax for it, I think this is right?


#Define RPM_MID 345543 //I'm just using random numbers here
#Define EGT_MID 23432
#define TSS_MID 645555
.
.
.
.
.

void MessageHandler(CAN Message){
fourbyte value = GetFourbyteFromMessage(Message);

Select Message.ID{
   Case RPM_MID:
    RPM = value;
    break;
  Case EGT_MID;
    TSS = value;
    break;
  Case TSS_MID:
    TSS = value;
    break;
}
}

fourbyte GetFourbyteFromMessage(CAN Message){
//do your memcopy here, or just do it byte by byte
return value;
}


'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

Chewy1576

I'll try to give it a shot tonight. Thanks!!!

Chewy1576

Here's my first attempt, no workie....

void MCP2515_ISR()
{
  data_rcvd = true;
}

void C_CANBUS()
{
  data_rcvd = false;
 
  if (CAN.available() == true)
    {
      rcv_data = CAN.read();
    };
 
  data_ready = true;
}

void copydata()
{
  data_ready = false;
  switch(rcv_data.id)
    {
      case turbo_speed_ID:
        memcpy(rcv_data.data,turbo_speed.b,4);
        break;

      case vane_pos_ID:
        memcpy(rcv_data.data,vane_pos.b,4);
        break;

      case boost_pressure_ID:
        memcpy(rcv_data.data,boost_pressure.b,4);
        break;

      case egt_ID:
        memcpy(rcv_data.data,egt.b,4);
        break;
    }
}

void loop()
{
  if (data_rcvd = true)
  {
    C_CANBUS();
  }

  if (data_ready = true)
  {
    copydata();
  }

  D_LCDWrite();

}

Rx7man

I'd start tossing in some serial prints in there and see what's going on..  Also pay attention to HEX and DECimal values with your message ID's

I'd start with putting one in the interrupt, then each CASE statement.. is it actually getting in there?

Also, it would make the program flow look smoother if instead of setting a flag that the copy is done, just go right to parsing that data out.   Also, global variables tend to be frowned upon when not absolutely necessary.. Pass directly to the function..
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

Chewy1576

So I haven't given up... Been a busy month or so and I haven't had much time to tinker. I had some time tonight to work on moving the received data around, and figured out I had the destination and source in the MEMCPY backwards  ;D. Now it receives one message and the program seems to hang, it doesn't pull in any more messages.

void MCP2515_ISR()
{
  data_rcvd = true;
}

void C_CANBUS()
{
  data_rcvd = false;
 
  CAN_Frame rcv_data;

  if (CAN.available() == true)
    {
    rcv_data = CAN.read();
    }

  if (rcv_data.id == 300000000)
    {
    memcpy(turbo_speed.b,rcv_data.data,sizeof(rcv_data.data));
    }

  if (rcv_data.id == 305000000)
    {
    memcpy(vane_pos.b,rcv_data.data,sizeof(rcv_data.data));
    }

  if (rcv_data.id == 310000000)
    {
    memcpy(boost_pressure.b,rcv_data.data,sizeof(rcv_data.data));
    }

  if (rcv_data.id == 315000000)
    {
    memcpy(egt.b,rcv_data.data,sizeof(rcv_data.data));
    }
}

void D_LCDWrite()
{
  long disp_turbospeed = 0;
  int disp_egt = 0;

  disp_turbospeed = (long) turbo_speed.f;
  disp_egt = (int) egt.f;
 
    //lcd.setCursor(0,0);
    //lcd.("TurboSpd:          ");
   
    //lcd.setCursor(0,0);
    Serial.println(String("TurboSpd:") + String(disp_turbospeed) + String(" RPM"));
   
    //lcd.setCursor(0,1);
    //lcd.print("TurboPos:         ");
       
    //lcd.setCursor(0,1);
    Serial.println(String("VanePos:") + String(vane_pos.f,2) + String (" cm2"));

    //lcd.setCursor(0,3);
    //lcd.print("Boost:  ");
   
    //lcd.setCursor(0,3);
    Serial.println(String("Boost:") + String(boost_pressure.f,2));

    //lcd.setCursor(12,3);
    //lcd.print("EGT:    ");

    //lcd.setCursor(12,3);
    Serial.println(String("EGT:") + String(disp_egt));

    //delay(100);
}

void loop()
{
   
  if (data_rcvd = true)
  {
    C_CANBUS();
  }

  D_LCDWrite();
 
}

Chewy1576

K another dumb mistake...

As soon as I changed "sizeof(rcv_data.data))" in the MEMCPY to "rcv_data.length", it started working!